WOWCube Docs logo
WOWCube Docs
Mission Control
Section Shortcuts
APIExamplesSourceWOWConnectChangelog
Filters
SDK and language defaults persist in cookies.
SDK version
Navigation Tree
Collapsed by default, focused on the active path.
Made byMcKay Seamons
GitHub
  1. Home
  2. Docs
  3. Examples
  4. GfxSpriteAtlas.cpp
Mission NodeSDK 6.2C++renderingProject Included

GfxSpriteAtlas.cpp

Example: GfxSpriteAtlas.cpp

Examples / SDK 6.2 / C++ / rendering / Gfx Engine - Sprite Atlas / project / src
GfxSpriteAtlas.cpp
CPP
1// This file is generated by WOWCube SDK project wizard
2//
3// Application UUID: 6EqWQJuAqt
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 "GfxSpriteAtlas.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 GfxSpriteAtlas* theApp = new GfxSpriteAtlas();
23
24 appMgr.SetApplication(theApp,"6EqWQJuAqt");
25
26 theApp->InitializeResources();
27}
28
29
30GfxSpriteAtlas::GfxSpriteAtlas()
31{
32}
33
34GfxSpriteAtlas::~GfxSpriteAtlas()
35{
36 this->Scene.DisposeAllObjects();
37}
38
39void GfxSpriteAtlas::InitializeResources()
40{
41 //Create sprite atlas with terrain sprites
42 this->terrainAtlas = new Cubios::Gfx::SpriteAtlas<Cubios::Gfx::SpriteAtlasElement>("terrain_atlas.png",&this->Scene);
43
44 //Define atlas sprites
45 this->terrainAtlas->AddSprite(GfxObjects::terrain, Cubios::Math::Rect2(0,0,163,100));
46 this->terrainAtlas->AddSprite(GfxObjects::pit, Cubios::Math::Rect2(163,0,163,100));
47 this->terrainAtlas->AddSprite(GfxObjects::rock3, Cubios::Math::Rect2(163*2,0,163,100));
48
49 this->terrainAtlas->AddSprite(GfxObjects::rock2, Cubios::Math::Rect2(0,100,163,100));
50 this->terrainAtlas->AddSprite(GfxObjects::rock, Cubios::Math::Rect2(163,100,163,100));
51 this->terrainAtlas->AddSprite(GfxObjects::plant4, Cubios::Math::Rect2(163*2,100,163,100));
52
53 this->terrainAtlas->AddSprite(GfxObjects::plant3, Cubios::Math::Rect2(0,200,163,100));
54 this->terrainAtlas->AddSprite(GfxObjects::plant2, Cubios::Math::Rect2(163,200,163,100));
55 this->terrainAtlas->AddSprite(GfxObjects::plant, Cubios::Math::Rect2(163*2,200,163,100));
56
57 //Create background
58 this->Scene.CreateObjectWithID(GfxObjects::myBackground,new Background(Cubios::Gfx::Colors::black));
59
60 //Create offscreen render target
61 this->prepareOffscreenResource();
62
63 //Create an atlas for animated object
64 this->fireballAtlas = new Cubios::Gfx::SpriteAtlas<FireballSpriteAtlasElement>("fireball_atlas.png",&this->Scene);
65
66 //Add dynamic sprite objects
67 this->fireballAtlas->AddSprite(GfxObjects::fireball,Cubios::Math::Rect2(0,0,51,38));
68 this->fireballAtlas->AddSprite(GfxObjects::fireball+1,Cubios::Math::Rect2(0,0,51,38));
69 this->fireballAtlas->AddSprite(GfxObjects::fireball+2,Cubios::Math::Rect2(0,0,51,38));
70
71 this->fireballAtlas->AddSprite(GfxObjects::fireball+3,Cubios::Math::Rect2(0,38,51,20));
72 this->fireballAtlas->AddSprite(GfxObjects::fireball+4,Cubios::Math::Rect2(0,38,51,20));
73 this->fireballAtlas->AddSprite(GfxObjects::fireball+5,Cubios::Math::Rect2(0,38,51,20));
74
75 //Set initial positions
76 this->fireballAtlas->Get(GfxObjects::fireball)->SetPosition(-20,100);
77 this->fireballAtlas->Get(GfxObjects::fireball+1)->SetPosition(-20,80);
78 this->fireballAtlas->Get(GfxObjects::fireball+2)->SetPosition(-20,170);
79
80 this->fireballAtlas->Get(GfxObjects::fireball+3)->SetPosition(-20,70);
81 this->fireballAtlas->Get(GfxObjects::fireball+4)->SetPosition(-20,50);
82 this->fireballAtlas->Get(GfxObjects::fireball+5)->SetPosition(-20,190);
83
84 //Uncomment this line in order to see actuall FPSes
85 //this->ShowFPSCounter(true);
86}
87
88void GfxSpriteAtlas::prepareOffscreenResource()
89{
90 OffscreenRenderTarget* rt = new OffscreenRenderTarget(240,240,Cubios::GFX_PixelFormat_t::FORMAT_RGB565);
91 rt->SetPosition(120,120);
92
93 rt->Begin(true);
94
95 rt->Add(this->Scene[GfxObjects::myBackground]);
96
97 rt->Add(terrainAtlas->Get(GfxObjects::terrain))->SetPosition(120,120);
98 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120-79,120-47);
99 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120+79,120-47);
100 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120+79,120+47);
101 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120-79,120+47);
102
103 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120,120-47*2);
104 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120,120+47*2);
105
106 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120-79*2,120-47*2);
107 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120-79*2,120+47*2);
108
109 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120+79*2,120-47*2);
110 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120+79*2,120+47*2);
111
112 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120+79*2,120);
113 rt->AddCopy(terrainAtlas->Get(GfxObjects::terrain)->Copy())->SetPosition(120-79*2,120);
114
115
116 rt->Add(terrainAtlas->Get(GfxObjects::pit))->SetPosition(120,120);
117
118 rt->Add(terrainAtlas->Get(GfxObjects::rock3))->SetPosition(120-79,120-47);
119 rt->Add(terrainAtlas->Get(GfxObjects::rock))->SetPosition(120-79,120-47);
120 rt->Add(terrainAtlas->Get(GfxObjects::rock2))->SetPosition(120,120-47*2);
121
122 rt->AddCopy(terrainAtlas->Get(GfxObjects::rock3)->Copy())->SetPosition(120+79,120-47);
123 rt->AddCopy(terrainAtlas->Get(GfxObjects::plant3)->Copy())->SetPosition(120+79,120-47);
124
125 rt->AddCopy(terrainAtlas->Get(GfxObjects::rock3)->Copy())->SetPosition(120-79,120+47);
126 rt->AddCopy(terrainAtlas->Get(GfxObjects::rock3)->Copy())->SetPosition(120,120+47*2);
127 rt->AddCopy(terrainAtlas->Get(GfxObjects::plant3)->Copy())->SetPosition(120,120+47*2);
128
129 rt->Add(terrainAtlas->Get(GfxObjects::plant))->SetPosition(120+79,120+47);
130 rt->Add(terrainAtlas->Get(GfxObjects::plant4))->SetPosition(120-79,120+77);
131
132 rt->Add(terrainAtlas->Get(GfxObjects::plant2))->SetPosition(120-39,120+7);
133
134 rt->End();
135
136 this->Scene.CreateObjectWithID(GfxObjects::myRT,rt);
137}
138
139//This callback is called every "tick" of cubeapp application loop
140void GfxSpriteAtlas::on_Tick(uint32_t currentTime, uint32_t deltaTime)
141{
142
143 dynamic_cast<FireballSpriteAtlasElement*>(this->fireballAtlas->Get(GfxObjects::fireball))->Tick(15);
144 dynamic_cast<FireballSpriteAtlasElement*>(this->fireballAtlas->Get(GfxObjects::fireball+1))->Tick(10);
145 dynamic_cast<FireballSpriteAtlasElement*>(this->fireballAtlas->Get(GfxObjects::fireball+2))->Tick(12);
146
147 dynamic_cast<FireballSpriteAtlasElement*>(this->fireballAtlas->Get(GfxObjects::fireball+3))->Tick(35);
148 dynamic_cast<FireballSpriteAtlasElement*>(this->fireballAtlas->Get(GfxObjects::fireball+4))->Tick(25);
149 dynamic_cast<FireballSpriteAtlasElement*>(this->fireballAtlas->Get(GfxObjects::fireball+5))->Tick(30);
150
151}
152
153//This callback is called every time device is about to render visuals. Use it for calling your rendering code.
154void GfxSpriteAtlas::on_Render(std::array<Cubios::Screen, 3>& screens)
155{
156 for(auto it = screens.begin(); it != screens.end(); ++it)
157 {
158 //Start adding objects to a screen
159 it->Begin(TOPOLOGY_orientation_mode_t::ORIENTATION_MODE_GRAVITY,true);
160
161 it->Add(this->Scene[GfxObjects::myRT]);
162
163 it->Add(this->fireballAtlas->Get(GfxObjects::fireball));
164 it->Add(this->fireballAtlas->Get(GfxObjects::fireball+1));
165 it->Add(this->fireballAtlas->Get(GfxObjects::fireball+2));
166
167 it->Add(this->fireballAtlas->Get(GfxObjects::fireball+3));
168 it->Add(this->fireballAtlas->Get(GfxObjects::fireball+4));
169 it->Add(this->fireballAtlas->Get(GfxObjects::fireball+5));
170
171 //Finish adding objects
172 it->End();
173 }
174}
175
176//The "physics" callback. Gets called recurrently with at least 33ms resolution or less depending on the load.
177void GfxSpriteAtlas::on_PhysicsTick(const std::array<Cubios::Screen, 3>& screens)
178{
179}
180
181//This callback is called on programmable timer (if any)
182void GfxSpriteAtlas::on_Timer(uint8_t timerID)
183{
184}
185
186//The cube topology change callback. Gets called when cube is twisted and its topological desctiption has been changed
187void GfxSpriteAtlas::on_Twist(const Cubios::TOPOLOGY_twistInfo_t& twist)
188{
189}
190
191//The "inner network" callback. Gets called when WOWCube module receives a data packet from other module
192void GfxSpriteAtlas::on_Message(uint32_t type, uint8_t* pkt, u32_t size)
193{
194}
195
196//The external data transfer callback. Gets called when WOWCube module receives a data over BLE from an external source
197void GfxSpriteAtlas::on_ExternalMessage(uint8_t* pkt, u32_t size)
198{
199}
200
201//Screen pat callback
202void GfxSpriteAtlas::on_Pat(uint32_t count)
203{
204}
205
206//This callback is called before the application quits
207void GfxSpriteAtlas::on_Close()
208{
209}
Wrapped for easier reading. Turn wrap off to inspect exact line lengths.
Context Rail

Project files

GfxSpriteAtlas.cpp
project/src/GfxSpriteAtlas.cpp
GfxSpriteAtlas.h
project/src/GfxSpriteAtlas.h
wowcubeapp-build.json
project/wowcubeapp-build.json
Context Rail

Related nodes

GfxSpriteAtlas.h
Examples / SDK 6.2 / C++ / rendering / Gfx Engine - Sprite Atlas / project / src
Gfx Engine - Sprite Atlas
Examples / SDK 6.2 / C++ / rendering
info.json
Examples / SDK 6.2 / C++ / rendering / Gfx Engine - Sprite Atlas
wowcubeapp-build.json
Examples / SDK 6.2 / C++ / rendering / Gfx Engine - Sprite Atlas / project
Previous Node
info.json
Examples / SDK 6.2 / C++ / rendering / Gfx Engine - Sprite Atlas
Next Node
GfxSpriteAtlas.h
Examples / SDK 6.2 / C++ / rendering / Gfx Engine - Sprite Atlas / project / src