1// This file is generated by WOWCube SDK project wizard
2//
3// Application UUID: CNiZStZ0Mg
4//
5
6#include <stdint.h>
7#include <string>
8#include <vector>
9#include <string>
10#include <memory>
11
12#include "AppManager.h"
13#include "GfxAnimatedSprite.h"
14
15using namespace Cubios;
16using namespace Cubios::Math;
17using namespace Cubios::Gfx;
18
19//Applicaton initialization callback. Called once when CUB application starts
20void OnInit(Cubios::AppManager& appMgr)
21{
22 GfxAnimatedSpriteApp* theApp = new GfxAnimatedSpriteApp();
23
24 appMgr.SetApplication(theApp,"CNiZStZ0Mg");
25
26 theApp->InitializeResources();
27}
28
29
30GfxAnimatedSpriteApp::GfxAnimatedSpriteApp()
31{
32}
33
34GfxAnimatedSpriteApp::~GfxAnimatedSpriteApp()
35{
36 this->Scene.DisposeAllObjects();
37}
38
39void GfxAnimatedSpriteApp::InitializeResources()
40{
41 this->animationAtlas = new Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>("animation.png",&this->Scene);
42
43 for(int x=0; x<8; x++)
44 {
45 this->animationAtlas->AddSprite(GfxObjects::myAtlasBase+x, Cubios::Math::Rect2(92*x,0,92,163));
46 }
47
48
49 this->animationAtlas2 = new Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>("earth.png",&this->Scene);
50
51 int c = 0;
52 for(int y=0;y<4;y++)
53 {
54 for(int x=0;x<12;x++)
55 {
56 this->animationAtlas2->AddSprite(GfxObjects::myAtlas2Base+c, Cubios::Math::Rect2(52*x,52*y,52,52));
57 c++;
58 }
59 }
60
61
62 this->Scene.CreateObjectWithID(GfxObjects::myBackground,new Background(17,38,41));
63
64 this->position = 0;
65 this->prevFrame = -1;
66
67 this->Scene.CreateObjectWithID(GfxObjects::mySprite,new AnimatedSprite(this->animationAtlas,this->position,120));
68 this->sprite = dynamic_cast<AnimatedSprite*>(this->Scene[GfxObjects::mySprite]);
69 this->sprite->SetPlaybackSpeed(100);
70 this->sprite->SetPlaybackMode(AnimatedSprite::playbackMode_t::Loop);
71
72 this->Scene.CreateObjectWithID(GfxObjects::mySprite2,new AnimatedSprite(this->animationAtlas2,170,45));
73 this->sprite2 = dynamic_cast<AnimatedSprite*>(this->Scene[GfxObjects::mySprite2]);
74 this->sprite2->SetPlaybackSpeed(100);
75 this->sprite2->SetPlaybackMode(AnimatedSprite::playbackMode_t::Loop);
76
77 this->Scene.CreateObjectWithID(GfxObjects::mySprite3, new Cubios::Gfx::Sprite("grass.png",120,195));
78}
79
80//This callback is called every "tick" of cubeapp application loop
81void GfxAnimatedSpriteApp::on_Tick(uint32_t currentTime, uint32_t deltaTime)
82{
83 this->sprite2->Tick(deltaTime);
84
85 int16_t frame = this->sprite->Tick(deltaTime);
86
87 if(this->prevFrame!=frame)
88 {
89 this->sprite->Transform.Position.X+=5;
90 if(this->sprite->Transform.Position.X>260) this->sprite->Transform.Position.X = 0;
91 }
92}
93
94//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
95void GfxAnimatedSpriteApp::on_Render(std::array<Cubios::Screen, 3>& screens)
96{
97 for(auto it = screens.begin(); it != screens.end(); ++it)
98 {
99 //Start adding objects to a screen
100 it->Begin(TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true);
101
102 it->Add(this->Scene[GfxObjects::myBackground]);
103
104 it->Add(this->sprite2);
105 it->Add(this->sprite);
106 it->Add(this->Scene[GfxObjects::mySprite3]);
107
108 //Finish adding objects
109 it->End();
110 }
111}
112
113//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
114void GfxAnimatedSpriteApp::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
115{
116}
117
118//This callback is called on programmable timer (if any)
119void GfxAnimatedSpriteApp::on_Timer(uint8_t timerID)
120{
121}
122
123//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
124void GfxAnimatedSpriteApp::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
125{
126}
127
128//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
129void GfxAnimatedSpriteApp::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
130{
131}
132
133//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
134void GfxAnimatedSpriteApp::on_ExternalMessage(uint8_t* pkt, u32_t size)
135{
136}
137
138//Screen pat callback
139void GfxAnimatedSpriteApp::on_Pat(uint32_t count)
140{
141}
142
143//This callback is called before the application quits
144void GfxAnimatedSpriteApp::on_Close()
145{
146}