Pending Intent
Pending Intent

Reputation: 121

LibGdx Texture loading in game and using it for various listeners

hi i am developing a game using libgdx. I want to make the texture object available to entire application. I have a requirement like, initialize the texture in one application listener and i want to use it in another application listener. Can anyone help me on this.

Upvotes: 2

Views: 775

Answers (2)

Daahrien
Daahrien

Reputation: 10320

You don't need to have 2 or more Application listeners. Actually that only makes things harder.

Use Screens instead (extending Game in your core class instead of directly implementing ApplicationListener).

Either way, you should be able to just send the textures as arguments. For example I have a class Assets that contains all the textures and I sent it to each screen. You can make them static as Doran suggested too.

Upvotes: 1

Doran
Doran

Reputation: 4090

There are two ways I think you can do this. First, you could read the data into a static variable. For an example of this, take a look at the Art class in metagun demo: Art.java. The second way, which I have not tried yet, is to use the new AssetManager class. There is example use in the AssetManager test. These should help you access your textures more easily.

Upvotes: 2

Related Questions