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

2015/5/29

Removing Objects Off-Screen, Using Keys.

TechDan TechDan

2015/5/29

#
Hey peoples, I am in need of help to figure out how to code a segment of code that removes an object off the screen when a key is pressed. For example, if I press the spacebar, a polar bear will appear, and when I press the letter "d", the polar bear will disappear. BTW, Im a beginner sadly. Thank You for taking a look at my post.
azazeel azazeel

2015/5/29

#
suppose you create a bear object like this
Bear b = new Bear()
remove use add object to appear and removeobject
//if you use this code it should be placed in world sub class
String theKey = Greenfoot.getKey();
if(("space").equals(theKey))
  addObject(b, 100,100) ; 
else (("d").equals(theKey))
  removeObject(b);
You need to login to post a reply.