I am looking to edit my collision zone, I have made a flappy birds type game, my 'bird' is a round shape, however the .png file is square with a transparent corners. In game play, if a user collides the surrounding corners of the bird into the pipe then the game ends, can I add code that details that only the image is a collision, not the entire square?
I'm not familiar with a straightforward way of doing this, and it would be nice if there was. There are two primary routes for checking collisions:
1. You could load in the physics behavior and change the size of the fixtures that would be colliding.
2. If you aren't using the physics plug-in, then there's the onOverlap event or so.getOverlappingObjects, but those functions operate on all the sprites of each sceneobject, so creating a smaller invisible sprite for the collisions of your flappy bird won't work. Instead, you'd have to check if sceneobject overlaps sprite, where you would get the invisible hit-sprite from the bird sceneobject and check in the onUpdate.
None of this is ideal or particularly intuitive, but these are the only ways I know how to accomplish what you're talking about.
I'm sure i've done this before. What you are looking for though is called pixel perfect collision. First you use the traditional get overlapping objects. As you have rightly noted, these collisions are not perfect, they are the shape of a box. The basic Idea is to look at each pixel that is not transparent, and see if any pair of none transparent pixels from each image overlap. If they do, you have a collision.
Now it's so long since I've done this in wade that I cant recall doing it, but we did do it for the flappy dragon game. Gio would know, but if he doesn't see this I will take a quick look at the code tomorrow if I have time and work out what we were doing. Sorry I can't be more helpful
Forget what I just wrote. We are working on a collision shape editor. It should be ready soon.
Hi, I have a basic hack for you. Make your character a procdural_squre, or circle, or whatever shape most resembles your character. Make it invisible. Assign all the movements and collisions to it. Then, make an object that has only your character graphic and animations. Assign that to always have the same screen position as the object you're running your collisions on. I'm using that technique in a game I'm making right now and it works great.
Just for the benefit of anyone reading this thread, I'd like to add that the physics collision shape editor was released with version 3.5 a few months back.
If you want to use that, you can go to the Behaviors tab of a Scene Object that has got a PhysicsObject behavior. There is an Edit Physics Shapes button there. More info in this youtube video.
However, as of version, 3.6 you can also test for pixel-perfect collisions:
myObject.overlapsObject(otherObject, 'pixel');
Obviously this can be a bit slow, depending on the size of the textures involved.