Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Experiments with the new oCanvas library
/* Author: Joe Critchley
oCanvas Experiments
*/
var canvas = oCanvas.create({
canvas: '#canvas',
background: '#222',
fps: 60
});
var circles = [], disabled = false;
var hover_circle = canvas.display.ellipse({
x: 100,
y: 100,
radius_x: 100,
radius_y: 100,
stroke: '1px #666'
});
canvas.addChild(hover_circle);
canvas.bind('mousemove', function() {
hover_circle.x = canvas.mouse.x;
hover_circle.y = canvas.mouse.y;
});
hover_circle.bind('click', function() {
if(disabled) {
return;
}
disabled = true;
var new_circle = this.clone({
fill: '#999'
});
canvas.addChild(new_circle);
circles.push(new_circle);
new_circle.animate({
radius_x: 50,
radius_y: 50
}, '600', 'ease-in-out', function() {
disabled = false;
});
});
canvas.setLoop(function() {
// ?? why did I need a set-loop to get the mousemove event working?
});
canvas.timeline.start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.