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 problem

Author
Message
pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 5th Feb 2018 05:01
Ok, I am messing around with physics this weekend, having never really used it before.... I try to put a sprite on the screen and apply gravity to it so it drops. That works but it doesn't fall all the way to the bottom. I turned on physics debugging and was surprised that the collision area was much larger than the sprite itself. I tried setting the sprite shape to polygon and then turning on physics but the collision shape was still way too large. I verified as the sprite was loaded that it was the correct size.

This is happening with every single sprite I try to put on the screen.

Am I missing something here?

Thanks,

Phil
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Feb 2018 09:02
Any example code? Your media?
pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 6th Feb 2018 02:56

Well, I started a new project with the same media files and now it works.

The sprite was animated in the first project, but not in the new one. That's the only difference.

I'll keep playing with it.
TrezSoft
AGK Tool Maker
11
Years of Service
User Offline
Joined: 8th Nov 2012
Location: UK
Posted: 6th Feb 2018 10:06
Normally its down to a change in the physics scale, so the scale of the physics system does not match the scale of the sprites displayed.

https://www.appgamekit.com/documentation/Reference/2DPhysics/SetPhysicsScale.htm

The above link explains it in more detail.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 6th Feb 2018 10:11
I find SetSpriteShape( spriteid, 3 ) usually does the job, but you MUST do this after you have created and positioned / scaled your sprite. If you move or resize your sprite AFTER creating the physics shape, then the sprite image and the physics system will be out of sync with each other. Use SetPhysicsDebugOn() to check if your physics shapes match up with your sprites.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 6th Feb 2018 12:46
It could be because you were using an animated sprite.
SetSpriteShape() does not create a unique shape for each frame. If you want that then it will need to be called every frame to readjust for the different sized sprite.
pjsmith67
8
Years of Service
User Offline
Joined: 2nd Feb 2016
Location: Nebraska, USA
Posted: 6th Feb 2018 16:05
Thanks for the all the suggestions! I will take a look at it today when I get some time.

Day job keeps getting in the way of my AppGameKit fun!
PHeMoX
6
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 7th Feb 2018 00:06
Quote: "It could be because you were using an animated sprite.
SetSpriteShape() does not create a unique shape for each frame."


True, however when you use the correct order of the commands, you can definitely set a correct polygon shape to a sprite with an alpha channel transparency. Animated sprites rarely really change their actual size anyway. You'd need to set up the animation stuff before setting the shape. Position doesn't matter, nor does scale from what I've found, although it is probably good practice to set up sprite to the correct size before either way.

fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 12th Feb 2018 03:15
I have found with animating sprites when you want to make a big animation change to an animating character calling SetSpriteShape(yourSpr,3 ) after the set sprite animation commands helps
This might help when for example you change from a moving animation to a jumping dieing one etc
fubar

Login to post a reply

Server time is: 2024-04-23 12:06:14
Your offset time is: 2024-04-23 12:06:14