Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Collision, lets set this straight

Author
Message
RxMadJack
13
Years of Service
User Offline
Joined: 28th Jun 2010
Location:
Posted: 29th Jun 2010 07:59
After searching for days on end through these forums, there are many posts about 2d collsion, in its many shapes and forms. Could someone please explain in the simplest way possible, the best way for 2d collision? ive read about the pixel perfect, but also saw a post about line collision being better and less processor consuming. Could someone please explain and give an example of how to code the line collision? Another question, does "Play Basic" interact with Dark GDK? i see lots of forum posts between the two... Any help would be appreciated, my brothers and i are working on a sweet platformer game, collision seems to be the greatest impediment at the moment. One other question, is tile based maps always the best way to go? or can artistic drawn maps be used? would the large image file slow things down? all the old games like earthworm jim seem to be done this way. Sorry for the huge amount of questions, i just finally broke down and wanted to plead for this great communitys help. thanks in advance!
Kevin Picone
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 30th Jun 2010 17:06 Edited at: 11th Aug 2010 22:25
Quote: "Another question, does "Play Basic" interact with Dark GDK?
"


No, PlayBASIC is a standalone programming language. The two have nothing in common.

DarkGDK is a set of libraries. DarkGDK can be used are number of languages, from C/C++, VB NET, PureBasic. It'd be possible to make a binding for PlayBASIC also.


Quote: "i see lots of forum posts between the two... Any help would be appreciated, my brothers and i are working on a sweet platformer game, collision seems to be the greatest impediment at the moment. One other question, is tile based maps always the best way to go? or can artistic drawn maps be used? would the large image file slow things down? all the old games like earthworm jim seem to be done this way.
"


The majority of platform games are tile based, which greatly conserves memory. Often what we see, is a mixture of the 'common' elements augmented with unique sections.

Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 30th Jun 2010 21:03
I'm a big fan of line based collision, keep meaning to make an example but time is short these day unfortunately.

What I do is store the angle, and radius of a series of points that connect to form an outline of whatever sprite. With this, it's probably best to have the sprite pivot right in the middle, even if it means bigger images than you'd normally use. By storing the angle and radius, rather than the X and Y offset, it's possible to have practically free rotation. With pixel based collision, rotation is a complete nightmare - with this technique, rotation is free, so is scaling. I would store the radius as a 0.0 to 1.0 range, so that it has no bearing on scale, the actual XY coordinate of each point can be calculated by simply multiplying the 0-1 radius with SIN and COS.

The complex part is really making the editor - the code for this simply falls together once you have 'someones' line to line collision function. By someone I mean Mr.Picone there - he has all sorts of collision snippets. I tend to have an array of lines for static collision and enemy sprites, then check the player sprites own collision data with that. It is fairly straightforward to optimise things, last time I just built up the array with the static level collision data, then bookmarked the array position and reverted back each time, replacing the enemy collision data.

Benefits though, well besides free rotation and scaling, there's circle - line collision too, very handy. Also, you can work out which line got hit and react depending on that, maybe a ship has a weak spot that destroys it instantly. It can mean the ability to add decent 2D physics, rotation based on the point hit for example.

I suggest that you find a good, fast line collision function, and try making an editor. It's a beautiful technique once it's set up, and if your using GDK then you really have to know it inside and out.


One other option for building levels would be sprites themselves, with the same collision system. This would allow for a very free design, using big sprites for the ground, rotating them to save on GFX memory. Again though, the issue is the time it takes to make a good editor - at least with tiles, you have lots of easy options for editing. Myself, I would prefer to have the sprites, maybe get them layered, animated even - tile based games can be a little lifeless compared to more modern engines. A good example would be Aquaria.

The only project I've done using some of these techniques is an old 2D shoot em up, I'm sure the code layout is horrific but I'll have a look, might be worth uploading the source.


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2024-03-28 11:40:28
Your offset time is: 2024-03-28 11:40:28