Page 1 of 1

Irregular sprite overlapping area

Posted: Wed Mar 16, 2022 10:44 am
by rrTea
I made a small game in a non-ZGE engine, so this made me think how would the same project work in ZGE.

The mechanic I’m not sure about is the “calculate the relevant area” mechanic. Basically what I’d like to find out is how much (in pixels, but doesn't have to be super precise) of a certain sprite is overlapping with another sprite. The shape of one of the sprites is organic and animated (10 frames or so), while the other is rectangular.

This is what it currently looks like:
Image

Is this possible to do in ZGE without using OpenGL calls?

Re: Irregular sprite overlapping area

Posted: Wed Mar 16, 2022 6:59 pm
by Kjell
Hi rrTea,
rrTea wrote: Wed Mar 16, 2022 10:44 amIs this possible to do in ZGE without using OpenGL calls?
Sure. The only thing that is a little cumbersome is the fact that you can't access image data directly, so you need to copy the alpha channel of your image / spritesheet to a array ( using a BitmapExpression ) .. and if you want to use a spritesheet there's no way to access the spritesheet coordinate data, so you need to import / copy that to a persistent array ( this isn't a issue when using tiles ). Attached is a silly & dirty example*

Image

*Didn't feel like adding support for sprite-mirroring so i mirrored the sprite in the spritesheet itself.

K

Re: Irregular sprite overlapping area

Posted: Wed Mar 16, 2022 7:08 pm
by rrTea
I see, this way I could also adjust the precision of the detection too, that's great!

Thanks! :D

Re: Irregular sprite overlapping area

Posted: Wed Mar 16, 2022 9:21 pm
by Ats
As always your examples are so cool, Kjell :D

Re: Irregular sprite overlapping area

Posted: Thu Mar 17, 2022 11:58 am
by VilleK
I agree, very cool example!