AGK 2 - Animation example

By   2017-02-26

// Project: superfrogger
// Created: 2017-02-20
SetErrorMode(2)
// set window properties
SetWindowTitle( "superfrogger" )
SetWindowSize( 410, 720, 0 )
// set display properties
SetVirtualResolution( 410, 720 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 60, 0 ) // 30fps instead of 60 to save battery
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

CreateSprite ( LoadImage ( "street.jpg" ) )

// create a sprite with ID that has no image
CreateSprite ( 1, 0 )
// add individual images into an animation list
AddSpriteAnimationFrame ( 1, LoadImage ( "horse1.png" ) )
AddSpriteAnimationFrame ( 1, LoadImage ( "horse2.png" ) )
AddSpriteAnimationFrame ( 1, LoadImage ( "horse3.png" ) )
AddSpriteAnimationFrame ( 1, LoadImage ( "horse4.png" ) )

// play the sprite at 10 fps, looping, going from frame 1 to 5
PlaySprite ( 1, 8, 1, 1, 4 )
SetSpritePosition(1,0,250)
SetSpriteFlip(1,180,0)
carspeed = random(1,5)

do
    PinkX# = GetSpriteX (1)
    
    // move sprite pink1
    SetSpritePosition ( 1, GetSpriteX ( 1 ) + carspeed, 250 )
 
    
    if PinkX# > 400
        SetSpritePosition ( 1,-100,250)
        carspeed = random(1,2)
        SetSpriteColor ( 1, random(1,255), random(1,255), random(1,255), 255 )
    endif

    Sync()
loop

 

Loading...