TazGraph Project
v0.1.0
Loading...
Searching...
No Matches
TazGraphEngine
src
GECS
Components
Empty
Util
MainMenuBackground.h
1
#pragma once
2
3
#include "../../../Components.h"
4
#include "../../../UtilComponents.h"
5
6
class
MainMenuBackground
:
public
Component
7
{
8
private
:
9
TransformComponent
* transform =
nullptr
;
10
SpriteComponent
* sprite =
nullptr
;
11
12
float
elapsedTime = 0.0f;
13
14
TazGraphEngine::Window
* window =
nullptr
;
15
public
:
// it is like it has init that creates Animator Component since it inherits it
16
17
18
MainMenuBackground
()
19
{
20
21
}
22
23
MainMenuBackground
(
TazGraphEngine::Window
* m_window)
24
{
25
window = m_window;
26
}
27
28
~MainMenuBackground
() {
29
30
}
31
32
void
init()
override
{
33
std::shared_ptr<PerspectiveCamera> main_camera2D =
34
std::dynamic_pointer_cast<PerspectiveCamera>(
35
CameraManager::getInstance().getCamera(
"mainMenu_main"
)
36
);
37
38
if
(!entity->hasComponent<
TransformComponent
>()) {
39
entity->
addComponent
<
TransformComponent
>(
40
glm::vec2(
41
0
42
), Layer::action,
43
glm::ivec2(
44
window->getScreenWidth(),
45
window->getScreenHeight()
46
),
47
1.0f);
48
}
49
if
(!entity->hasComponent<
SpriteComponent
>()) {
50
entity->
addComponent
<
SpriteComponent
>(
"graphnetwork"
);
51
}
52
transform = &entity->GetComponent<
TransformComponent
>();
53
sprite = &entity->GetComponent<
SpriteComponent
>();
54
55
}
56
57
void
update(
float
deltaTime)
override
{
58
59
elapsedTime += deltaTime;
// Update the accumulated elapsed time
60
float
amplitude = 100.0f;
// Maximum displacement along the Y axis
61
float
frequency = 0.002f;
// How fast the object moves up and down
62
63
// Calculate the new Y position
64
float
newY = -amplitude + amplitude * sin(frequency * elapsedTime);
65
66
transform->position.z = newY;
67
}
68
69
std::string GetComponentName()
override
{
70
return
"MainMenuBackground"
;
71
}
72
};
Component
Definition
GECS.h:131
Entity::addComponent
T & addComponent(TArgs &&... mArgs)
have addScript function
Definition
GECS.h:345
MainMenuBackground
Definition
MainMenuBackground.h:7
SpriteComponent
Definition
SpriteComponent.h:15
TazGraphEngine::Window
Definition
Window.h:12
TransformComponent
Definition
TransformComponent.h:7
Generated by
1.9.8