The Table Engine
crosshair_script.cpp
Go to the documentation of this file.
1 #include "crosshair_script.h"
2 #include "input.h"
3 #include "transform.h"
4 #include "scenemanager.h"
5 
7  auto input = m_owner->getComponent<Input>();
8  auto transform = m_owner->getComponent<Transform>();
9  auto cameraPosition = SceneManager::getInstance().getCameraWorldPosition();
10 
11  if (input && transform) {
12  int worldMouseX = input->m_mouseX + cameraPosition.x - 320 - 8;
13  int worldMouseY = input->m_mouseY + cameraPosition.y - 240 - 8;
14  transform->setWorldPosition(worldMouseX, worldMouseY);
15  }
16 }
void update() override
Updates the position of the crosshair based on the mouse cursor.
T * getComponent()
Gets a component of the specified type.
Definition: gameobject.h:123
Component for handling and storing the state of input devices.
Definition: input.h:20
static SceneManager & getInstance()
Retrieves the singleton instance of SceneManager.
Vec2 getCameraWorldPosition()
Retrieves the world position of the camera.
virtual void input()
Virtual method for handling input. Should be overridden by derived classes.
Definition: script.cpp:21
GameObject * m_owner
Pointer to the GameObject that owns this script.
Definition: script.h:25
Component for handling the transformation of game objects.
Definition: transform.h:23
Defines the Input component for handling input operations in the game engine.
Defines the SceneManager class for managing scenes in the game.
Provides the Transform component for positioning and sizing game objects.