Skip to content

WE ARE SPARTANS! The sample code

Adawat Chanchua edited this page Sep 30, 2015 · 4 revisions

Let's create spartan!

First, create entity

// Create spartan image atlas
WonderPtr<ImageAtlas> spartan = CreateElement<ImageAtlasEntity>();
spartan->LoadImage("Resource/Character/Spartans.png"));
spartan->LoadJsonDataFormat("Resource/Character/Spartans.json"); 
spartan->position = point2f(300.0f, 300.0f);
spartan->pivot = point2f(0.0f, 0.0f);

As you have seen, Spartan.png and Spartans.json are generated from TexturePacker.

Next, create tasks to define entity's behavior

// Bind character animation task to animate our spartan
spartan->BindTask(CreateElement<CharacterAnimation>());
// Bind character controller task to control our spartan
spartan->BindTask(CreateElement<CharacterController>());

Finally, add our little spartan sprite to the scene

AddElement(spartan);

Finished!

Clone this wiki locally