TazGraph Project v0.1.0
Loading...
Searching...
No Matches
MainMenuBackground.h
1#pragma once
2
3#include "../../../Components.h"
4#include "../../../UtilComponents.h"
5
6class MainMenuBackground : public Component
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 =
34 std::dynamic_pointer_cast<PerspectiveCamera>(
35 CameraManager::getInstance().getCamera("mainMenu_main")
36 );
37
38 if (!entity->hasComponent<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};
Definition GECS.h:131
T & addComponent(TArgs &&... mArgs)
have addScript function
Definition GECS.h:345
Definition MainMenuBackground.h:7
Definition SpriteComponent.h:15
Definition Window.h:12
Definition TransformComponent.h:7