Super awesome twitchy animation for axe guy.
This commit is contained in:
parent
80a0f2ba75
commit
83df9ff03b
10 changed files with 42 additions and 68 deletions
|
@ -12,7 +12,7 @@ namespace components {
|
|||
ENROLL_COMPONENT(LightSource, strength, radius);
|
||||
ENROLL_COMPONENT(Device, config, events);
|
||||
ENROLL_COMPONENT(Sprite, name);
|
||||
ENROLL_COMPONENT(Animation, scale, simple, frames);
|
||||
ENROLL_COMPONENT(Animation, scale, simple, frames, speed);
|
||||
|
||||
void configure_entity(const ComponentMap& component_map, DinkyECS::World& world, DinkyECS::Entity ent, json& data) {
|
||||
for (auto &i : data) {
|
||||
|
@ -36,4 +36,29 @@ namespace components {
|
|||
components::enroll<Sprite>(component_map);
|
||||
components::enroll<Animation>(component_map);
|
||||
}
|
||||
|
||||
void Animation::play() {
|
||||
if(!playing) {
|
||||
current = 0;
|
||||
playing = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Animation::step(sf::Vector2f& scale_out, sf::IntRect& rect_out) {
|
||||
if(playing && current < frames) {
|
||||
if(simple) {
|
||||
scale_out.x += scale;
|
||||
scale_out.y += scale;
|
||||
} else {
|
||||
rect_out.position.x += current * TEXTURE_WIDTH;
|
||||
}
|
||||
|
||||
subframe += speed;
|
||||
current = int(subframe);
|
||||
} else {
|
||||
playing = false;
|
||||
current = 0;
|
||||
subframe = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue