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

2019/11/29

how do i make my character "die" after getting out of the world?

NotABoomer NotABoomer

2019/11/29

#
my current code for it: this should add a text (png) saying you lose, and remove the character, but it does not seem to work public void outOfWorld() { if (getY() >= 1600) { getWorld().addObject (new YouLose(), 800,300); getWorld().removeObject(this); Greenfoot.stop(); } }
danpost danpost

2019/11/29

#
Maybe you meant:
if (getX() >= 1600)
NotABoomer NotABoomer

2019/11/30

#
no, it is a horizontal game, where the backgroudn scroll behind the character, and the character is supposed to 'die' after it gets out oif the screen (too low) but the game does not pop up the losign scren, nor remove the character nor stop the game
danpost danpost

2019/11/30

#
NotABoomer wrote...
no, it is a horizontal game, where the backgroudn scroll behind the character, and the character is supposed to 'die' after it gets out oif the screen (too low) but the game does not pop up the losign scren, nor remove the character nor stop the game
Then maybe it should be:
if (getY() >= 599)
599 is the lowest y-coordinate in a world of height 600.
NotABoomer NotABoomer

2019/11/30

#
currently usign the follwoing code public void outOfWorld() { if (getY() >= 999) { getWorld().addObject (new YouLose(), 800,300); getWorld().removeObject(this); Greenfoot.stop(); } } in a world of 1000px high, and it still malfunctions
danpost danpost

2019/11/30

#
Is the outOfWorld method being called from the act method?
NotABoomer NotABoomer

2019/12/1

#
it now is, thank you for your help :)
You need to login to post a reply.