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

Get help using Construct 2

Post » Wed Mar 11, 2015 12:39 pm

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.
B
3
Posts: 6
Reputation: 187

Post » Wed Mar 11, 2015 3:31 pm

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
B
75
S
26
G
13
Posts: 1,086
Reputation: 13,694


Return to How do I....?

Who is online

Users browsing this forum: RetroSpock, skrotar and 8 guests