cs381/as6/components/ScrollableComponent.cpp

23 lines
532 B
C++

#include "components/ScrollableComponent.hpp"
#include "Entity.hpp"
#include "components/TransformComponent.hpp"
void ScrollableComponent::Setup() {}
void ScrollableComponent::Update(float) {
if (!context) {
return;
}
auto transform = entity->GetComponent<TransformComponent>();
if (!transform) {
return;
}
// keeps the drawable aligned with the camera by subtracting the global scroll offset
transform->get().x = worldX - context->scrollX;
}
void ScrollableComponent::Cleanup() {}