This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I am trying to rewrite a tutorial for slick2d in my own way, but I've met a block. I want to use this code in a void method, while sheet is declared in another class. Is this possible? It says sheet cannot be resolved. I'm on Eclipse. Thanks in advance.
"The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!', but 'That's funny...' "
- Isaac Asimov
That isn’t a global variable. It is a private field in another class. You should avoid global variables like the plague, but if you are trying to get a field from another class, you should reconsider your design.
It might be appropriate to give that other class a getSheet() method, or getSpritesFromSheet(), but I don’t know enough about your application to tell that sort of thing. Don’t give the field more visibility in order to placate the compiler.
sheet is a SpriteSheet, a .png with many sprites on it. I want to only load one, to make my game load faster and to keep all the assets in one location. Each entity that I will make hopefully will have an public void init() method in which the class initializes all of the variables and assets needed. The method below allows my player class to initialize where his sprites are.