This site requires JavaScript, please enable it in your browser!
Greenfoot back
DarkMageCkmario
DarkMageCkmario wrote ...

2014/3/27

2 Small, probably easy fix problems

DarkMageCkmario DarkMageCkmario

2014/3/27

#
My first little bit i'm having trouble with is at the end of a game, making a window for the final score to pop up onto, so that the game does not pause when the player dies. here's the code i'm using now
public void eatply(Class clss)
    {Actor actor = getOneObjectAtOffset(0,0,clss);
        if (actor != null) {
        getWorld().removeObject(actor);
        Greenfoot.stop();
        
    }
}
second problem! as you play the game, sometimes enemies will spawn RIGHT next to you and kill you immediatly. not fun. so creating a method that checks if the player is in a certain range (prrooooobably the getObjectsinRange method, but i do not know how to use that) and spawn the enemies a few pixels away. no code, because I have no idea how to do this.
danpost danpost

2014/3/27

#
You would want to add an Actor class 'addedToWorld' method to the enemy class. It is called automatically by the system when an object created from that class is added into a world. That is the time you want to reposition the enemy (before the act method is first called on it). Refer to the Actor class API documentation if needed. Oh, and yes -- getObjectsInRange is prrooooobably the method you will be using.
DarkMageCkmario DarkMageCkmario

2014/3/28

#
haha thank you, bear with me I'm very new and very very bad at this
You need to login to post a reply.