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.

Dark GDK / 2d sprite collision

Author
Message
Wikaman1
16
Years of Service
User Offline
Joined: 17th Aug 2008
Location: Scotland
Posted: 11th Sep 2008 23:10
hey, i've started work on my first 2d darkGDK project but i'm having trouble with the collision. The code snippet is just a circle and a wall. You control the circle and when you hit the wall I want it to stop. I just cant get it to work, Can someone please help?





Thanks
Cole Xemi
16
Years of Service
User Offline
Joined: 20th Aug 2008
Location:
Posted: 12th Sep 2008 02:40
Mista Wilson
16
Years of Service
User Offline
Joined: 27th Aug 2008
Location: Brisbane, Australia
Posted: 12th Sep 2008 12:12
you would need to add collision detection code into you main loop... basically create an integer value to hold the value that is returned by calling the dbSpriteCollision(isprite_a, isprite_b) function..

something like :

int icollision_holder = dbSpriteCollsion(isprite_a, isprite_b);

call that once each time you want to check for collision, in the main loop of the game somewhere, a value is assigned each time that function is called...

you would then just define a conditional, probably and "if" statement, to check the value of the integer icollision_holder. The values that function returns depend on the context in which you call it and the values its passed, essentially, if isprite_b is 0 the returned value will be the number of the sprite that isprite_a has collided with, otherwise it will return zero for no collision... if both isprite_a and isprite_b are sprites, the returned value will be either 1 or 0... 0=no collision, 1=those 2 sprites have collided.

once you have gotten that collision information, you would then need to write code to deal with it, for movement i guess you would need to check for if collision had occured after you get the input to move the sprite, but before you actually move it, if collision has occured, then you wouldnt allow that movement.... something like that.

(note you will also have problems if you use a whole sprite as a background image that is the size of the whole screen, it will be detected first for your collisions, so you would either need to disable it being detected or display as something other than a sprite maybe, or play around with sprite priorities and write individual detection code for each sprite )

Its a fun topic though, alot of good reading in these forums, and there is also some good examples of basic sprite collision detection and how to do something with that collision information in the Dark Invaders tutorial that comes with the DarkGDK download.

If it ain't broke.... DONT FIX IT !!!
Wikaman1
16
Years of Service
User Offline
Joined: 17th Aug 2008
Location: Scotland
Posted: 12th Sep 2008 20:55
omg i finally got it working, thanks Mista

Login to post a reply

Server time is: 2024-09-30 05:35:49
Your offset time is: 2024-09-30 05:35:49