LoadImageAsync Example


(Posted 1 year ago) RonTek

Loads an external image through URL then displays to screen after completion.

Import mojo

Class MyApp Extends App Implements IOnLoadImageComplete

    Field image:Image

    Method OnCreate()
        LoadImageAsync( "http://cdn.blitzcoder.org/images/logos/monkey-x.png",,,Self )
        SetUpdateRate 60
    End

    Method OnUpdate()
        UpdateAsyncEvents
    End

    Method OnRender()
        Cls
        DrawText "Hello World!",0,0
        If image Then
            PushMatrix
            Scale 0.5,0.5
            DrawImage image,DeviceWidth/2,DeviceHeight/2
            PopMatrix
        End If  
    End

    Method OnLoadImageComplete:Void( image:Image,path:String,source:IAsyncEventSource )
        If image Print "OK!" Else Print "ERR"
        Self.image=image
    End

End

Function Main()
    New MyApp
End

Reply To Topic

Please log in to reply