'' ----------------------------------------------------------------------------
'' Irrlicht Wrapper For Imperative Languages - Freebasic Examples
'' Frank Dodd (2006-2010)
'' ----------------------------------------------------------------------------
'' Blitz-Irrlicht 1.8.3 Interface by Ed Musolino (AquaLung 2015)
'' ----------------------------------------------------------------------------
'' Example 47: Animation with 2D Images
'' This example draws a sequence of 2D images To the screen generating an
'' animation
'' ----------------------------------------------------------------------------

'' ////////////////////////////////////////////////////////////////////////////
'' Includes For extension libraries
Framework usr.birrlicht

'' ////////////////////////////////////////////////////////////////////////////
'' Global variables
' This wrapper uses a series of types To bring Type errors To your attention
' when passing variables into the wrapper
Global AnimationStrip:Int
Global screen_width:Int
Global screen_height:Int
Global frame:Int = 0
Global framesync:Float = 0

Const LAST_FRAME = 4

'' ////////////////////////////////////////////////////////////////////////////
' start the irrlicht interface. The scene will be rendered using the Irrlicht,
' software renderer, the display will be a window 400 x 200 pixels in size, the
' display will Not support shadows And we will Not capture any keyboard And
' mouse events
screen_width = 800
screen_height = 600
iIrr3D( screen_width, screen_height, 32, False )

' Set the title of the display
iAppTitle( "Example 47: 2D Animation" )

' Load bitmap images of important Open Source tools used in this development
' And store them in irrlicht texture objects
AnimationStrip = iLoadTexture( "./media/strip.tga" )

' make a note of the time 
framesync = iTime()'Timer

' erase the canvas To Yellow before rendering
iCameraCLSColor( 255,255,0 )

' While the scene is still running
While iRun() And (Not iKeyHit( KEY_ESCAPE ))
    ' begin the scene
    iBeginScene()

    ' first supply the texture, Then the destination co-ordinates, Then the
    ' co-ordinates of the rectangular area To copy And finally a flag To
    ' specify whether To use the alpha channel For transparency
    iDrawImageElement( AnimationStrip, (screen_width - 32) / 2, (screen_height - 32) / 2,frame * 64, 0, ( frame + 1 ) * 64 - 1, 63, True )

    ' check To see If 0.1 seconds have advanced since we recorded the time
    If iTime() - framesync > 500 Then
        ' record the New time
        framesync = iTime()
        ' advance To the Next frame
        frame = frame + 1
        ' If we have passed the last frame rewind To the begining
        If frame >= LAST_FRAME Then frame = 0
    EndIf

    ' End drawing the scene And render it
    iEndScene()
Wend

' -----------------------------------------------------------------------------
' Stop the irrlicht engine And Release resources
iEndIrr3D()

End 