Tileset animations.
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/components/display/AnimationController.hpp"
|
||||
#include "scene/components/display/Camera.hpp"
|
||||
#include "scene/components/display/MeshHost.hpp"
|
||||
#include "scene/components/display/MeshRenderer.hpp"
|
||||
|
30
src/dawn/scene/components/display/AnimationController.cpp
Normal file
30
src/dawn/scene/components/display/AnimationController.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "AnimationController.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
AnimationController::AnimationController(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void AnimationController::onSceneUpdate() {
|
||||
if(this->animation == nullptr) return;
|
||||
this->animation->tick(this->getGame()->timeManager.delta);
|
||||
}
|
||||
|
||||
void AnimationController::onStart() {
|
||||
SceneItemComponent::onStart();
|
||||
getScene()->eventSceneUnpausedUpdate.addListener(this, &AnimationController::onSceneUpdate);
|
||||
}
|
||||
|
||||
AnimationController::~AnimationController() {
|
||||
getScene()->eventSceneUnpausedUpdate.removeListener(this, &AnimationController::onSceneUpdate);
|
||||
}
|
24
src/dawn/scene/components/display/AnimationController.hpp
Normal file
24
src/dawn/scene/components/display/AnimationController.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "display/animation/Animation.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class AnimationController : public SceneItemComponent {
|
||||
private:
|
||||
void onSceneUpdate();
|
||||
|
||||
public:
|
||||
Animation *animation = nullptr;
|
||||
|
||||
AnimationController(SceneItem *item);
|
||||
|
||||
void onStart() override;
|
||||
|
||||
~AnimationController();
|
||||
};
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
# Sources
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
AnimationController.cpp
|
||||
Camera.cpp
|
||||
Material.cpp
|
||||
MeshHost.cpp
|
||||
|
@ -41,7 +41,7 @@ namespace Dawn {
|
||||
|
||||
// Shared
|
||||
float_t clipNear = 0.001f;
|
||||
float_t clipFar = 100.0f;
|
||||
float_t clipFar = 1000.0f;
|
||||
|
||||
/**
|
||||
* Create a new Camera Component.
|
||||
|
@ -13,6 +13,7 @@ TiledSprite::TiledSprite(SceneItem *item) : SceneItemComponent(item) {
|
||||
}
|
||||
|
||||
glm::vec2 TiledSprite::getUV0() {
|
||||
assertNotNull(this->tileset);
|
||||
auto tile = this->tileset->getTile(tileIndex);
|
||||
return glm::vec2(
|
||||
(this->flipState & TILED_SPRITE_FLIP_X) == 0 ? tile.uv0.x : tile.uv1.x,
|
||||
@ -21,6 +22,7 @@ glm::vec2 TiledSprite::getUV0() {
|
||||
}
|
||||
|
||||
glm::vec2 TiledSprite::getUV1() {
|
||||
assertNotNull(this->tileset);
|
||||
auto tile = this->tileset->getTile(tileIndex);
|
||||
return glm::vec2(
|
||||
(this->flipState & TILED_SPRITE_FLIP_X) == 0 ? tile.uv1.x : tile.uv0.x,
|
||||
@ -34,8 +36,18 @@ void TiledSprite::setTileset(Tileset *tileset) {
|
||||
this->setTile(0);
|
||||
}
|
||||
|
||||
void TiledSprite::setTilesetAndSize(TilesetGrid *tileset, glm::vec2 center) {
|
||||
this->setTileset(tileset);
|
||||
this->setSize(glm::vec2(tileset->divX, tileset->divY), center);
|
||||
}
|
||||
|
||||
void TiledSprite::setTilesetAndSize(TilesetGrid *tileset) {
|
||||
this->setTileset(tileset);
|
||||
this->setSize(glm::vec2(tileset->divX, tileset->divY));
|
||||
}
|
||||
|
||||
void TiledSprite::setTile(int32_t tileIndex) {
|
||||
assertNotNull(this->tileset);
|
||||
if(tileIndex == this->tileIndex) return;
|
||||
this->tileIndex = tileIndex;
|
||||
if(this->host != nullptr) {
|
||||
QuadMesh::bufferCoordinates(
|
||||
|
@ -20,7 +20,7 @@ namespace Dawn {
|
||||
MeshHost *host = nullptr;
|
||||
Tileset *tileset = nullptr;
|
||||
flag_t flipState = TILED_SPRITE_FLIP_Y;
|
||||
int32_t tileIndex;
|
||||
int32_t tileIndex = -1;
|
||||
glm::vec2 xy0 = glm::vec2(0, 0);
|
||||
glm::vec2 xy1 = glm::vec2(1, 1);
|
||||
|
||||
@ -31,6 +31,8 @@ namespace Dawn {
|
||||
TiledSprite(SceneItem *item);
|
||||
|
||||
void setTileset(Tileset *tileset);
|
||||
void setTilesetAndSize(TilesetGrid *gridTileset, glm::vec2 center);
|
||||
void setTilesetAndSize(TilesetGrid *gridTileset);
|
||||
void setTile(int32_t tile);
|
||||
void setFlippedState(flag_t flippedState);
|
||||
void setSize(glm::vec2 size, glm::vec2 center);
|
||||
|
Reference in New Issue
Block a user