Created
September 16, 2013 03:10
-
-
Save girasquid/6576353 to your computer and use it in GitHub Desktop.
This is a simple MelonJS ObjectEntity that uses an RPG Maker spritesheet file to draw itself standing and walking in four different directions.
This file contains 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
game.CharacterFromRPGMakerSpritesheet = me.ObjectEntity.extend({ | |
init: function(x, y, settings) { | |
this.parent(x, y, settings); | |
this.renderable.addAnimation("stand-down", [0]); | |
this.renderable.addAnimation("down", [0, 1, 2, 3], 3); | |
this.renderable.addAnimation("stand-up", [12]); | |
this.renderable.addAnimation("up", [12, 13, 14, 15], 3); | |
this.renderable.addAnimation("stand-left", [4]); | |
this.renderable.addAnimation("left", [4, 5, 6, 7], 3); | |
this.renderable.addAnimation("stand-right", [8]); | |
this.renderable.addAnimation("right", [8, 9, 10, 11], 3); | |
this.setFriction(0.8, 0.8); | |
this.setVelocity(3, 3); | |
this.gravity = 0; | |
me.game.viewport.follow(this.pos, me.game.viewport.AXIS.BOTH); | |
this.direction = "down"; | |
}, | |
update: function () { | |
if(me.input.isKeyPressed("left")) { | |
this.animationspeed = 3; | |
this.vel.x = -this.accel.x * me.timer.tick; | |
this.renderable.setCurrentAnimation("left"); | |
this.direction = "left"; | |
} else if(me.input.isKeyPressed("right")) { | |
this.animationspeed = 3; | |
this.vel.x = this.accel.x * me.timer.tick; | |
this.renderable.setCurrentAnimation("right"); | |
this.direction = "right"; | |
} else if(me.input.isKeyPressed("up")) { | |
this.animationspeed = 3; | |
this.vel.y = -this.accel.y * me.timer.tick; | |
this.renderable.setCurrentAnimation("up"); | |
this.direction = "up"; | |
} else if(me.input.isKeyPressed("down")) { | |
this.animationspeed = 3; | |
this.vel.y = this.accel.y * me.timer.tick; | |
this.renderable.setCurrentAnimation("down"); | |
this.direction = "down"; | |
} | |
if(this.vel.y == 0 && this.vel.x == 0) { | |
this.renderable.setCurrentAnimation("stand-" + this.direction); | |
} | |
var updated = this.updateMovement(); | |
if(updated) { | |
this.parent(this); | |
} | |
return updated; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment