Take the 2-minute tour ×

How do I make my player fade in and out for a few seconds when collision occurs? I have my player setup that when he collides he loses a life but when he collides he basically gets stuck on the object. I want him to collide, lose a life and flash in and out for a second past the physics object with the player not having any physics properties for that fade time.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Collide I suppose you are doing with physics.

For losing a life, that is up to your code.

Flashing in and out:

Use "transition" and "setFillColor" or "alpha", I use this code personally in one of my projects:

--on collision yaddayadda
myPlayerObject.alpha = 0.3;
transition.to(myPlayerObject, {alpha=1, time=300})
--more yaddayadda

Since you can only REMOVE color (not add) using code, if you want it to flash white (like those old NES games), you will need a second object that is white, and do the reverse of what I did (set alpha to 1 and transition to 0 instead).

Making physics object don't have properties:

There are a property named "isSensor", just set it to true on your player, this will make it don't collide with other stuff but maintain momentum, velocity and whatnot.

It will still trigger a collision event (but it won't "bump" into stuff) thus you will need to check if "isSensor" is true, and return from that point instead.

share|improve this answer
Thank you very much. –  user1839885 Nov 22 '12 at 14:59

Your Answer


