Basically, I am trying to find a way to see if I can delete an object in the world class.
Something like this
if (Player.class isTouching(Key.class) {
removeObject(new Key());
}
This is why because I have my timer in the world class.
So there is a key that spawns after 5 seconds in the world class. If a player touches that key, it should despawn without effecting the timer. So when it despawns in the world class, I can make it so the timer resets if the time runs out or if the player touches the key
Hey StudyNerd!
If you want the timer to reset when the player touches the key, you can use a global variable for the timer.
In this way, it is possible for the player class to access and alter the variable.
This can be achieved by declaring the timer like so (in the World class):
public static int timer;
To reference the timer in the player code, do this:
World.timer
(Where World is the name of your world)
If you want to reset the timer in the player code, do this:
World.timer = 0;
So you want that a new key spawns every five seconds? I think I didn’t understand how collecting or not collecting is affecting the timer.
Using a static variable for it seems pretty unnecessary though.