# squish effect on a sprite

## Recommended Posts

Hi.

I've another easy newbie question for you.

I am making a simple platformer where the player can jump on baddies to kill them. It works, but I want to add a subtle 'squish' effect, whereby the enemy sprite becomes 10 pixels shorter (but keeps current width) when jumped upon. Crucially I don't want the bottom 'y' position of the sprite to change, only the top. I want the shrinkage to be smooth, not sudden, perhaps tweened over 0.25 secs.   Also, I need the physics to continue properly ie. the player standing atop the baddie stays on top of them as it shrinks.

What is an easy way to achieve this?  Any example I could look at?

Example of where I need it is here - http://owensouthwood.com/mrgoggles

Thanks!

Owen

##### Share on other sites

You should just be able to tween the height of the enemy to do this if you need it to be exactly 10 pixels, otherwise you could tween the scale.y to 0.9 or something. Bear in mind these will affect the object from the center, and changing the size of physics-driven objects can often have unintended side effects like them suddenly flying into the air. You'll just need to experiment a bit I think.

##### Share on other sites

You should just be able to tween the height of the enemy to do this if you need it to be exactly 10 pixels, otherwise you could tween the scale.y to 0.9 or something. Bear in mind these will affect the object from the center, and changing the size of physics-driven objects can often have unintended side effects like them suddenly flying into the air. You'll just need to experiment a bit I think.

Yep and I agree it's that central y position that I need to work around - so the enemy's feet stay on the floor.

I'm thinking maybe

scale.y = 0.9

body.y  = body.y + 64 - body.height   (where 64 is original enemy height.  this assumes body.height is affected by change to scale.y)