Last active
August 29, 2015 13:56
-
-
Save jeremyckahn/9222627 to your computer and use it in GitHub Desktop.
A potential way to use KineticJS with Rekapi.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rekapi = new Rekapi(); | |
var textPathActor = rekapi.addActor({ | |
// This actor setup function performs some initial preparation work. This is | |
// where KineticJS is set up and given an initial state. | |
setup: function () { | |
var stage = new Kinetic.Stage({ | |
container: 'container', | |
width: 578, | |
height: 220 | |
}); | |
// Attach textpath and layer to `this` so that the render function can | |
// access it. | |
this.layer = new Kinetic.Layer(); | |
this.textpath = new Kinetic.TextPath({ | |
x: 100, | |
y: 50, | |
fill: '#333', | |
fontSize: '24', | |
fontFamily: 'Arial', | |
text: 'All the world\'s a stage, and all the men and women merely players.', | |
data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50' | |
}); | |
this.layer.add(this.textpath); | |
stage.add(this.layer); | |
}, | |
render: function (context, state) { | |
// Not sure if the KineticJS API allows for this, but you'll need to | |
// somehow re-render the text path. | |
// | |
// Even if this does work, it's probably very inefficient. Hopefully | |
// KineticJS allows for more performant TextPath updating. | |
this.layer.remove(this.textPath)); | |
this.textpath = new Kinetic.TextPath({ | |
x: 100, | |
y: 50, | |
fill: '#333', | |
fontSize: '24', | |
fontFamily: 'Arial', | |
text: 'All the world\'s a stage, and all the men and women merely players.', | |
// Notice that state.SVGString is being passed as `data` to TextPath. | |
data: state.SVGString | |
}); | |
this.layer.add(this.textpath); | |
} | |
}); | |
textPathActor | |
.keyframe(0, { | |
SVGString: 'M10,10 C0,0 10,150 100,100 S300,150 400,50' | |
}) | |
.keyframe(1000, { | |
// I'm not sure what these SVG values do, but what this demonstrates is | |
// that the numbers changed from the last keyframe. | |
SVGString: 'M99,50 C5,0 99,150 300,500 S999,150 888,50' | |
}); | |
rekapi.play(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment