Little documentation update

This commit is contained in:
2022-12-14 06:27:10 -08:00
parent 850f4c227d
commit 6404f35b1c
17 changed files with 332 additions and 105 deletions

View File

@ -0,0 +1,17 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Animation.hpp"
using namespace Dawn;
void Animation::restart() {
this->time = 0;
this->finished = false;
}
void Animation::clear() {
this->duration = 0;
}

View File

@ -17,21 +17,24 @@ namespace Dawn {
float_t duration = 0;
Event<> eventAnimationEnd;
/**
* Ticks the animation along. Delta is whatever you want to update the
* animation by (in seconds). Animations can overshoot if necessary and
* will not be clamped (by default). Subclasses may interpret ticks in
* different ways.
*
* @param delta Time delta (in seconds) to tick the animaiton by.
*/
virtual void tick(float_t delta) = 0;
/**
* Restart a running animation.
*/
virtual void restart() {
this->time = 0;
this->finished = false;
}
virtual void restart();
/**
* Clears an animaton of all its animation items and keyframes.
*/
virtual void clear() {
this->duration = 0;
}
virtual void clear();
};
}

View File

@ -4,7 +4,8 @@
# https://opensource.org/licenses/MIT
# Sources
# target_sources(${DAWN_TARGET_NAME}
# PRIVATE
# Animation.cpp
# )
target_sources(${DAWN_TARGET_NAME}
PRIVATE
Animation.cpp
TiledSpriteAnimation.cpp
)

View File

@ -24,6 +24,12 @@ namespace Dawn {
this->modifies = modifies;
}
/**
* Adds a keyframe that will be slerped to at a given time.
*
* @param time Time the keyframe occurs.
* @param value Value at this given time.
*/
void addKeyframe(float_t time, T value) {
struct SimpleKeyframe<T> keyframe;
keyframe.time = time;
@ -33,6 +39,22 @@ namespace Dawn {
this->keyframes.push_back(keyframe);
}
/**
* Quickly add a series of keyframes. For example, if you want to have a
* keyframe series of;
* [ 1, 3, 5, 7, 9 ]
*
* And occur at times
* [ 0, 2, 4, 6, 8 ]
*
* You would pass frameTime as 2, and step as 2.
*
* @param startTime When the first keyframe occurs.
* @param frameTime At what rate do keyframes occur.
* @param start Initial value (the value at startTime).
* @param end The end value (for the last keyframe).
* @param step How to step the value.
*/
void addSequentialKeyframes(
float_t startTime,
float_t frameTime,
@ -49,6 +71,14 @@ namespace Dawn {
}
}
/**
* Shorthand addSequentialKeyframes, assumes a step of 1 and a startTime
* of 0.
*
* @param frameTime Time between frames.
* @param start Initial value.
* @param end End value.
*/
void addSequentialKeyframes(float_t frameTime, T start, T end) {
this->addSequentialKeyframes(0, frameTime, start, end, 1);
}
@ -115,7 +145,7 @@ namespace Dawn {
this->finished = true;
this->eventAnimationEnd.invoke();
}
void clear() override {
Animation::clear();
this->keyframes.clear();

View File

@ -0,0 +1,19 @@
// Copyright (c) 2022 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "TiledSpriteAnimation.hpp"
using namespace Dawn;
TiledSpriteAnimation::TiledSpriteAnimation(TiledSprite *sprite) :
SimpleAnimation(&frame),
sprite(sprite)
{
}
void TiledSpriteAnimation::tick(float_t delta) {
SimpleAnimation::tick(delta);
this->sprite->setTile(frame);
}

View File

@ -13,15 +13,13 @@ namespace Dawn {
int32_t frame = 0;
TiledSprite *sprite = nullptr;
TiledSpriteAnimation(TiledSprite *sprite) :
SimpleAnimation(&frame),
sprite(sprite)
{
}
/**
* Construct a new Tiled Sprite Animation.
*
* @param sprite Sprite that this animation will control.
*/
TiledSpriteAnimation(TiledSprite *sprite);
void tick(float_t delta) override {
SimpleAnimation::tick(delta);
this->sprite->setTile(frame);
}
void tick(float_t delta) override;
};
}