After Chat To answer the underlying problem that was discussed in chat:
There was an ArrayList<Rectangle> chickens
as an instance variable for the OptionsScreen
class. The OP wasn't getting the Rectangle
's out of the ArrayList
in the render
method. OP was using a variable name chicken
from a different method, spawnChicken
that only had method scope. I showed the OP how to loop over the ArrayList
in the render
method, access the Rectangle
s one at a time, and then perform the necessary operations.
From Before Chat And Edited Question The scope of sprite
is only in the method method
. This means that you can only make use of the sprite
variable while inside of method
. You could make sprite
an instance variable, then you could access it in another method of that same class.
public class OptionScreen{
private Rectangle sprite; // Make instance variable
public OptionScreen(){ // Constructor - called when initializing
sprite = new Rectangle(); // Initialize (so it's not null)
... // Set other info on sprite, such as x
}
public void render(float delta){
...
sprite.x;
...
}
public static void main(String[] args){ // Example of useage
OptionScreen optionScreen = new OptionScreen(); // Constructor called
optionScreen.render(1.1);
}
}
Initializing sprite
in a constructor ensures that it won't be null
when attempting to use render
. (Unless you set it to null
)
Note: It is probably a good idea to not name methods method
since it gets confusing.