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