so currently this is what im trying to resemble to happen.
"Put in some code to allow the object to rotate when it gets to the edge of the world so that it
doesn't get stopped when it reaches the edge. When an object has hit an edge 8 times, have
the object disappear."
but my counter does not seem to be working, so when object hits the edge 8 times, it disappears.
Any help is appreciated, THANK YOU.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public class dolphin extends Actor { private int counter = 0 ; /** * Act - do whatever the dolphin wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. move( 20 ); if (isAtEdge()) { turn(- 90 ); counter = counter + 1 ; //increments everytime dolphin hits edge disappear(); } } /** * keep count of how many times object has hit edge. * if counter accumelates to == 5 remove object. */ public void disappear() { if (counter == 8 ) { getWorld().removeObject( this ); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | public class dolphin extends Actor { private int counter = 0 ; /** * Act - do whatever the dolphin wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. move( 20 ); if (isAtEdge()) { turn(- 90 ); move( 5 ); counter = counter + 1 ; //increments everytime dolphin hits edge disappear(); } } /** * keep count of how many times object has hit edge. * if counter accumelates to == 5 remove object. */ public void disappear() { if (counter == 8 ) { getWorld().removeObject( this ); } } } |