Skip to content

Commit

Permalink
dont reset frame when looping
Browse files Browse the repository at this point in the history
  • Loading branch information
straker committed Jul 14, 2018
1 parent b3739b9 commit 9e50638
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/sprite.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions docs/js/kontra.js
Original file line number Diff line number Diff line change
Expand Up @@ -1733,9 +1733,15 @@ this.kontra = {
* @param {boolean} [loop=true] - If the animation should loop.
*/
playAnimation: function playAnimation(name, loop) {
loop = (loop == undefined ? true : loop);

this.currentAnimation = this.animations[name];
this.currentAnimation.loop = (loop == undefined ? true : loop);
this.currentAnimation._frame = 0;
this.currentAnimation.loop = loop;

// reset the frame if we shouldn't loop the animation, that way
// changing animations on keydown doesn't constantly reset the
// frame
if (!loop) this.currentAnimation._frame = 0;
},

/**
Expand Down
6 changes: 6 additions & 0 deletions examples/tileEngine/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</head>
<body>
<canvas width="600" height="600"></canvas>
<p>M - Mute</p>
<script id="code">
/**
* ATTRIBUTION:
Expand Down Expand Up @@ -201,7 +202,12 @@
}
});

kontra.keys.bind('m', function() {
kontra.assets.audio.Digital_Forest.muted = !kontra.assets.audio.Digital_Forest.muted;
});

kontra.assets.audio.Digital_Forest.loop = true;
kontra.assets.audio.Digital_Forest.volume = 0.5;
kontra.assets.audio.Digital_Forest.play();
loop.start();
});
Expand Down
10 changes: 8 additions & 2 deletions kontra.js
Original file line number Diff line number Diff line change
Expand Up @@ -1733,9 +1733,15 @@ this.kontra = {
* @param {boolean} [loop=true] - If the animation should loop.
*/
playAnimation: function playAnimation(name, loop) {
loop = (loop == undefined ? true : loop);

this.currentAnimation = this.animations[name];
this.currentAnimation.loop = (loop == undefined ? true : loop);
this.currentAnimation._frame = 0;
this.currentAnimation.loop = loop;

// reset the frame if we shouldn't loop the animation, that way
// changing animations on keydown doesn't constantly reset the
// frame
if (!loop) this.currentAnimation._frame = 0;
},

/**
Expand Down

0 comments on commit 9e50638

Please sign in to comment.