Skip to content

Commit

Permalink
fix #506 animation freezeframe never set
Browse files Browse the repository at this point in the history
  • Loading branch information
jedeen committed Sep 30, 2015
1 parent 199a382 commit 0d3763e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sandbox/web/Excalibur.Sandbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
<Content Include="html\healthbar.tmpl" />
<Content Include="images\heart.png" />
<Content Include="index.html" />
<Content Include="tests\animation\animation.html" />
<Content Include="tests\animation\animation.png" />
<Content Include="tests\audio\index.html" />
<Content Include="tests\audio\loop.mp3" />
<Content Include="tests\collision\index.html" />
Expand Down Expand Up @@ -103,6 +105,7 @@
</ItemGroup>
<ItemGroup>
<TypeScriptCompile Include="src\game.ts" />
<TypeScriptCompile Include="tests\animation\animation.ts" />
<TypeScriptCompile Include="tests\audio\index.ts" />
<TypeScriptCompile Include="tests\collision\index.ts" />
<TypeScriptCompile Include="tests\culling\culling.ts" />
Expand Down
1 change: 1 addition & 0 deletions sandbox/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<body>
<ul>
<li><a href="html/index.html">Sandbox Platformer</a></li>
<li><a href="tests/animation/animation.html">Animations</a></li>
<li><a href="tests/culling/culling.html">Sprite Culling</a></li>
<li><a href="tests/input/index.html"> Input</a></li>
<li><a href="tests/input/keyboard.html">Keyboard Input</a></li>
Expand Down
13 changes: 13 additions & 0 deletions sandbox/web/tests/animation/animation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Animation Test</title>
</head>
<body>
<canvas id="game"></canvas>
<script src="../../Excalibur.js"></script>
<script src="animation.js"></script>
<p>Press 'd' for debug mode</p>
<p>An animation with 3 frames should play, stopping on the third frame.</p>
</body>
</html>
Binary file added sandbox/web/tests/animation/animation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions sandbox/web/tests/animation/animation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var width = 600;
var height = 400;
var playerTexture = new ex.Texture("animation.png");


var engine = new ex.Engine(
{
width: width,
height: height,
canvasElementId: 'game',
pointerScope: ex.Input.PointerScope.Canvas
});
engine.backgroundColor = ex.Color.Black;

var player = new ex.Actor(width / 2, height / 2, 100, 30, ex.Color.Red);
var spritesheet = new ex.SpriteSheet(playerTexture, 3, 1, 100, 100);
var animation = spritesheet.getAnimationForAll(engine, 1500);
animation.loop = false;
player.addDrawing("default", animation);
engine.currentScene.add(player);

engine.input.keyboard.on('down', (keyDown?: ex.Input.KeyEvent) => {
if (keyDown.key === ex.Input.Keys.D) {
engine.isDebug = !engine.isDebug;
console.log(animation.freezeFrame);
}
});

engine.start(new ex.Loader([playerTexture])).then(() => {

});
3 changes: 3 additions & 0 deletions src/engine/Drawing/Animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ module ex {

this.naturalWidth = images[0] ? images[0].naturalWidth : 0;
this.naturalHeight = images[0] ? images[0].naturalHeight : 0;

this.freezeFrame = images.length - 1;
}

}

/**
Expand Down

0 comments on commit 0d3763e

Please sign in to comment.