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

2021/3/8

Let an actor do different things in other worlds

liekevaniep01 liekevaniep01

2021/3/8

#
Hello, I am programming a game with bees and I want different levels in my game. Now I have two worlds 'Level1' and 'Level2'. I want that my class 'Bij' in Actor move different in each world, so I need a code to know in which world the Actor is. I now have this: public class Bij extends Actor { public void act() { checkToetsen(); } public void checkToetsen(){ World world = getWorld(); if (world == Level1){ if (Greenfoot.isKeyDown("left")) { setRotation(180); move(2); } } if (world == Level2){ if (Greenfoot.isKeyDown("left")) { setRotation(180); move(10); } } The code with ' if (world == Level1) and if (world== Level2) doesn't work. Can somebody help me?
danpost danpost

2021/3/8

#
liekevaniep01 wrote...
The code with ' if (world == Level1) and if (world== Level2) doesn't work.
Change "==" to "instanceof".
Hacker707 Hacker707

2021/3/8

#
change setRotation(180) to instanceof
liekevaniep01 liekevaniep01

2021/3/9

#
Thanks! it works
You need to login to post a reply.