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

2014/4/8

Toggling a variable

qwertyuiop qwertyuiop

2014/4/8

#
I have my game set up at the moment so when an item collides with the user then the image of the user should change. It works perfectly however when they collide the image only changes for a split second as they are no longer colliding. So I was wondering how I would be able to make it so it toggles whether the image should be set or not.
danpost danpost

2014/4/8

#
Sounds to me like you are wanting to put a timer on the setting of the image -- you already have the toggling of the image part working. Add an instance 'int' field, call it 'collisionTimer'. When you detect a collision and set the image, also set the timer to some value, maybe something around 30. As an 'else' part in detecting a collision, if the timer is not zero, decrease it and check to see if it is now zero, and if so, revert the image.
qwertyuiop qwertyuiop

2014/4/8

#
Thanks that gave me the idea of using an int variable that will change depending on the power up gained and it is working.
You need to login to post a reply.