How To

How to do sub-sprite collision checks

1

nebyoolae 2023-09-14 21:05

If I have one sprite that doesn't use all of its area (the "hittable" region of the sprite is less than 8x8, and the rest is background), is there a way to check for collision only with the "hittable" region?

  0 1 2 3 4 5 6 7
0 _ _ _ _ _ _ _ _
1 _ _ _ _ _ _ _ _
2 _ _ _ 0 0 _ _ _
3 _ _ _ 0 0 _ _ _
4 _ _ 0 0 0 0 _ _
5 _ _ 0 0 0 0 _ _
6 _ 0 0 0 0 0 0 _
7 0 0 0 0 0 0 0 0

Per the image above, I don't want a collision with 0,0 or 6,2 to trigger a HIT, but I would want to with 3,3 or 0,7.


Timo 2023-09-14 21:32 (Edited)

Sprite with sprite collision or sprite with background?
For the first you have the SPRITE HIT function, if I understand your question correctly.


McPepic 2023-09-14 23:32

@nebyoolae
This is how it works by default. No extra processing required besides the SPRITE HIT function.


was8bit 2023-09-14 23:38 (Edited)

Collision with SPRITE and SPRITE will do a pixel to pixel collision check for every color 1,2,3... “color” 0 is considered as void and not a color, and so the SPRITE HIT command only checks portions of the sprite that uses colors 1,2,3

For touch drag applications, having large empty spaces will make a sprite hard to touch and drag, so in that situation you will need to make the item like a button shape with your image on the button (I know you didn’t ask that question but I added it just give a complete overview of things)


nebyoolae 2023-09-15 02:13

My latest version of NebyooSkate adds some cones to jump over. The cone itself is smaller than the 8x8 space it occupies as a SPRITE, but a collision is registered even if my skater sprite hits the "void" pixels of the sprite, despite that not making visual sense.

The screenshot shows a 15 next to the title, which is the sprite ID for that particular cone, and the number is displaying at all because a SPRITE HIT has been triggered due to collision.

My questions are:
1. Can I make it so the skater has to actually touch the non-void pixels of the cone before a collision is triggered?
2. Can I make a smaller-than-8x8 sprite?

Nebyooskate.nx | Open in app
2023-09-15 02:13

was8bit 2023-09-15 03:23

Look for EDIT_STUFF:


was8bit 2023-09-15 03:27

Here is what i did....

1) edited cone image

2) added YDIFF that calculates WHERE the skater hits the cone, Y wise...

3) with testing with TRACE i edited to only allow a "hit cone" if the skater's FEET hits the cone :) ... obviously doesnt hit cone with their head ;)


was8bit 2023-09-15 03:34 (Edited)

To answer your questions...

1) if you are trying to register skater CLOSE to cone but not touching cone, i recommend adding an extra sprite that is a ring... that way touching the ring sprite counts as close to cone, separate from touching the cone sprite ... adjusting different ring radius and thickness could be used for different difficulty levels... thicker big rings for easy, smaller thin rings for harder...

2) you can a sprite with one pixel ... i do this with a single pixel in the upper left corner, and use it with TOUCH and DRAG other sprites...


was8bit 2023-09-15 03:38

SPRITE SIZE setting is just adjusting your maximum possible size...

a size 0 sprite with only one single pixel in upperleft corner will behave identically as a size 3 sprite with only one single pixel in upperleft corner...


nebyoolae 2023-09-15 04:19

Thanks was8bit!


was8bit 2023-09-15 15:18

:)


Log in to reply.