Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
13.2 Load a sprite atlas and pull the player animation from it.
Class Game Extends App
'......................
Field current_level:Int
' add field to hold new sprite sheet
Field game_sprite_atlas:ftSpriteAtlas
'.......................
Method OnCreate()
Self.engine = New CustomEngine
play_scene = engine.GetDefaultScene()
play_layer = engine.GetDefaultLayer()
play_scene.AddLayer(play_layer)
'Load the sprite sheet before creating the player
LoadGameSprites()
CreatePlayer()
'................
End
' load the image into a sprite atlas
Method LoadGameSprites()
game_sprite_atlas = New ftSpriteAtlas
game_sprite_atlas.Load("tutorial_game_sprite_sheet.png", "tutorial_game_sprite_sheet.txt")
End
'........................
Method CreatePlayer()
' load player sprite from sprite atlas
Local box:ftObject = engine.CreateAnimImage(game_sprite_atlas.GetImage("player_submarine_anim"), 0, 0,
128, game_sprite_atlas.GetImageHeight("player_submarine_anim"), 3, engine.GetCanvasWidth()/2, engine.GetCanvasHeight()/2)
box.SetMaxSpeed(20.0)
box.SetMinSpeed(-20.0)
box.SetColGroup(PLAYER_GROUP)
box.SetColType(Self.engine.ctBox)
box.SetText("PLAYER")
Local projectile_type:ProjectileType = New ProjectileType()
Self.player = New Character(box, projectile_type, 0, 3, "PLAYER")
End
'..................
End
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment