Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:bengourley/gin

  • Loading branch information...
commit 2bfd1e1166b68d4c7cbe18a67f652c720b3f85de 2 parents 2684af6 + 67e8634
@bengourley authored
Showing with 14 additions and 2 deletions.
  1. +14 −2 entityTraits.js
View
16 entityTraits.js
@@ -66,11 +66,11 @@ Game.registerEntityTrait('position', function (entity, element, context) {
top : 0,
'-webkit-transform' : 'translate3d(' +
(bounds.x || bounds.x === 0
- ? Math.max(bounds.x, Math.min(x, 768 - bounds.x - element.width()))
+ ? Math.max(bounds.x, Math.min(x, Game.width() - bounds.x - element.width()))
: x) +
'px, ' +
(bounds.y || bounds.y === 0
- ? Math.max(bounds.y, Math.min(y, 1004 - bounds.y - element.height()))
+ ? Math.max(bounds.y, Math.min(y, Game.height() - bounds.y - element.height()))
: y) +
'px, 0px)'
});
@@ -312,11 +312,13 @@ Game.registerEntityTrait('lifespan', function (entity, element, context) {
Game.registerEntityTrait('animated-sprite', function (entity, element, context) {
+ // Run a single frame
entity.animateSprite = function(animationData) {
// Set initial sprite position
if (animationData.currentPos === undefined) {
animationData.currentPos = 0;
+ animationData.initialFrames = animationData.frames;
}
// Update parameters
@@ -335,6 +337,16 @@ Game.registerEntityTrait('animated-sprite', function (entity, element, context)
},
1000 / animationData.fps);
}
+ else if (animationData.repeat) {
+ // Reset animation
+ animationData.currentPos = 0;
+ animationData.frames = animationData.initialFrames;
+
+ setTimeout(function() {
+ entity.animateSprite(animationData);
+ },
+ 1000 / animationData.fps);
+ }
return entity;
};
Please sign in to comment.
Something went wrong with that request. Please try again.