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.

Newcomers AppGameKit Corner / How do I make a still image change to an animation when its moving and back to a still image when its not!

Author
Message
Zikasuo
7
Years of Service
User Offline
Joined: 15th Jul 2017
Location:
Posted: 15th Jul 2017 05:46
I'm very new to coding overall, in face I just started. But what i'm trying to do is use an animated sprite for when the sprite moves and go back to a still image when there isn't any imput. I've achieved this but I put both sprites on top of each other just changing their alpha's so you don't see the still when you're moving your player, and vice versa for when its still.

I tried setting the position of the opposing sprite off the screen and bringing it back in but I didn't have any luck if anybody has any tips or ideas it would be greatly appreciated! -THANKS IN ADVANCE

This is my code



SetWindowTitle( "animating from a sprite sheet." )
SetWindowSize( 1920, 1080, 0 )

// Screen
SetVirtualResolution( 1920, 1080 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetWindowAllowResize(1)
print (Screenfps())

//Animation
Astronaut=loadimage("Astronaut.png")
CreateSprite(2,Astronaut)
SetSpritePosition(2,2000,1100)
SetSpriteAnimation(2,64,64,6)

//Screen controll Make the sprite not go off the screen
//If X#>GetVirtualWidth()-GetSpriteWidth(2) <-------------- I tried to make it so my sprites wouldn't be able to go off the screen, didn't work so I commented it out
// X#= GetVirtualWidth() -GetSpriteWidth(2)
//Endif


//images and basic position
loadimage(2,"still.png")
CreateSprite(1,2)
SetSpritePosition(1,960,540)


do
x# = GetSpriteX(1)
y# = GetSpriteY(1)

//Physics
//SetSpritePHysicsOn(2,2)
//SetSpritePhysicsOn(1,2) <-------------- the physics of both sprites collide with each other so I commented them out
SetPhysicsWallBottom(1)
SetPhysicsWallTop(1)
SetPhysicsWallLeft(1)
SetPhysicsWallRight(1)


// A KEY
If GetRawKeyState(68)
SetSpritePosition ( 2 , GetSpriteX ( 1 ) + 3 , GetSpriteY ( 1 ) + 0 )
SetSpritePosition ( 1 , GetSpriteX ( 1 ) + 3 , GetspriteY ( 1 ) + 0 )
setspriteflip(2,0,0)
SetSpriteColorAlpha(1,0)
Endif


If GetRawKeyPressed(68)
playsprite(2)
SetspritecolorAlpha(2,255)
Endif

If GetRawKeyReleased(68)
setspritecoloralpha(2,0)
setspritecoloralpha(1,255)

Endif

// D KEY
If getRawKeyState(65)
setspriteflip(2,1,0)
SetSpritePosition ( 2 , GetSpritex ( 1 ) -3 , GetSpritey ( 1 ) + 0 )
setspritePosition ( 1 , GetSpriteX ( 1 ) -3 , GetSpriteY ( 1 ) + 0 )
SetSpriteColorAlpha(1,0)
Endif

If GetRawKeyPressed(65)
playsprite(2)
SetSpriteColorAlpha(2,255)
Endif

if GetRawKeyReleased(65)
SetSpriteColorAlpha(2,0)
SetSpriteColorAlpha(1,255)
Endif


sync()
loop




Zikasuo
7
Years of Service
User Offline
Joined: 15th Jul 2017
Location:
Posted: 15th Jul 2017 05:50
I guess what I'm trying to ask is how can I create a box so my sprite won't go off the screen with this setup!
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 15th Jul 2017 10:43
set a frame for the still image then swap to that frame using
SetSpriteFrame(id,#)
or swap image of the sprite directly using
SetSpriteImage(sprid,imageid)

but this won't help with positioning, for positioning the best option is to check inside the code used to move the sprite, something like this
If GetRawKeyState(68)
newx = GetSpriteX ( 2 ) + 3
if newx < GetVirtualWidth()-GetSpriteWidth(2)
SetSpritePosition ( 2 , newx , GetSpriteY ( 2 ) + 0 )
endif
life\'s one big game
spec= 2.6ghz, 1gb ram, 512mb gpu, directx 9.0c, dbpro and classic
Zikasuo
7
Years of Service
User Offline
Joined: 15th Jul 2017
Location:
Posted: 15th Jul 2017 16:22
Thanks a million Smallg, Never thought about running it as one sprite and just playing certain frames when imput is detected!

Login to post a reply

Server time is: 2024-11-22 16:02:55
Your offset time is: 2024-11-22 16:02:55