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

2013/10/20

One object is enough

ddvink ddvink

2013/10/20

#
I have a char where I can press the 'u'. What should happen, is that an object of a class is created. It's creating the object, but it does it a couple of times, instead of exact one (that object by the way is an instance of a class where an animation is played of a couple of images). Does anyone know the trick? Yours, Dennis
danpost danpost

2013/10/20

#
There are two option (at least). One is using 'getKey' instead of 'isKeyDown' ('getKey' is triggered when the key is relased while 'isKeyDown' is triggered every act cycle that the key is in a pressed state). The other is just asking if the object is present or not:
if (/* 'getWorld.' (if in actor class) */ getObjects(Character.class).isEmpty() && Greenfoot.isKeyDown("u")) addObject ...
ddvink ddvink

2013/10/21

#
Thanx very much!!!
You need to login to post a reply.