Created
March 1, 2014 22:32
-
-
Save dpogorzelski/9298527 to your computer and use it in GitHub Desktop.
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
function spawn(m) { | |
var label = m.Id.match(/(^\w*)-/i)[1]; | |
var p = game.add.sprite(m.X, m.Y, 'char'); | |
p.animations.add('down', [0, 1, 2], 10); | |
p.animations.add('left', [12, 13, 14], 10); | |
p.animations.add('right', [24, 25, 26], 10); | |
p.animations.add('up', [36, 37, 38], 10); | |
p.label = game.add.text(m.X, m.Y - 10, label, style); | |
return p; | |
} | |
function uPosition(m) { | |
if (players[m.Id].x > m.X) { | |
players[m.Id].animations.play('left'); | |
} else if (players[m.Id].x < m.X) { | |
players[m.Id].animations.play('right'); | |
} else if (players[m.Id].y > m.Y) { | |
players[m.Id].animations.play('up'); | |
} else { | |
players[m.Id].animations.play('down'); | |
} | |
players[m.Id].x = players[m.Id].label.x = m.X; | |
players[m.Id].y = m.Y; | |
players[m.Id].label.y = m.Y - 10; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment