Pixel Perfect Collision

Discussion and feedback on Construct 2

Post » Tue Feb 05, 2013 11:49 pm

Okay, sad to see there was no responses, but let's move on from that.

I tried to make a sort of middle ground here. I know that one big PNG isn't gonna cut it, but neither is a hundred sprites. And while I have discovered that I can indeed give them their own rotations, coordinates, size, and whatnot, I still don't want to make twenty or thirty of them per level. That's a nightmare.

So here's my "Round-Peg-Square-Hole-Bigger-Hammer" approach:

I went back into the image and chopped the entire thing up into areas which contained walls. I made each block just big enough to cover an area that I knew would be covered by only eight vertices. Roughly three walls, give or take a rounded corner.

Each image was then dropped into the layout, the collision areas all properly defined, and then set to an Opacity of zero.

Instead of having a layout that consists of twenty individual blocks for walls, each one requiring a unique list of info, I now had five pngs, and the only attention they required was to simply have their verts properly lined up. And if you can play connect-the-dots, you can line up verts.

To reiterate that last point- creating walls via sprites involves a process which looks like this:

On LoadBeachMap   >
   System Create > WallSprite at 0,0
   Wallsprite > Set Size to 40,500
   Wallsprite > Set Angle to 180
   System Create > WallSprite at 500,0
   Wallsprite > Set Size to 40,500
   Wallsprite > Set Angle to 180
   System Create > WallSprite at 0,500
   Wallsprite > Set Size to 400,40
   Wallsprite > Set Angle to 180

That would create a vague "U" shape. Then you'd still have to set the opacity to 0, change the behavior to solid, etc.

With the new version, one image gets the same result.

On LoadBeachMap >
   System Create BeachWallsU.png at 250,250

Set your behavior, opacity, and verts. Done.

   Makes the runtime slow waaaaaay down on my older laptop. As in... each section takes ~1.3 to 1.7 seconds to load. Not using power of 2 is one of my concerns here...

So, in closing, this is one solution that can help you achieve more precise results when it comes to collisions. Break things up into pieces, like reese's.
Everybody got to come out of the closet... does that mean I'm allowed to come out of the corner? Is that even funny anymore? Do parents still make their kids stand in corners when they mouth off?? These are the questions that keep me out of the really good schools.

Posts: 27
Reputation: 2,750

Post » Wed Feb 06, 2013 3:13 am

For grid (or hex) type of movement I wonder if it would be quicker to list the locations of solid objects in an array and then scroll through the array each time to see if a solid object is there before allowing the player to move into that spot? This way there would be no collision detection of graphics needed at all. This would restrict the player to moving in blocks equal to the size of the grid.

Posts: 63
Reputation: 4,437


Return to Construct 2 General

Who is online

Users browsing this forum: wavetalk55 and 6 guests