Aniframes.js is a quick library I have put together to help you create animations and / or games in javascript.
Note that the updater runs before the renderer.
var myGame = new aniframes(),
canvas = document.querySelector("canvas");
myGame.set_canvas(canvas);
myGame.set_renderer(function(aniframes, canvas, context) {
//todo add rendering code here....
});
myGame.set_updater(function(aniframes) {
//todo add updaing code here....
});
myGame.start();
var myGame = new aniframes();
myGame.set_canvas(canvas);
Sets the canvas that aniframes will operate on.
myGame.set_updater(function(myGame) {
//todo canvas state updating code here...
});
Sets the function that updates the canvas state.
myGame.set_renderer(function(myGame, canvas, context) {
//todo canvas rendering code here...
});
Sets the function that renders the canvas state.
myGame.start();
Starts the rendering loop (using requestAnimationFrame()
).
myGame.stop();
Stops the rendering loop after the next frame has been rendered.
events.load = function(event) {
//todo onload code here...
});
events.keyup = function(event) {
//todo onkeyup code here...
An object that should contain your events that you want binding.
Contains various environmental variables. You can put other things in here too.
env.canvas
- The canvas aniframes is operating on.env.context
- The canvas context aniframes is operating on.env.mouse.x
- The current x position of the user's cursor. Doesn't update yet.env.mouse.y
- The current y position of the user's cursor. Doesn't update yet.env.stop
- A boolean value that if true, tells the rendering loop to stop on the next frame.
- Update
this.env.mouse.x
andthis.env.mouse.y
when the mouse moves - Test it :)
aniframes.js
was built by Starbeamrainbowlabs in Brackets