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

2014/2/1

What is an emnum???

nofavrel nofavrel

2014/2/1

#
shoot { public void act() { setLocation(getX() + speed, getY()); checkBoundaries(); destroyEnemies(); } //we add a method "checkBoundaries()" that destroys bullets that are off screen. public void checkBoundaries() { if(getX() > getWorld().getWidth() - 1) getWorld().removeObject(this); else if(getX() < 1) getWorld().removeObject(this); if(getY() > getWorld().getHeight() - 1) getWorld().removeObject(this); else if(getY() < 1) getWorld().removeObject(this); } //"destroyEnemies()" destroys enemies. public void destroyEnemies() { //"Enemy" can be any class that you want the bullet to destroy. Actor enemy = getOneIntersectingObject(Enemy.class); if(enemy != null) { getWorld().removeObject(enemy); getWorld().removeObject(this); } } private int speed = 10; } This is what I have can you tell me what is wrong with it plz
danpost danpost

2014/2/1

#
What is wrong is your scenario will stop when a bullet reaches the edge of the world and give you an IllegalStateException error on the line 'Actor enemy = getOneIntersectingObject(Enemy.class);' in the 'destroyEnemies' method. This much should have been supplied by you in your initial post. When the edge is reached and your bullet is removed from the world, it can no longer provide any collision detection (it is not in any world that could be checked for intersecting objects). You need to ask if the bullet is in the world before calling the method: 'if (getWorld() != null)' (in the 'act' method).
danpost danpost

2014/2/1

#
If the title was supposed to be 'What is an Enum?' then refer to the java tutorial page Enum type.
You need to login to post a reply.