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 animation problem

Author
Message
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 7th Jun 2012 21:55
I am trying to get a sprite to move and play the correct walk animation for the movement. I thought I figured it out but when I call the animation it says the sprite doesn't exist. I created the sprite well before the animation. Everything works except adding in the moveSpriteRight function and moveSpriteLeft function.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 7th Jun 2012 22:25
After typing everything below, I spotted your problem. You hav not declared 'digger' to be a global variable. So it is not visible to your two functions. When they try to play the sprite, they see digger as a value of zero. You should also stop playing the sprite before you set it to play a different piece, just to keep AppGameKit unconfused.

Assuming your image file is in your media directory, try using "/media/digger.png" in your loadImage call.

Also try it without resizing the sprite, just to make sure it is loading.

Are you using percentage or pixel positions? I'm guessing percentage, based on a sprite size of 10.

Cheers,
Ancient Lady
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 8th Jun 2012 18:15
Face to palm!!! I missed the global. D'OH!!! I added in the stop sprite function. The only problem now is that it doesn't play through the sprite. It will change direction but only play the first frame of the playSprite function. Even if I take out the stop sprite it still does not work. Also I am not sure if where I put the stop sprite is the best location.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 8th Jun 2012 18:24
I tried your code with a blank sprite (and no animation).

The sprite didn't move.

You need to initialize the direction variable to 1. Then the sprite moves back and forth.

Also, you don't want to call moveSpriteRight/Left every loop. It constantly resets the frame. You should only call it when the direction changes. Like this:


Cheers,
Ancient Lady
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 9th Jun 2012 06:56
I used your code and it worked. The only thing I was missing was to call the moveSpriteRight() at the beginning of the code.

I did not include all of my code only the part that I thought was the problem. I may have missed something.
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 9th Jun 2012 18:48
I'm glad I could help.

Happy Programming!

Cheers,
Ancient Lady
serandre
11
Years of Service
User Offline
Joined: 14th Sep 2012
Location:
Posted: 21st Sep 2012 23:52
Hello,

I have a similar problem. I have a png with 26 frames but canĀ“t see other frames after the animation is initialized. This is driving me crazy. Tried stopanimation, resume, etc... nothing works...


SetVirtualResolution ( 640, 480 )

rem Background image 640x480
CreateSprite ( LoadImage ( "grass.jpg" ) )

rem Horse Animation (26 frames), eating:Frame 1-14, walking:Frame 15-26
horse = CreateSprite ( LoadImage ( "horse_animation.png" ) )
SetSpritePosition ( horse, 20, 200 )
SetSpriteAnimation ( horse, 144, 144, 26 )

rem Horse begins to walk
PlaySprite ( horse, 10, 1, 15, 26 )

rem Horse is not eating
eating = 0

do
if (eating = 0)
x = GetSpriteX(horse)
if (x > 480) rem After horse walks > 480 it needs to eat... And boy it will not STOP! (flag eating=1 forever)
eating = 1
PlaySprite ( horse, 10, 1, 1, 14 )
elseif (x < 480) rem If not continues walking
SetSpritePosition ( horse, x+1, 200 )
endif
endif
Sync ( )
loop
serandre
11
Years of Service
User Offline
Joined: 14th Sep 2012
Location:
Posted: 22nd Sep 2012 00:12
OPS! Sorry, my mistake at elseif (x < 480) must be (x <= 480)... Fixed...

Well, not to loose the travel... How to put a Code snipet in the message ?
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 22nd Sep 2012 00:36 Edited at: 22nd Sep 2012 00:37
Can you post the image you are using? Then I might try your code.

Also, you are using a frame rate of 10 to display 11 and 14 frames. The default frame rate for apps is 60. That might have an affect on which frames you see, I'd have to play with the code to check that.

Edit: What version of AppGameKit are you using? And, are you seeing this on your PC or in a Player? If in a Player, how sure are you that it is the same version as your PC AppGameKit?

Cheers,
Ancient Lady
AGK Community Tester
bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 23rd Sep 2012 21:13
you can use any frame rate without problems.
works fine at this end
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 23rd Sep 2012 22:27
Quote: "
Well, not to loose the travel... How to put a Code snipet in the message ?
"




Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 23rd Sep 2012 23:45
Quote: "Face to palm!!! I missed the global. D'OH!!! I added in the stop sprite function. The only problem now is that it doesn't play through the sprite. It will change direction but only play the first frame of the playSprite function. Even if I take out the stop sprite it still does not work. Also I am not sure if where I put the stop sprite is the best location."

I spent the whole day trying to find a bugg in my code as the spike traps did show on my computer but not on android.

The problem whas that i neaded to start the file manager and delete the game project inside the agk folder on the phone.

The player didt update the map file when i broadcasted it to the phone

Sometimes do you have one of those days where the brain rests while coding

Android 2.3 Gingerbread , ZTE Skate , 480x800 , 800 mhz cpu , Samsung Galaxy Y , 240x320 , 832 mhz cpu
Android 4.0 Sandwich , Dmtech 3g 9738B , 1024x768 , 9.7 inches , cortex A8 1.2 cpu , 1 gb ram.

Login to post a reply

Server time is: 2024-05-04 20:15:25
Your offset time is: 2024-05-04 20:15:25