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 / Help with sprite collision

Author
Message
negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 22nd Dec 2011 23:42
Hay im making my own version of Asteroids and for some reason the collision isnt working. its not returning true.

here is the code for the classes i made to contol the asteroids and bullets

Bullet Class


Asteroid Class


I even tryed to check for a collision not even using the classes so please tell me what im doing wrong

thanks for any help

All is revealed with time.
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 23rd Dec 2011 08:40
how do you store/collect your bullets/asteroids?
this should work, if you're using vectors for example

this should be somewhere in your game loop

negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 23rd Dec 2011 09:02
Well im making them in an array of objects and the problem im having is when I use dbSpriteCollision() or dbSpriteHit() and they both keep returning true constantly even when the sprites arent colliding.

All is revealed with time.
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 23rd Dec 2011 14:47


First, are you sure that "HitId" is greater than zero?


GDK Docs say:

Quote: "If a target sprite has not been specified and a value of zero has been used, this command will return the sprite number of any sprite overlapping it.
"


So basically, if HitId == 0 and you have a background sprite, then the return value would be the background sprite's id. Try changing your code to:



This way, you can place a break-point on the line and see what the real return value is. The reason it's important to know the real value returned is becase any non-zero value will be true when converted to bool; only zero will be false when converted. So, if any other value besides zero is returned by dbSpriteCollision(), your BulletHit() method will return true.

I hope this helps,

JTK
negi
13
Years of Service
User Offline
Joined: 16th Feb 2011
Location:
Posted: 23rd Dec 2011 21:05
It did help but I tryed loading another image not using a class and cheking if there is a collision with she sprite I have as the ship and the return is still true. so I made a seperate game using the same two sprites and code for collision and it works just fine so it must be a problem with my game.

I will upload the whole project file to see if you can see what I must be missing. And thanks so much for your help

All is revealed with time.

Attachments

Login to view attachments
bad ass little venom
12
Years of Service
User Offline
Joined: 28th Dec 2011
Location:
Posted: 29th Dec 2011 21:09 Edited at: 30th Dec 2011 07:58
i cant solve this post easily but ok u have a sprite 30 by 30. 30 is to the top and 30 is to the bottom ur image within this might only be 10 by 25 but in dark gdk what u dont see by the color key is still there and the size of the image is the endge were the collision will happen being 30 30

spider

Login to post a reply

Server time is: 2024-10-02 21:36:29
Your offset time is: 2024-10-02 21:36:29