Commit 27099204 authored by Michael Ochmann's avatar Michael Ochmann
Browse files

added manual override for frameanimation initialized with -1

parent 9fad3629
......@@ -36,9 +36,10 @@
"type" : "animation",
"id" : "level",
"frames" : [
"ui/level/Lvlanzeige_blank_1.png"
"ui/level/Lvlanzeige_blank_1.png",
"ui/level/Lvlanzeige_blank_2.png"
],
"frametime" : 0,
"frametime" : -1,
"x" : 80,
"y" : -5,
"height" : "auto",
......@@ -53,7 +54,41 @@
"y" : 2,
"height" : 8,
"width" : 15,
"childs" : []
"childs" : [
{
"type" : "animation",
"id" : "coin",
"frames" : [
"ui/coin/Frame_01.png",
"ui/coin/Frame_03.png",
"ui/coin/Frame_05.png",
"ui/coin/Frame_07.png",
"ui/coin/Frame_09.png",
"ui/coin/Frame_11.png",
"ui/coin/Frame_13.png",
"ui/coin/Frame_15.png",
"ui/coin/Frame_17.png",
"ui/coin/Frame_19.png",
"ui/coin/Frame_21.png",
"ui/coin/Frame_23.png",
"ui/coin/Frame_25.png",
"ui/coin/Frame_27.png",
"ui/coin/Frame_29.png",
"ui/coin/Frame_31.png",
"ui/coin/Frame_33.png",
"ui/coin/Frame_35.png",
"ui/coin/Frame_37.png",
"ui/coin/Frame_39.png"
],
"frametime" : 0.1,
"x" : 0,
"y" : 0,
"height" : 100,
"width" : "auto",
"childs" : []
}
]
}
]
}
......
......@@ -10,15 +10,22 @@ namespace gdw {
class frameanimation_widget : public ui_widget {
private:
std::vector<std::unique_ptr<nanovg_texture>> textures;
float deltaSum;
float frameTime;
int activeTexture;
public:
frameanimation_widget(float x, float y, float width, float height, float frameTime, std::vector<std::unique_ptr<nanovg_texture>>& textures);
virtual void render(NVGcontext *context, float delta_time) override;
};
void next() {
this->activeTexture = this->activeTexture >= this->textures.size() - 1 ? 0 : this->activeTexture + 1;
}
void previous() {
this->activeTexture = this->activeTexture <= 0 ? (int) this->textures.size() - 1 : this->activeTexture - 1;
}
};
}
}
#endif //GDW_SS15_CPP_FRAMEANIMATION_WIDGET_HPP
......@@ -35,6 +35,7 @@
#include <ui/box_widget.hpp>
#include <ui/UIManager.hpp>
#include <ui/texture_widget.hpp>
#include <ui/frameanimation_widget.hpp>
#include <ui/text_widget.hpp>
namespace gdw {
......
#include <ui/frameanimation_widget.hpp>
#include <ui/nanovg_texture.hpp>
#include <util/logger.hpp>
namespace gdw {
frameanimation_widget::frameanimation_widget(float x, float y, float width, float height, float frameTime, std::vector<std::unique_ptr<nanovg_texture>>& textures) :
ui_widget(x, y, width, height),
textures(std::move(textures)),
activeTexture(0),
frameTime(frameTime) {
frameTime(frameTime),
deltaSum(0.0f){
}
void frameanimation_widget::render(NVGcontext *context, float delta_time) {
NVGpaint imgPaint;
int imgw, imgh;
this->deltaSum += delta_time;
if (this->frameTime != -1) {
if (this->deltaSum >= frameTime) {
this->deltaSum = 0.0f;
this->activeTexture = this->activeTexture >= this->textures.size() - 1 ? 0 : this->activeTexture + 1;
}
}
nvgImageSize(context, this->textures[this->activeTexture]->nanovg_image_handele, &imgw, &imgh);
float aspect = (float)imgw/(float)imgh;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment