Created
August 14, 2016 01:45
-
-
Save DCubix/15db857c5ddd69b84fba2785c459e323 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function SimpleAnimation() { | |
pix.Component.apply(this); | |
this.t = 0; | |
}; | |
SimpleAnimation.prototype = new pix.Component(); | |
SimpleAnimation.prototype.update = function(dt) { | |
this.t += dt; | |
if (this.t >= Math.PI * 2) { | |
this.t = 0; | |
} | |
this.owner.rotation += dt; | |
var s = Math.abs(Math.sin(this.t * 4)) + 4.0; | |
this.owner.scale = [s, s]; | |
}; | |
/// Create a new Stage | |
var stage = new pix.Stage(); | |
// Create a simple entity | |
var ent = stage.createEntity(-1); | |
ent.origin = [0.5, 0.5]; | |
ent.scale = [4.0, 4.0]; | |
ent.rotation = 0.0; | |
// Create the game and register a state | |
var game = new pix.Game(); | |
game.registerState("main", stage); | |
// Queue some assets for loading | |
pix.engine.assets.queueAsset("pix.png", "image"); | |
// Setup our entity(es) | |
pix.engine.onload = function(assets) { | |
ent.addComponent(new pix.Sprite(assets.get("pix.png"))); | |
ent.addComponent(new SimpleAnimation()); | |
}; | |
// Start the game | |
pix.engine.start(game); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment