Skip to content

Instantly share code, notes, and snippets.

@AGoblinKing
Created March 27, 2011 08:35
Show Gist options
  • Save AGoblinKing/889043 to your computer and use it in GitHub Desktop.
Save AGoblinKing/889043 to your computer and use it in GitHub Desktop.
Jxl.init(function() {
Jxl.loader.load({
'animals': ['image', 'examples/assets/animals.png']
}, function() {
Jxl.state = new GameState();
});
Jxl.start();
});
var GameState = new Class({
Extends: Jxl.State,
create: function() {
var animal = this.add(new Cat(20, 20));
Jxl.follow(animal);
}
});
var Cat = new Class({
Extends: Jxl.Sprite,
initialize: function(x, y) {
this.parent({
graphic: Jxl.loader.get('animals'),
x: x,
y: y,
animated: true,
width: 32,
height: 32
});
this.addAnimation('run', [72,73,74,73], .30);
this.addAnimation('idle', [48,49,50,49], .50);
this.play('idle');
this.speed = -80;
this.drag = new Jxl.Point(150,150);
},
update: function(delta) {
if (Jxl.keys.A == true) {
this.velocity.x = this.speed;
this._flipped = true;
this.play('run');
} else if (Jxl.keys.D == true) {
this._flipped = false;
this.play('run');
this.velocity.x = -1*this.speed;
} else {
this.play('idle');
}
this.parent(delta);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment