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 / Sprite collision wanted- but just with the visible pixels.

Author
Message
Mark Garrett
Reviewed AGK on Steam
20
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 12th Nov 2013 18:20
How do you make a sprite collide, but not with the transparency?

I have a triangle sprite with a transparent back-ground (you know, the square background part that we get when we load a bitmap and 'get the image'.)

So, I have succesfully made the triangle sprite with a transparent background. But..

I just want the visible triangle to collide with other sprites. But how can I do that? I don't want the transparent background to collide... just the visible triangle part of the sprite.

I have looked at other answers in this forum from 2010. But I need an updated answer for the DB-pro- version 1.077 (the contemporary version with coding language for todays db-pro version 1.077).

Man is a figment of God's imagination.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 12th Nov 2013 18:36
You could split the image in several sprite, or use the command point.
Quote: "
POINT

This command will return the pixel color value from the screen at the specified Coordinates"


I'm not a grumpy grandpa
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 12th Nov 2013 18:39
Your kinda on your own, but there are options.

Like, you could get Box2D collision and use that, that would automatically calculate the shape of the sprite and use a solid shape collision, probably the most straightforward option.

When I made a shoot-em-up, I needed line collision on sprites, and it's not easy - but with a line collision check it is possible to do it your own way, storing the lines and checking them against other sprites. For the work involved in that, paying as little for Box2D is probably a no brainer.

I am the one who knocks...
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 12th Nov 2013 18:42
Google Per-Pixel Collision and there are a ton of source codes on this that can easily be translated to DBP. There's a create XNA series that deals with everything 2d. That would be a start

"Get in the Van!" - Van B
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 13th Nov 2013 00:24
Chafari's suggestion of using the POINT command will work, although many decry the command as being too slow. (For those of us who aren't math geniuses, I feel this is an acceptable work-around.)

It's worked perfectly so far for my 2D game 'D-Zone' (I've recently learned there was already an old game called D!ZONE)

What I did was put a solid-colored sprite underneath all my enemy sprites, always with the same exact shape. To do a collision check, I simply called the POINT command to look for the unique solid color hidden underneath the enemy, which naturally excludes the transparent edges of the sprite.

D.D.
chafari
Valued Member
20
Years of Service
User Offline
Joined: 2nd May 2006
Location: Canary Islands
Posted: 13th Nov 2013 01:06
I know that the POINT command could be too slow if we try to make something big, but it works even as a collision system for our levels using arrays or memblocks ...an example:



Cheers.

I'm not a grumpy grandpa
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 14th Nov 2013 02:23 Edited at: 14th Nov 2013 02:24
Honestly, it's also fun to bold the word POINT because it seems to get the POINT across more effectively. It's easier to see, so people can POINT it out to their friends, family neighbors and coworkers.

Anyway, I'm sure you get my meaning...

D.D.
pcRaider
19
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 14th Nov 2013 13:56 Edited at: 14th Nov 2013 13:59
Cloggy's
Code Snippets / Pixel perfect collison for sprites
http://forum.thegamecreators.com/?m=forum_view&t=51743&b=6

Attachment: demo
https://forumfiles.thegamecreators.com/download/2496504

windowsXp
Mark Garrett
Reviewed AGK on Steam
20
Years of Service
User Offline
Joined: 10th Jul 2005
Location: California, US
Posted: 16th Nov 2013 19:49 Edited at: 16th Nov 2013 19:51
Thankyou,

Interesting, a lot to tinker with.

Cloggys demo works nice too.

.

Login to post a reply

Server time is: 2026-07-07 00:09:06
Your offset time is: 2026-07-07 00:09:06