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.

DarkBASIC Professional Discussion / sprite hit flag confusion

Author
Message
jerryd
13
Years of Service
User Offline
Joined: 20th Feb 2013
Location:
Posted: 8th Mar 2013 04:47
DarkBasic forum,

After I use the command "IF (SPRITE hit(x,y)" the sprite hit
flag seems to be cleared.

I want to reset the flag before another SYNC command so I do
a command sequence like this:

IF (SPRITE HIT(x,y)) = 1
SPRITE n, xloc, yloc, 3 'set the hit flag again
WHILE (SPRITE HIT(n,12) = 1)
more code
more code
SPRITE n, xloc, yloc, 3 'set the hit flag again
more code
more code
ENDWHILE
ENDIF

But the flag doesn't get set by the "SPRITE x, xlco, yloc, 3"
command after IF/ENDIF or inside the WHILE/ENDWHILE.

Any suggestions?

jerryd
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 10th Mar 2013 00:08
It does indeed get reset after calling the function.
The easiest way to save it throughout the current frame is to simply store the return value to a variable like so:



"Why do programmers get Halloween and Christmas mixed up?"
jerryd
13
Years of Service
User Offline
Joined: 20th Feb 2013
Location:
Posted: 10th Mar 2013 01:01
Rodolpho,
Thanks for the reply.

I could save the status but I'm trying to move a sprite back
to a place where it's not overlapping another sprite as the
AUTOMATIC OBJECT COLLISION does for 3D objects.

So I want the flag to get set again with the "sprite x, xloc ,yloc, 3"
as I move it back 1 pixel at a time without executing a SYNC command.

Is there a way to do this?
jerryd
Rudolpho
20
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 10th Mar 2013 01:24 Edited at: 10th Mar 2013 01:25
I'm not sure... the built-in sprite collision commands are honestly really poor. Your best bet might be to implement some sort of line collision system yourself. The built-in system uses the rectangles of the sprite images, never minding any transparent pixels. If this is all you would just check if any corner of each rectangle lies within the coordinates encompassed by the other one. It gets a bit more complicated if the sprites can have arbitrary rotation, but I'm sure something can be found by googling for "collision detection rotated rectangles" or similar.

If you just want to reset the sprite to it's oldest non-colliding position I would store the last good position and reset to that one.
Something like this:



"Why do programmers get Halloween and Christmas mixed up?"
jerryd
13
Years of Service
User Offline
Joined: 20th Feb 2013
Location:
Posted: 10th Mar 2013 02:04
Rodolpho,

Thanks for the suggestions.

I did try saving the previous locations but since the speed or
pixels per move is variable and I'm doing a rocochet sometimes
the old position puts the sprite in a place that looks wrong
on the screen. That's why I don't want to do a SYNC while
relocating the sprite.

The sprite is 2D, loaded as an image and is a .png file. If I
could make the sprite an object I could use the "AUTOMATIC
OBJECT COLLISION" command. Is there a way to do that?

jerryd
pcRaider
19
Years of Service
User Offline
Joined: 30th May 2007
Location:
Posted: 10th Mar 2013 05:52 Edited at: 10th Mar 2013 05:55
Quote: "If you just want to reset the sprite to it's oldest non-colliding position I would store the last good position and reset to that one."


Login to post a reply

Server time is: 2026-07-08 12:26:46
Your offset time is: 2026-07-08 12:26:46