Code: Select all
Repeat
DisplaySprite(#SpriteLink1,400,y)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
y+2
EndIf
Until whateverJust want a smooth animation from the moment the key is pressed.
Code: Select all
Repeat
DisplaySprite(#SpriteLink1,400,y)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
y+2
EndIf
Until whatever
Code: Select all
Enumeration
#WinMain
#SpriteLink1
EndEnumeration
UsePNGImageDecoder()
InitSprite()
InitKeyboard()
OpenWindow(#WinMain,0,0,800,600,"Screen Test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(#WinMain),0,0,800,600,1,0,0)
LoadSprite(#SpriteLink1, "C:\Users\horn\Desktop\link1.png", #PB_Sprite_AlphaBlending)
y=300
Repeat
evnt = WaitWindowEvent()
FlipBuffers()
ClearScreen(RGB(0,0,0))
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
y+2
EndIf
DisplaySprite(#SpriteLink1,400,y)
Until evnt = #PB_Event_CloseWindow

Code: Select all
UsePNGImageDecoder()
InitSprite()
InitKeyboard()
Enumeration
#WinMain
#SpriteLinkDown
#SpriteLinkUp
#SpriteLinkRight
#SpriteLinkRightStep1
#SpriteLinkRightStep2
#SpriteLinkLeft
EndEnumeration
Structure SprAttrib
x.i ;x and y coordinates for Link sprite
y.i
EndStructure
LinkSpriteToUse = #SpriteLinkDown ;Used to change sprite direction on key events.. Set initial direction - Down
Link.SprAttrib
;set initial coordinates for Link
Link\y=300
Link\x=400
OpenWindow(#WinMain,0,0,800,600,"Screen Test", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(#WinMain),0,0,800,600,1,0,0)
CatchSprite(#SpriteLinkDown, ?LinkSpriteDown, #PB_Sprite_AlphaBlending)
CatchSprite(#SpriteLinkUp, ?LinkSpriteUp, #PB_Sprite_AlphaBlending)
CatchSprite(#SpriteLinkRight, ?LinkSpriteRight, #PB_Sprite_AlphaBlending)
CatchSprite(#SpriteLinkRightStep1, ?LinkSpriteRightStep1, #PB_Sprite_AlphaBlending)
CatchSprite(#SpriteLinkRightStep2, ?LinkSpriteRightStep2, #PB_Sprite_AlphaBlending)
CatchSprite(#SpriteLinkLeft, ?LinkSpriteLeft, #PB_Sprite_AlphaBlending)
;Main loop
Repeat
evnt = WindowEvent()
FlipBuffers()
ClearScreen(RGB(0,0,0))
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
;Move down
Link\y+1
LinkSpriteToUse = #SpriteLinkDown
EndIf
If KeyboardPushed(#PB_Key_Up)
;Move up
Link\y-1
LinkSpriteToUse = #SpriteLinkUp
EndIf
If KeyboardPushed(#PB_Key_Right)
;Move Right
Link\x+1
LinkSpriteToUse = #SpriteLinkRightStep1
EndIf
If KeyboardPushed(#PB_Key_Left)
;Move left
Link\x-1
LinkSpriteToUse = #SpriteLinkLeft
EndIf
DisplaySprite(LinkSpriteToUse,Link\x,Link\y)
;less CPU usage
Delay(15)
Until evnt = #PB_Event_CloseWindow
DataSection
LinkSpriteDown:
IncludeBinary "C:\Users\horn\Desktop\linkdown.png"
LinkSpriteUp:
IncludeBinary "C:\Users\horn\Desktop\linkup.png"
LinkSpriteRight:
IncludeBinary "C:\Users\horn\Desktop\linkright.png"
LinkSpriteRightStep1:
IncludeBinary "C:\Users\horn\Desktop\linkrightstep1.png"
LinkSpriteRightStep2:
IncludeBinary "C:\Users\horn\Desktop\linkrightstep2.png"
LinkSpriteLeft:
IncludeBinary "C:\Users\horn\Desktop\linkleft.png"
EndDataSection


Code: Select all
If KeyboardPushed(#PB_Key_Right)
x+1
Counter + 1
If Counter > 4
Counter = 0
AnimFrame + 1
If AnimFrame > LastFrame
AnimFrame = FirstFrame
EndIf
EndIf
EndIf
Code: Select all
Dim Link( 3, 7 )Code: Select all
Dim Link( 3, 7 )
Link( 0, 0 ) = LoadSprite( #PB_Any, "LinkUpStep1.png" )
Link( 0, 1 ) = LoadSprite( #PB_Any, "LinkUpStep2.png" )
Link( 0, 2 ) = LoadSprite( #PB_Any, "LinkUpStep3.png" )
Link( 0, 3 ) = LoadSprite( #PB_Any, "LinkUpStep4.png" )
Link( 0, 4 ) = LoadSprite( #PB_Any, "LinkUpStep5.png" )
Link( 0, 5 ) = LoadSprite( #PB_Any, "LinkUpStep6.png" )
Link( 0, 6 ) = LoadSprite( #PB_Any, "LinkUpStep7.png" )
Link( 0, 7 ) = LoadSprite( #PB_Any, "LinkUpStep8.png" )
Link( 1, 0 ) = LoadSprite( #PB_Any, "LinkDownStep1.png" )
Link( 1, 1 ) = LoadSprite( #PB_Any, "LinkDownStep2.png" )
Link( 1, 2 ) = LoadSprite( #PB_Any, "LinkDownStep3.png" )
...
Link( 2, 0 ) = LoadSprite( #PB_Any, "LinkLeftStep1.png" )
...
Link( 3, 0 ) = LoadSprite( #PB_Any, "LinkRightStep1.png" )Code: Select all
DisplaySprite( Link( Direction, AnimationFrame ), Link\x, Link\y) Code: Select all
Repeat
evnt = WindowEvent()
FlipBuffers()
ClearScreen(RGB(0,0,0))
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
x-1
FrameCounter+1
If FrameCounter > 4
FrameCounter = 0
Frame +1
LinkSprite = Link(0,Frame)
If Frame = 8
Frame = 3
EndIf
EndIf
EndIf
DisplaySprite(LinkSprite,x,y)
Until evnt = #PB_Event_CloseWindow
well, not at all...ignign0kt wrote:I don't really know how to code 'If key isn't being pressed and the last pressed was Left, then LinkSprite = Link(0,0)'
Code: Select all
AnimationFlag = 0
If KeyboardPushed(#PB_Key_Left)
x-1
Direction = 0
AnimationFlag = 1
EndIf
If KeyboardPushed(#PB_Key_Right)
x+1
Direction = 2
AnimationFlag = 1
EndIf
If KeyboardPushed(#PB_Key_Up)
y-1
Direction = 1
AnimationFlag = 1
EndIf
If KeyboardPushed(#PB_Key_Down)
y+1
Direction = 3
AnimationFlag = 1
EndIf
If AnimationFlag = 1
FrameCounter+1
If FrameCounter > 4
FrameCounter = 0
Frame +1
If Frame > 4
Frame = 1
EndIf
EndIf
Else
FrameCounter = 0
Frame = 0
EndIf
LinkSprite = Link( Direction, Frame)