Skip to content

Instantly share code, notes, and snippets.

@codetravis
Last active February 3, 2017 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codetravis/92ac8713406834f758ce5c8f1c4f8f23 to your computer and use it in GitHub Desktop.
Save codetravis/92ac8713406834f758ce5c8f1c4f8f23 to your computer and use it in GitHub Desktop.
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