# Curve 2D Collision Map

This topic is 2188 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,

I'm currently looking at different ways at implementing a 2D curved map in Flash. I normally program in C and C++ so I feel slightly limited in implementation and the current method I have I expect will have a huge performance hit.

So the current method I have planned out and currently implementing is as followed:

I give the 2D artist the freedom to draw what ever collision they want within flash as one huge movie clip most likely > 2000x2000 pixels
when the game loads the level will then be converted into bitmapdata. Then when an object wants to move it will call the map collision function with the amount it wants to move in the x and y. That object is then converted into bitmapdata and tested against the map using the hitTest function built into the bitmap function. How ever the hitTest will be performed for each pixel the object wants to move so for example if it move x: 4 and y: 5 then it will test for collision 9 times. when moving in the x direction it will also text up to a maximum of 4 time each step to see if the object is on a slope and needs to move up it. so in all it could be a maximum of 21 test per object (I believe). Once that is all done the new x and y is returned.

I have an image of it draw up here http://i.imgur.com/qWY3b.png?1
The green box is the start position and then the red is the end with each other colour being in between and the black is the level collision.

There are going to be at max 10 collision object on screen at once but again that could be up for 210 checks on the level per frame.

I was thinking of using polygons and lines but the problem is storing all of them. I'm not really familiar with flash but I presume you can't create a pre-defined array of objects(lines movieclips etc.) without coding it in. Otherwise I would look into using lines and work out the angle from the two points.

From what I've read on the gamedev so far is either use alpha mapping and do per-pixel collision (which im kinda currently doing) or use the polygon method which will make it harder on the artist and me to add all the collision object in.

##### Share on other sites

I was thinking of using polygons and lines but the problem is storing all of them. I'm not really familiar with flash but I presume you can't create a pre-defined array of objects(lines movieclips etc.) without coding it in. Otherwise I would look into using lines and work out the angle from the two points.

You can open and read a file in ActionScript, so you can create your polygons/lines with an external tool and save them to, say, an XML format. If you want the shapes actually embedded in your flash object, you could generate an ActionScript file that defines them with an external tool. Or I guess you can embed XML in a flash object.

Not saying polygons is the way to go - never done any physics with bitmapped collision masks so don't know. Plenty of games have great success - Worms, Lemmings - but tend to require destructable environments to make the overhead of the mask worthwhile. Edited by Aardvajk

##### Share on other sites
Thats the way I would normally go about it but the only issue I have with that is the artist needs to create the collision and sadly I don't have the time to write a custom tool which would allow for simple polygon creation and manipulation.

I went through with the bitmap collision and it seems to be running ok with a large amount of iterations of the function though I havn't tested the time it takes fully.
were also using pesudo physics so dont need to worry too much about it being accurate for physics objects.
I didn't really think about destructible environment.

1. 1
2. 2
3. 3
Rutin
22
4. 4
JoeJ
16
5. 5

• 14
• 29
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631774
• Total Posts
3002288
×