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.

DarkBASIC Professional Discussion / Pixel collision, Sprite collision or Sparky's? Which is fastest?

Author
Message
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 15th Sep 2010 02:11
Hi all, I'm in the process of making a horizontal spaceshooter. I already have some collision handling done with Sparky's and models. But, I was wondering what method is best used for this kind of game.
Is sprite collision faster to check for collision, or is Sparky's used with models faster or better, or is pixel collision the best and fastest solution?
Suppose I would make images that are textured with the outer lines of the collision boundaries, like this:



and, my spaceship is a model, and the lazerbeam is a sprite or a model, how would I check the collision with the yellow lines?
Or, would it be faster to just make the models that define the boundaries?
Or should I just use sprites to make the outline and check for collision?
Any advice or snippets to demonstrate the best and fastest form of collision would be appreciated.

Thanks in advance!

Slayer rules!!! Yeaaah, man!
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 15th Sep 2010 19:14
Hum, does anyone have an idea or suggestions or experience with this kind of collision? And maybe something to get me going?

Thanks in advance!

Slayer rules!!! Yeaaah, man!
Brendy boy
21
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 15th Sep 2010 20:39 Edited at: 15th Sep 2010 20:39
Quote: "Hum, does anyone have an idea or suggestions or experience with this kind of collision?"

if i were you i would use sparky

dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 15th Sep 2010 21:00
Sprite collision is useless in DBPro, pixel collision is far too slow for any practical application, so that leaves you with sparky's! One way to not separate level creation from the collision meshes is to make the meshes automatically generated from the images, obviously you wouldn't make one plane per pixel edge, as that would be ridiculous and would be pixel collision. Instead you'd want to stretch the mesh edges out as much as you can get away with, your example level is pretty simple and can be done using a single long straight edge for each of the slopes and flat parts.

The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 16th Sep 2010 14:01
Thanks both for answering!
Yeah, I'll probably stick to Sparky's anyway.

Quote: "make the meshes automatically generated from the images"

Can you explain that a bit more?

I was planned to make plaines or boxes to shape (and texture) the collision borders for the levels. But plaines or boxes (made with the DBPro commands) are square - ish or rectangular. Suppose I want other shapes to define the boundaries? Say that I texture a plaine with transparent areas, does Sparky's collision work with transparent parts?
The transparent parts would not be roundish, but rather diagonal.
Maybe I would be better to make those non-rectangular/squarish plaines in a 3D program, and load them in as models?

Cheers

Slayer rules!!! Yeaaah, man!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Sep 2010 15:10
I don't think any of those methods is suitible.

I would use line collision, so rather than images or anything like that - you would have lines, connected along the yellow lines. Once you have an array of lines, you can easily sort them depending on X location, sort them on that, and your detection will be nice and fast, because you can work out which lines are relevant. I would make an array, to store a lines start XY and end XY, then sort by the start XY.

With a line array, you would step through the relevant lines and check them, maybe for a bullet, or a around the player sprite. Line collision like this is also good for spherical collision, line-circle collision detection is quick too.

Kevin Picone has some great examples of line collision, you should see if you can find them.

Health, Ammo, and bacon and eggs!
Hawkblood
16
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Sep 2010 16:01
Using 3D models in a side scroller would look really nice! Collisions would need something powerfull like Sparky's. I wouldn't worry about speed though; most computers can handle something like that.

The fastest code is the code never written.
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 16th Sep 2010 21:15
Thanks VanB!
I'll definately take a closer look at some line collision examples. The only problem I see, is that my player's ship is a 3D model that 'banks' or rotates (screenies) when moving up or down. So, the shape of the connected lines forming the outer collision, would not be the same all of the time. One other thing to consider is that the ship body and the exhaust flame, are two seperate models. When moving forward, the exhaust model is shown, but not while the ship is not moving forward. And, I was also thinking of adding some kind of oval shield around the ship that activates on collecting a power-up, so that will make it even more difficult. It won't be easy to set it up, but it's worth a try, cuz' with line collision, you can get quik and precise collision detection.





Quote: "Using 3D models in a side scroller would look really nice! Collisions would need something powerfull like Sparky's. I wouldn't worry about speed though; most computers can handle something like that."

Yeah, the idea is to make the models (spaceships, aliens, etc...) 3D, and for the world (collision) objects, textured plaines.
I will definately need the fastest collision possible, because this new game I'm making, will probably be for the netbook aswell.

Cheers

Slayer rules!!! Yeaaah, man!
dark coder
23
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 17th Sep 2010 05:17
Quote: "Can you explain that a bit more? "


Assuming your images have alpha channels or transparent colours, it's trivial finding out if a certain pixel is a solid wall or free space. What you need to do is scan the image until you hit a solid pixel then plot the start of a line there, you then need to check the surrounding pixels to find where the edge of that surface leads, then begin traversing the edge and once the angle of the surface changes by some significant amount(i.e. you hit a corner), then drop a line and continue. Once done you should have an array of lines comprising the collision walls for your sprite, do this for all your objects then when you load the objects into your map, you generate a single collision mesh that uses all of these lines by converting them into planes.

However, such code isn't really that simple, especially if your alpha channels aren't 1 bit, and you require sub-pixel accuracy for the line detection. I've done this in C++ for my current project, so if you really want to do it in DBPro I can give you some more comprehensive details.

The far easier option would be to create a collision editor, where you load up a sprite and you manually draw lines. Also, the reason why you should use sparky's collision is because it very efficiently organises all objects within the scene making raycasts and such lighting fast, if you did the line collision yourself then it would never be as fast(understatement) if written in DBPro alone, and thus your game would be a lot more limited, assuming you care about FPS.

Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th Sep 2010 09:28
I think you'd be surprised actual DarkCoder, I used line-line and circle-line collision in a shoot em up a couple of years ago, and DBPro could handle it pretty well.
An editor is certainly the way to go if your adding line collision, but it can be basic as hell, so shouldn't take too long to write.

When I wrote a shmup, I decided to use rotation on the sprites, so I actually stored the angle and radius of each point, then translated this into lines with the sprites current angle - this is really handy, especially if scaling and rotation are involved.

The best shape I think for that ship is just a basic outline of the middle part, then just don't change it when the ship tilts. If you change the shape, then you could end up with some real unfair collision detection, because the player could be dead level, then they move up, and because the ship tilts, it might recognise a collision. If you keep the shape the same, then it'll make it possible to negotiate narrow spaces.

Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2026-07-24 23:12:35
Your offset time is: 2026-07-24 23:12:35