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 / Physics restitution on player

Author
Message
Keneth
12
Years of Service
User Offline
Joined: 16th May 2012
Location:
Posted: 16th May 2012 22:32
Hi everybody

First of all, I'm new here, first time programming with AppGameKit but long time programming for the web.

So I began to create my first apps, a little game... and I had some questions for you.

First question is, I want my sprite to run an animation and when the animation end, the sprite should disppear... if I put the "SetSpriteVisible" just after the "PlaySprite", the sprite disppear immediatly... and if I put a "Sleep()" between, the animation wait the Sleep to end before starting...

Is there some sort of callback in functions ?

My second question is more for physics, I've a player that is moving with the Accelerometer, and I want it to "bounce" when he collides something... so I tested the "SetSpritePhysicsRestitution", but it doesn't seems to work... I think it's because when my player collides into something, my player "bounce", but because I'm always moving, the moving function just override the bounce and my player doesn't "bounce", he just push the other sprite.

So how can I make my player bounce when he collides ? Is there a way to see if my player is getting some "restitution" from a collide, and then don't launch the move function ?

I hope you could understand me and sorry if my english is bad, and ask me if you didn't understand everything.

Thanks a lot
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 17th May 2012 00:08 Edited at: 17th May 2012 00:08
You can try something like this:


How are you moving your player?

If you are manually setting the position, then the physics just won't work.

Cheers,
Ancient Lady
Keneth
12
Years of Service
User Offline
Joined: 16th May 2012
Location:
Posted: 17th May 2012 15:09
Hi,

Thanks for your answer, I've been able to make this animation works ^^

For the moving, yes I'm moving it manually (I get the X and Y from GetDirectionX / GetDirectionY, and I update the SpritePosition...

So yes, you're right that it just won't work...

So to move with physics, instead of updating the SpritePosition with the Accelerometer, I give my player some Impulse like that :

SetSpritePhysicsImpulse( player, GetSpriteX ( player ), GetSpriteY ( player ), x#, y# )

(Where x# is GetDirectionX and y# is GetDirectionY)

It seems to work, but the ball is moving really slowly (I tried to multiply x# and y# by 1000, but the ball still move slowly)

Is it the good way to make the player move with physics ?

Thanks
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 17th May 2012 15:41
Yes, or you can setSpritePhysicsVelocity(). Impulse or force are more natural for gradual changes in speed though. I guess it depends on the game.

There are a number of different ways of moving sprites using physics.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 17th May 2012 17:27
I use this combination:


If you use SetSpritePhysicsVelocity, the reactions are more immediate, but you loose the bounces.

Cheers,
Ancient Lady

Login to post a reply

Server time is: 2024-11-23 12:47:50
Your offset time is: 2024-11-23 12:47:50