Current world check [SOLVED]


(Eva Droch) #1

Hello guys. How can I check the current world :relaxed:

MyCheckPoint class

package CheckPoint {
    import Levels.MyLevel;
    import net.flashpunk.FP;
    import net.flashpunk.Entity;
    import net.flashpunk.graphics.Image;

    public class MyCheckPoint extends Entity {
        [Embed(source='../assets/checkp.png')] 
        private const CHECK_POINT:Class; 
 
        public function MyCheckPoint(posX:int, posY:int){ 
            graphic = new Image(CHECK_POINT); 
            setHitbox(46, 46);
            type = "check_point";
            x = posX * 46; 
            y = posY * 46;
        }
        override public function update():void {
            if (collide("player", x, y)) {
                FP.world.removeAll();
                FP.world = new MyLevel;// level_2
            }

        }
    }
}

I can do 30 checkPoint classes for each level, but how can check the current world like this

if (collide("player", x, y) &&/* current world ( MyWorld )*/ ) { //MyWorld is it level_1
                FP.world.removeAll();
                FP.world = new MyLevel;// level_2
            }

if (collide("player", x, y) &&/* current world ( MyLevel )*/ ) {
                FP.world.removeAll();
                FP.world = new MyLevelTwo;// level_3
            }

:sweat:


(Martí Angelats i Ribera) #2

Here you have two options:

First, checking the world class

if(FP.world.constructor == MyWorld)
{
// if the world is MyWorld class
}

Second, make a variable that tells you a referecnce.

PS: I haven’t tested it.


(Jacob Albano) #3

The is keyword is better.

if (FP.world is MyWorld)
{
}

(Martí Angelats i Ribera) #4

Oh true. Forgot about it.


(Eva Droch) #5

Thank you very much! It’s very smart move, and very easy, thank you ! And do not write 30 checkPoint classes :blush: