Public void SetTexture(TextureRegion region) Public TextureWrapper(TextureRegion tex,Vector2 pos,int destinationWidth,int destinationHeight) Now For Drawing Buttons we made two classes Button and TextureWrapper. This way we loaded the buttons required for the MainMenu So to access the particular texture we just give that file name in the findRegion argument and we get that texture in the TextureRegion. When TexturePacker is run on a group of textures their filename becomes the regionName in the “pack” file. We use TextureRegion to specify the part of the sprites we require. _menuScreenTextureAtlas.findRegion(String regionName) returns the region of the name specified in regionName. (String path) returns a file handle to the path specified in its argument (we are using because our file is stored in assets folder) TextureAtlas Constructor needs FileHandle of “pack” file and the FileHandle of the directory in which it is stored. As assets is the starting directory for libgdx we specify path as “Textures/” and name of the texture Pack generated after using Texture Packer is “pack”. TexturePath holds the path from where we load the textures. StartButtonTexture=_menuScreenTextureAtlas.findRegion("RegionName") _menuScreenTextureAtlas = new TextureAtlas((textureFile), (textureDir)) Private static TextureAtlas _menuScreenTextureAtlas Public static TextureRegion StartButtonTexture It is more efficient to load one texture and use parts of it while rendering different sprites in the scene.įor our project we made two TextureAtlases, one containing textures for the menu and another containing textures for the game objects.įor Textures we created a class called Assets which stores textures in static variables. It is a tool using which we pack different textures in one single big file called TextureAtlas which can be used to draw parts of it for particular sprites. In the constructor we call the Initialize function which is used to load the textures and setting up positions of objects.īefore we go further we would like to mention the tool Texture Packer available in libgdx project page. We just extend the Screen class to get the different screen types we specify for our game like MainMenu, Instruction, Option etc. Public abstract void OnResume() //Useful for Android code to do processing when the game regains focus Public abstract void OnPause() //Useful for Android code to do processing when the game loses focus Public abstract void render (Application app) Public abstract void update (Application app) Public Application App //Stores reference of the Application Public int IsDone //Tells whether the screen is ready to be destroyed Public int ScreenType //Stores the type of screen like MainMenu,OptionMenu, GameplayScreen This helps in maintaining a similar structure across all the pages. We have these menus in our game:Īll the different screens in the game extend a base abstract class Screen. So in Assets/Textures we would put our textures. It is better to keep it organized so we make folders for textures, fonts, sounds, data files. Now in assets we can put all the files we want to load in our game. Here is the screenshot of the folder structure of the project. We would take our game Polar as a reference.īefore going into the screens we would make a folder called assets in Android Project. In this post we will concentrate on different screens which are a part of a game like menus, scoreboard and gameplay.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |