Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 8749f46fb9
Fetching contributors…

Cannot retrieve contributors at this time

129 lines (116 sloc) 3.553 kB
<!DOCTYPE html>
<script src="CanvasEngine/canvasengine-1.0.7.all.min.js"></script>
<canvas id="canvas_id" width="800" height="600"></canvas>
<script>
var mainScene;
var canvas = CE.defines("canvas_id").
extend(Animation).
extend(Input).
ready(function() {
canvas.Scene.call("MainScene");
mainScene = canvas.Scene.get('MainScene');
});
canvas.Scene.new({
name: "MainScene",
materials: {
images: {
player: "sprites/cat_sprite.png"
}
},
ready: function(stage) {
this.element = this.createElement(),
animation = canvas.Animation.new({
images: "player",
animations: {
idle: {
frames: [0, 3],
size: {
width: 64,
height: 64
},
frequence: 5
},
kick: {
frames: [5*16, 5*16+6],
size: {
width: 64,
height: 64
},
frequence: 5
},
walk: {
frames: [16, 16+5],
size: {
width: 64,
height: 64
},
frequence: 5
}
}
});
canvas.Input.keyDown(Input.Up, function() {
mainScene.element.yspeed = -mainScene.element.defaultspeed;
animation.stop();
animation.play("walk");
});
canvas.Input.keyUp(Input.Up, function() {
mainScene.element.yspeed = 0;
animation.stop();
animation.play("idle", "loop");
});
canvas.Input.keyDown(Input.Bottom, function() {
mainScene.element.yspeed = mainScene.element.defaultspeed;
animation.stop();
animation.play("walk");
});
canvas.Input.keyUp(Input.Bottom, function() {
mainScene.element.yspeed = 0;
animation.stop();
animation.play("idle", "loop");
});
canvas.Input.keyDown(Input.Left, function() {
mainScene.element.xspeed = -mainScene.element.defaultspeed;
animation.stop();
animation.play("walk");
});
canvas.Input.keyUp(Input.Left, function() {
mainScene.element.xspeed = 0;
animation.stop();
animation.play("idle", "loop");
});
canvas.Input.keyDown(Input.Right, function() {
mainScene.element.xspeed = mainScene.element.defaultspeed;
animation.stop();
animation.play("walk");
});
canvas.Input.keyUp(Input.Right, function() {
mainScene.element.xspeed = 0;
animation.stop();
animation.play("idle", "loop");
});
canvas.Input.keyDown(Input.Space, function() {
animation.stop();
animation.play("kick");
});
canvas.Input.keyUp(Input.Space, function() {
animation.stop();
animation.play("idle", "loop");
});
animation.add(this.element);
animation.play("idle", "loop");
this.element.xspeed = 0;
this.element.yspeed = 0;
this.element.defaultspeed = 2;
stage.append(this.element);
},
render: function(stage) {
//if (this.element.x >= 500 || this.element.x < 0) {
//this.element.speed *= -1;
//}
this.element.defaultspeed = 2;
this.element.x += this.element.xspeed;
this.element.y += this.element.yspeed;
stage.refresh();
}
});
</script>
Jump to Line
Something went wrong with that request. Please try again.