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 / PlaySprite Interferes with Physics?

Author
Message
Wilf
Valued Member
18
Years of Service
User Offline
Joined: 1st Jun 2006
Location: Gone to Unity.
Posted: 16th Oct 2013 21:40
Hola all,
I've been working on a game with my son, using Baxslashes Boxman demo as its base. I've run into problems making the player sprite switch between two sets of frames for running and jumping. They are all on one sprite sheet.

Problem 1, line 84 - if the sprite is moving, why do I need to put the PlaySprite after the else command? The animation should only play when the character is not moving?

Problem 2, line 134 - why does running the PlaySprite command to show the jump animation frames inhibit the physics from jumping properly?



Project with spritesheet attached. Any help appreciated!

Attachments

Login to view attachments
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 16th Oct 2013 22:55
I have not tired these solutions, but here goes:

I think "BoxmanVel => 1" should be "BoxmanVel >= 1". Doesn't report as an error but I believe this could be the cause.

Next, try putting PlaySprite() before setSpritePhysicsVelocity(). That could work. As for why, I don't know. I have not mixed playsprite with physics yet.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 16th Oct 2013 23:03
I see a lot of things in your code that don't look right.

First, please put commas between things in the global statement and don't use the ':' to combine lines (it confuses things) with the global statement.

I do suggest that you use global variables for the width and height of boxman and set them once, after the sprite is fully created. This will save a bunch of processing time.

Your first 'wierd' thing about the sprite only playing when boxman is moving is because, if it is standing still, you continually call PlaySprite and reset it back to the first frame. You need to detect a change in state and start or stop the playing at that point, not every time you check for control.

Assuming that you want the sprite to play when velocity is not zero, try something like this..

Before you set up anything:


Replace entire if/else/endif block starting with 'if BoxmanVel <= -1' to


As for your second wierd, what happens if you move the SetSpritePhysicsVelocity command after the PlaySprite call?

Are the animation images of different sizes in your Atlas? (No, I did not download your whole project and I don't plan to.)

If they are all the same size, they can all go in one file and you can use the much simpler SetSpriteAnimation command instead of the complex method you are using for loading the animation.

It is also a bad idea to use the 'end' command inside a function as you are. Instead, make keyboardInput return 1 if escape is pressed or zero otherwise. Then, in your main do loop, use 'if keyboardInput() = 1 then exit' and add the 'end' command right after the 'loop' command. This gives AppGameKit a chance to clean up properly and is less likely to cause an issue in non-windows platforms. And putting the 'end' command after the 'loop' command makes sure that any code following it (like your subroutine) doesn't accidentally get executed when it shouldn't.

And why are you using a subroutine call/jump instead of it being a function? (This question is something that has been known to cause all sorts of arguments about the pros and cons of subroutines. I am just curious about why you are using it, not that you shouldn't {and I wouldn't, but that is my style}.)

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Wilf
Valued Member
18
Years of Service
User Offline
Joined: 1st Jun 2006
Location: Gone to Unity.
Posted: 17th Oct 2013 00:26
@Digital Awakening, making those changes didn't help but thank you.

Ancient Lady, your snippet fixed the flickering sprite issue I had experimented with states but your solution is much simpler. Thank you, also for the 'End' tip.

I am using the complex method for animations because it allows me to fit more sprites on the sheet, thus smoother animations. SetAnimationFrame limits me to 64 128x128 frames on a 1024x1024 sprite sheet with a lot of wasted space, whereas I can get well over 100 frames using SubImages, AddSpriteAnimationFrame and TexturePacker. I've attached a zip with two spritesheets to illustrate.

I use a subroutine to setup the level purely because thats what Baxslash used in the original snippet. I try not to second-guess him

Moving SetSpritePhysicsVelocity to after the PlaySprite call doesn't change the behaviour - the jump starts but immediately stops as if hitting something or the velocity has been cut. Spamming Jump sometimes does get it to work on the 2nd or 3rd attempt for some reason.

Moving the velocity change out of that if block and triggering it by a 'jump= 1' also does nothing. Possible AppGameKit bug where changing the sprite frame reference zeroes out velocity maybe?

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 17th Oct 2013 00:43
I can see the logic to using SubImages instead of SetSpriteAnimation if there are a lot of frames. So far, none of my animations are very big. Two are 16 50x50 frames, 1 wide by 16 down (50x800 total). I have discovered that it isn't always necessary to use a power of 2 image file. Most of mine aren't. Another set are 8 76x76 frames (8x1 layout) for total size of 608x76. And another with 12 60x60 frames (6x2 layout) for total size of 600x200. And this Tier 2 WIP plays perfectly in all tested platforms (iOS, Mac, Windows, Android) and devices (iPad 2 iOS 6, iPad 3 iOS 7, iPod Touch iOS6, and a bunch of Android devices, including a Kindle Fire HD). Pretty much all of my images are not power of two, but they all have even dimensions.

Quote: "Possible AppGameKit bug where changing the sprite frame reference zeroes out velocity maybe?"

If I can find the time tomorrow, I'll see if I can do a quick test on this.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master

Login to post a reply

Server time is: 2024-11-24 22:40:57
Your offset time is: 2024-11-24 22:40:57