Sign in to follow this  
Dekowta

Curve 2D Collision Map

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 [url="http://i.imgur.com/qWY3b.png?1"]http://i.imgur.com/qWY3b.png?1[/url]
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 this post


Link to post
Share on other sites
[quote name='Dekowta' timestamp='1343170322' post='4962767']
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.
[/quote]

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 this post


Link to post
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.

Thanks for the reply

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this