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 / dbSpriteCollision() not working properly.

Author
Message
Pog Mo Hone
14
Years of Service
User Offline
Joined: 21st May 2010
Location:
Posted: 11th Jun 2010 23:50
I have a simple ball and paddle game. I have a list of commands for the ball to bounce off the walls and it does that just fine. I set up the dbSpriteCollision() function to bounce the ball off accordinly when hitting the paddle but what it does it slide along the paddles length then will bounce off when reaching the edge. Should I forget this command and use RECT or something?

"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 12th Jun 2010 03:04
To be of any help, we would need to see the code. Show us your collision code (or response code)...

JTK
Pog Mo Hone
14
Years of Service
User Offline
Joined: 21st May 2010
Location:
Posted: 12th Jun 2010 21:26
[// update the ball in game
void ballUpdate(void)
{
//Ball moves, if reaches wall, bounces off
iBallX -= iBallSpeedX;
iBallY -= iBallSpeedY;

if(( iBallX < 10) || ( iBallX > 1020))
{
iBallX += iBallSpeedX;
iBallSpeedX *= -1;
}

if( iBallY > 735)
{
iBallY += iBallSpeedY;
iBallSpeedY *= -1;
g_bPlayerHit = true;
}

else if( iBallY < 80)
{
iBallY += iBallSpeedY;
iBallSpeedY *= -1;
}

if(dbSpriteCollision(2,1) == 1)
{
iBallY += iBallSpeedY;
iBallSpeedY *= -1;
}

}]

"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 13th Jun 2010 01:23
I've had this issue before when I've made pong. It's because of the speed of the ball.

It's kinda hard to illustrate this without a diagram, but I will try since I don't feel like drawing something.

Okay, let's say your paddle is 8 pixels in width, and your ball is the same. But the speed is set at something like 2 pixels per refresh. (every time the screen updates, it moves two pixels).

Well, when using dbSpriteCollision(), it checks to see if the bounding boxes are colliding. And what I can gather from your collision code, is that if the paddle collides with the ball, it makes the speed negative.

The issue is that sometimes, you may move the paddle (like trying to make a save), so that it touches the edge. And when this happens, it gets "caught". How I mean this, is take a look at the width's of the paddle and ball sprites (8 pixels as we set up earlier), yet the speed variable is only 2. So if you turned off the collisions, it would take about 4 screen refreshes for the ball to pass through the paddle.

Using that math, lets say that you make a save and the Ball's X position collides with the paddle about 5 pixels in. The collision code will kick in and tell the program to reverse the direction of the ball (a.k.a. "iBallSpeedY *= -1;"). So then then the ball goes in the reverse direction, and it's now 3 pixels into the paddle's width. What happens next? The collision code kicks in again and reverses the direction. This will keep on happening until the ball reaches the other end of the paddle, where it can escape.

Understand?

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 13th Jun 2010 09:01
In that case, try using dbSpriteHit instead of dbSpriteCollision. The difference is that dbSpriteHit triggers only once and it does not trigger again until the sprites leave each other, then collide again. dbSpriteCollision triggers continuously as long as the sprites overlap.
haliop
User Banned
Posted: 13th Jun 2010 10:12
i also had some problems with this, what i did is i founf a simple static geometry library and used it in the project, what it does, it takes the "vectors" of the image and keep them no matter the rotation or if its upside down.. so collision made really easy.
i dont remmber where this lib is , but once i found it,it was pretty easy to use.
Pog Mo Hone
14
Years of Service
User Offline
Joined: 21st May 2010
Location:
Posted: 14th Jun 2010 22:03
Cuddle, I believe I see where you are coming from. But not really sure how to use the information to adjust it. dbSpriteHit has the same results, so it doesnt seem to work either.

"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 15th Jun 2010 01:11
Well, you could make a system to check if it's stuck.



Understand?

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
Pog Mo Hone
14
Years of Service
User Offline
Joined: 21st May 2010
Location:
Posted: 16th Jun 2010 07:09
Good call Cuddle! Thank you! Works beautifully now. YAY!

"Wisemen say: Forgiveness is divine, but never pay full price for late pizza." - Michaelangelo

Login to post a reply

Server time is: 2024-11-19 23:07:56
Your offset time is: 2024-11-19 23:07:56