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 / collision problem using dbSpriteCollision can still go true other sprites

Author
Message
Alahadi
14
Years of Service
User Offline
Joined: 24th Dec 2009
Location: Sweden
Posted: 15th Feb 2010 21:23


I move sprite number 2 from the south down on sprite number 3 when a collision appars sprite number 2 is pushed back.

But when I'm on the sprite from the south and presses up instead I will go inside the sprite.

I know it's becouse of my code that just moves the sprite in the opposed way if the dbSpriteCollision becouse true.

So I'm looking for a sulotion for this so I cant go true other sprites!
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 16th Feb 2010 10:53
You should check for collision after placing the sprite, not before. The collision is checked at the current position of the sprite (which is set by the dbSprite command), so if you check before moving it, you don't know if it will collide after you move it. Also, I don't see the reason for your "moved" variable, it does not change the behaviour of the program.

Try this code. Not tested, but it should work. First, declare two variables (int oldx, int oldy) before the main loop, to store the current position of the sprite. Then, store the coordinates of the sprite, move it, check for collision and if it collides, place it back to the previous position.



The dbWait command is not a great way to time a program. It passes for a first attempt but in the future you should use a proper timer. And "go true" should be spelled as "go through".

Login to post a reply

Server time is: 2024-11-20 03:30:42
Your offset time is: 2024-11-20 03:30:42