summaryrefslogtreecommitdiff
path: root/vfg/src/Puppet.cpp
diff options
context:
space:
mode:
authorTim Redfern <tim@gray.(none)>2012-11-19 21:05:27 +0000
committerTim Redfern <tim@gray.(none)>2012-11-19 21:05:27 +0000
commit891b71c261a4571e0e0ba0e824e1bdb2478e0c65 (patch)
tree2005ff07fb391fcead17d3a0679cc3f82d0ff4cd /vfg/src/Puppet.cpp
parent1b56a18fc25f86591b410d32ceb19faea6fc74ea (diff)
flake animations
Diffstat (limited to 'vfg/src/Puppet.cpp')
-rwxr-xr-xvfg/src/Puppet.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/vfg/src/Puppet.cpp b/vfg/src/Puppet.cpp
new file mode 100755
index 0000000..46eee5e
--- /dev/null
+++ b/vfg/src/Puppet.cpp
@@ -0,0 +1,66 @@
+#include "Puppet.h"
+
+Puppet::Puppet()
+{
+
+}
+
+Puppet::~Puppet()
+{
+ //dtor
+}
+
+void Puppet::load(string filename) {
+ ofxXmlSettings XML;
+ int frames=0;
+ long t=ofGetElapsedTimeMillis();
+ if( !XML.loadFile(filename) ){
+ printf("unable to load %s check data/ folder\n",filename.c_str());
+ }else{
+ if(XML.pushTag("VFxmas")) {
+ for (int i=0;i<XML.getNumTags("Clip");i++) {
+ string name=XML.getAttribute("Clip", "name","",i);
+ if (name!="") {
+ clips[name]=ofxSprite();
+ clips[name].load(XML.getAttribute("Clip", "files","",i),XML.getAttribute("Clip", "frames",0,i));
+ clips[name].setAnchorPercent(XML.getAttribute("Clip", "xAnchorPct",0.5,i),XML.getAttribute("Clip", "yAnchorPct",0.5,i));
+ clips[name].setFrameRate(XML.getAttribute("Clip", "rate",25,i));
+ clips[name].setLoop(false);
+ frames+=clips[name].getTotalFrames();
+ }
+ }
+ printf("loaded %s: %i animation clips with %i frames in %2fs\n",filename.c_str(),clips.size(),frames,((float)(ofGetElapsedTimeMillis()-t))*.001f);
+ }
+ }
+}
+
+void Puppet::draw(float x, float y) {
+ if (playlist.size()>0) {
+ if (!clips[playlist[0]].getIsPlaying()) {
+ playlist.erase(playlist.begin());
+ if (playlist.size()>0) {
+ clips[playlist[0]].play();
+ }
+ }
+ }
+ if (playlist.size()==0) {
+ if (clips.find("base") != clips.end()) clips["base"].draw(x,y);
+ }
+ else {
+ clips[playlist[0]].update();
+ clips[playlist[0]].draw(x,y);
+ }
+}
+
+void Puppet::play(string clip){
+ if (clips.find(clip) != clips.end()) {
+ playlist.push_back(clip);
+ if (playlist.size()==1) clips[playlist[0]].play();
+ //printf("playing %s, %i, %s\n",playlist[0].c_str(),playlist.size(),clips[playlist[0]].getIsPlaying()?"true":"false");
+ }
+}
+
+bool Puppet::isPlaying(){
+ if (playlist.size()>0) return clips[playlist[0]].getIsPlaying();
+ else return false;
+} \ No newline at end of file