# How do I / Get pixel count in an object ( sprite )

0 favourites
• 2 posts
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
• Hi. I want to do following:

If player collides with an object, than the game should compare their size ( not just by height / width, but by the pixel count of anything that is not transparent )

Example:

Player is a square 10x10 pixels

Player collides with an object that is 9x9 pixels > player grows up by 10% of the size of the object.

Player collides with an object that is 10x11 pixels, player shrinks by 10% of the size of that object.

Player collides with an object that is 10x11 pixels, but 70% of the object is transparent, so player grows up by 10% of the size of that object.

So is there a way to get the actual size of the object and compare the values ?

I m sorry for reposting the same, but I have been trying to figure it out for last 3 days & I still dont know how to do it. It is really getting frustrating

Someone has suggested me the Canvas plugin, but I have no idea how to do what I am trying to do there.

• ## Try Construct 3

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• use SetSize... and you just have to do a bunch of checks..

you have to come up with an algorithm for changing sizes, like check the height of the colliding object and do a calculation that sets the player to the correct size.

or a better idea is to give the object an instance variable, and that will determine whether to grow or shrink.

if you don't want to deal with Height and Width, then just use scale.

there is no Player.scale so you have to make one manually. Just set an instance variable on the Player and everytime you effect it do:

Set Player Scale to self.scale

so a 9x9 object would have an instance variable change_amount=0.1, your 10x11 would have change_amount=-0.1 then for the opacity you'd have change_amount=self.scale * 0.1

then set Player.scale to Player.scale + Object.change_amount

then set Player Scale to self.scale

• 2 posts