GMS 2 Checking Sprite Size Against Other Sprite Size


I need to make an object get smaller when it collides with an object larger than itself.

Essentially, the Flash game Fishy is what I'm going for:

except instead of dying immediately when you hit something larger than yourself, you shrink and your score goes down.

I'm having a lot of difficulty figuring out how to do it though! Not sure which object to put the code on, or if image_xscale and image_yscale are the right variables for this. I did successfully use them to make the player sprite bigger on collisions.

How do I code this kind of check?
pictured above: the game (frame count reduced to decrease file size)


Firehammer Games
yes indeed, image_xscale and image_yscale are what you are looking for. If you want an object to shrink and then die, I would spawn a "death" version of it that only does the shrinking and destroy itself(so it isn't detecting collisions, etc...). If the object should not be be destroyed, rather it can scale up and down as gameplay goes on, then just modify the scale variables as needed.


Thanks for your reply!
Do you know if on collision, I can check if the colliding object is smaller or larger than the player character?


Firehammer Games the collision event, there is a variable called other, which represents instance that is being collided with. You can then access the same xscale/yscale variables other other.image_xscale. So you can compare those and then do something different based on which one is bigger.


šŸ§ *penguin noises*
GMC Elder
sprite_width and sprite_height are the current sprite dimensions in pixels (taking image_scale variables into account). Though keep in mind that this means they're negative if the object has a negative scale (e.g. when facing backwards) so you should compare the absolute values using the abs function.