I’m playing around with creating sprites and noticed that an image’s transparent space will still register as a click. is there any way to make the clickable space smaller than the 32X32 pixels? or if it’s larger, is there any way for the transparent parts not to be clickable?
It’s a bit hard to explain, but here’s an example in my game:
If you create a road and buildings next to it, your mouse will get confused because of the blank space in the sprites and will start picking up random things.
So, the hitbox of an object is it’s original size. So for example, if you had a one pixel big image but put a 200 pixel animation on it, then the hitbox would still be 1 pixel. So, have your object always playing an animation with the transparent pixels.
Hi! Thanks again xD
So are you saying that if I create an animation with the image of the object playing as an animation on a loop (just the same image in two frames) the hitbox will be reduced to the visible pixels in the sprite?
[hope that makes sense]
Wow! I know this isn’t a review or a play my game topic but it looks amazing!
hahahaha thanks!! I really like your city btw.
Yes that is what I’m saying. This technique is used all the time in combat games such as Street Fighter.
hmmm not sure what I’m doing wrong. I tried to add an animation to the road item (of the same sprite with the transparent background)
it starts with a “once” trigger (once the item is created by clicking on the small version on the side. and loops.
When I tested it however it still registers the click on the empty space surrounding the visible pixels. Any ideas what I might be doing wrong?
Could you send me an image of the original, unanimated sprite?
So what are you clicking that causes you to click the road?
Also, check your block’s hitbox shape. I recommend capsule or polygon for that.
I made some images to show what I think it’s happening.
So, I added this image 32x32 pixels:
It’s hitbox seems to be:
I’ve tried using polygon shape, and I would assume it would work this way:
but honestly it still seems to register as if it was the red box…
Is there any way to make the hitbox smaller? such as to keep it somewhat like this?:
Making the image larger than 32X32 would somewhat solve that but I’ve noticed that the hitbox then goes to the top left hand corner. So I suppose if I could move it to the middle that would work too.
I also thought about breaking the road into a middle square that is clickable:
and adding other squares that are not clickable that are generated and moved when the middle one is moved:
but that honestly sounds like hell to do for every single sprite.
The shapes aren’t the size of the name for the edges, it’s the number and shape of the corners. So a polygon would be more like this:
Hey! Sorry to hear your having some trouble. There is a lot of confusion happening in this thread, let me try to clear some of it up:
- Collision shapes are not related to mouse clicks, the refer to physics only
- Polygon collision shapes build a polygon around the shape of the object, it is not a hexagon (normally)
- Mouse Clicks should behave the way you expect (areas with 0 alpha should not be clickable), it appears that there is an issue with the hit testing. I’ll investigate and probably deploy a fix this weekend if it is a bug.
Thanks grazer, thought that mouseclicks and game collisions were the same hitboxes. Now that I think about it, that makes Notes and Waves bugs make more sense…
Thank you so much @grazer!! you’re the best
@meburningslime thank you anyway, I really appreciate it. It’s been fun trying to figure this out
Yes definitely lol, let me know if you want to explore or fix anything else lol. Been here for years and never knew that!
Hi! Do you happen to have any updates on this? I’m just wondering if I should start looking for alternative temporary fixes. Thanks
I can’t wait for this to become Sim City in the next 12 months