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.

Newcomers DBPro Corner / When two sprites hit or collide, They stick together

Author
Message
claudio
21
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 12th Jan 2006 22:24
I have a small bit of code here and I was wondering if anyone would be kind enough to tell me why the two sprites in my code stick together when they collide. The images I am using in the code are two bitmap boxes that I created in Paint for quick demonstration purposes. They are 40 by 40 pixles.

Thank you for your help
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 13th Jan 2006 08:58 Edited at: 13th Jan 2006 09:02
please use the code tags instead of the code box during message entry. like this:

[C0DE]

place
code
here

[/C0DE]

it will tuck your code away until someone opens it. like this:



so, since we can't see your code until you do that, about all i can do is ask if you're moving the sprites away from eachother once the collision is detected?

My Modest System:
Athlon XP1800+, Windows XP+SP2, Soyo K7V Dragon+ MB, 1.5Gb 333 RAM, ATI Radeon 8700LT (128Mb), Drivers and Updates Kept Current
claudio
21
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 13th Jan 2006 16:37
Sorry about that. Here's another try.

Also I should mention that I am using DBP with upgrade 5.7

Thank you again

[CODE]
sync on : sync rate 30
set display mode 800,600,16
backdrop on : color backdrop rgb(0,0,0)

load image "yell.bmp",1,1
load image "blue.bmp",2,1

yx=320
yy=320
bx=400
by=400

sprite 1,yx,yy,1
sprite 2,bx,by,2

do
oldyx=yx
oldyy=yy

if leftkey()=1 then yx=yx-5
if rightkey()=1 then yx=yx+5
if upkey()=1 then yy=yy-5
if downkey()=1 then yy=yy+5

if sprite collision(1,2)=1
yx=oldyx
yy=oldyy
endif

sprite 1,yx,yy,1


sync
loop
[/CODE]
Flashing Blade
22
Years of Service
User Offline
Joined: 19th Oct 2002
Location: United Kingdom
Posted: 13th Jan 2006 17:13
Try putting this line:
sprite 1,yx,yy,1
before the collision check.
i.e.:


becomes:




The word "Gullible" cannot be found in any English Dictionary.
claudio
21
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 13th Jan 2006 20:08
Well now, that was easy. Works like a champ! Thank you.

Login to post a reply

Server time is: 2024-11-27 07:26:00
Your offset time is: 2024-11-27 07:26:00