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.

AppGameKit Classic Chat / sprite at rest?

Author
Message
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 2nd Mar 2012 16:21
Hi,
I.was wondering if anyone had any ideas of how I can detect if a sprite is resting on top of another sprite?
I'll give you some context as I can't just use getspritevelocity.
My application is a bit like Tetris, but uses gravity to control the sprites falling. The sprites also bounce when they hit the bottom. I would like to determine the maximum height of the sprites so I was hoping to cycle through the active sprites and only consider the positions of those at rest and on top of another sprite. I can't seem to find a command that will help me.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2012 17:12
You could just check its current velocity using getSpritePhysicsVelocityX() and getSpritePhysicsVelocityY()...

BraindeaD
16
Years of Service
User Offline
Joined: 30th Mar 2008
Location:
Posted: 2nd Mar 2012 17:12
Hi Ched80
why not using a sensor below the falling piece. If the sensor collides with another sprite set the gravity to 0 a put the y coordinate of falling piece just above the collided sprite. Just an idea.
You can use raycast, too...
Hope it helps a bit.

regards
Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 2nd Mar 2012 17:26
@baxslash, I tried that route first, but when a sprite got to the top of it's bounce it triggered in error.

@BraindeaD, I forgot about raycasting. Don't want to change the gravity as the bouncing sprites are part of the fun. I'll try combining raycasts with a timer.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2012 17:29
What about replacing sprites at rest with static / kinematic sprites?

(I say replace because you can't edit the state of a sprite you have to replace it with a new sprite)

Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 2nd Mar 2012 17:41
Sorry, I don't want to do that because I want the sprites to fall again if the spires below disappear.

Is there a way to detect if the sprite is sitting on another? If I could combine that with velocity I'd have a winner!

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 2nd Mar 2012 17:46 Edited at: 2nd Mar 2012 17:48
Have you tried using the contact loop?

You might be able to use the data retrieved to get what you want?

EDIT: That version is to check for contacts for a specific sprite. You might find using the other version faster:


Ched80
14
Years of Service
User Offline
Joined: 18th Sep 2010
Location: Peterborough, UK
Posted: 2nd Mar 2012 18:29
Cheers B, I'll try them and let you know how I get on.

Login to post a reply

Server time is: 2024-11-23 05:17:54
Your offset time is: 2024-11-23 05:17:54