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 / Multiple sprite collision question

Author
Message
jerryd
7
Years of Service
User Offline
Joined: 20th Feb 2013
Location:
Posted: 4th Mar 2013 04:14
DarkBasic forum,

I have 3 images loaded and define them as multiple sprites:

SPRITE 1, XLOC, YLOC, 1
SPRITE 2, XLOC, YLOC, 1
SPRITE 3, XLOC, YLOC, 1

SPRITE 1, XLOC, YLOC, 2
SPRITE 2, XLOC, YLOC, 2
SPRITE 3, XLOC, YLOC, 2

SPRITE 1, XLOC, YLOC, 3
SPRITE 2, XLOC, YLOC, 3
SPRITE 3, XLOC, YLOC, 3

How do I distinguish between sprite number and target sprite
number when doing collision checking?

ex:
if collision(1,1) then .....

Jerryd
pcRaider
13
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 4th Mar 2013 12:44
Quote: "The target sprite number, and 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
"


sample-code
jerryd
7
Years of Service
User Offline
Joined: 20th Feb 2013
Location:
Posted: 5th Mar 2013 03:20
pcRaider,
Thanks for the reply but I don't think it solves my problem
If the "num" returned is a 1 and there are 2 different
sprites that are number 1 but from different images how
do I know which sprite is overlapping?

Jerryd
Chris Tate
DBPro Master
11
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 5th Mar 2013 20:13 Edited at: 5th Mar 2013 20:13
Generally speaking, all sprites should have their own IDs. Your code is recreating sprite numbers 1, 2 and 3 each time you specified those values as the first parameter.

You appear to be creating 9 sprites, so number them 1 to 9, then test their collision against other IDs.



pcRaider
13
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 5th Mar 2013 23:41 Edited at: 5th Mar 2013 23:42
Quote: "pcRaider,
Thanks for the reply but I don't think it solves my problem
"


num = SPRITE COLLISION(Sprite_Number, Target_Sprite_Number)

When you are unsure of which sprite may have been hit, you can use 0 for Target_Sprite_Number.
This will return the Sprite number of any sprite struck by sprite_1.
If no sprite has been hit , then zero is returned .
For sample , you could discover the ID of any sprite struck by sprite_1 with the code.

Login to post a reply

Server time is: 2020-08-03 15:27:26
Your offset time is: 2020-08-03 15:27:26