From 0d3763e09a2208929a48e1f5cf6302c33dc0fc64 Mon Sep 17 00:00:00 2001 From: Josh Edeen Date: Tue, 29 Sep 2015 22:39:06 -0500 Subject: [PATCH] fix #506 animation freezeframe never set --- sandbox/web/Excalibur.Sandbox.csproj | 3 ++ sandbox/web/index.html | 1 + sandbox/web/tests/animation/animation.html | 13 +++++++++ sandbox/web/tests/animation/animation.png | Bin 0 -> 1400 bytes sandbox/web/tests/animation/animation.ts | 31 +++++++++++++++++++++ src/engine/Drawing/Animation.ts | 3 ++ 6 files changed, 51 insertions(+) create mode 100644 sandbox/web/tests/animation/animation.html create mode 100644 sandbox/web/tests/animation/animation.png create mode 100644 sandbox/web/tests/animation/animation.ts diff --git a/sandbox/web/Excalibur.Sandbox.csproj b/sandbox/web/Excalibur.Sandbox.csproj index fb7e6668a..6119c0040 100644 --- a/sandbox/web/Excalibur.Sandbox.csproj +++ b/sandbox/web/Excalibur.Sandbox.csproj @@ -68,6 +68,8 @@ + + @@ -103,6 +105,7 @@ + diff --git a/sandbox/web/index.html b/sandbox/web/index.html index 21334e7ed..13a474109 100644 --- a/sandbox/web/index.html +++ b/sandbox/web/index.html @@ -6,6 +6,7 @@
  • Sandbox Platformer
  • +
  • Animations
  • Sprite Culling
  • Input
  • Keyboard Input
  • diff --git a/sandbox/web/tests/animation/animation.html b/sandbox/web/tests/animation/animation.html new file mode 100644 index 000000000..07a5b180e --- /dev/null +++ b/sandbox/web/tests/animation/animation.html @@ -0,0 +1,13 @@ + + + + Animation Test + + + + + +

    Press 'd' for debug mode

    +

    An animation with 3 frames should play, stopping on the third frame.

    + + \ No newline at end of file diff --git a/sandbox/web/tests/animation/animation.png b/sandbox/web/tests/animation/animation.png new file mode 100644 index 0000000000000000000000000000000000000000..f765573315e53e3818fdabbd8f113f0d98423505 GIT binary patch literal 1400 zcmZvaZ%h+s9LFET&5lCC2rxzd+(eYXu@nd4WC(j$&w)k8Rj#zdIqnb*U`!r17kp7i z3c6x6nM6w*B9o{0ss(ITB6nh5JpPv!-bYbIJ94rE8Xd#ODrif=m>=!YX zF_$Zg zXZIh=zOlMiDz^p)izb$<%m)hiq)XBM=CS-;=*#KCS5GrV((}L}7XE&0dR5O{OIpQ< zb7h9o#vf0s=A64TKi6g7xYPgf&V;x#{%zz*uR=NCdHbB>h>ozGi_^MSH}cPoe4?MT z=V$IE+q{v=3!ZAuaZv|^0XA89wDUbOva^OJ(KVMR z|LoM=p8Jz}SLN~#{P2#&@v)_%OHaNo&(a8u{W08J-(!00iaBGww@$alKKZAAeDun< z8OfH-o|aT9{)1nysr64fKmCPU{%~WV#aH|A75!v)&%nAld*UHQ?umr8%HiK$JAGcq zztFzH7UxJlpepYB=;RySUAMn;xx2fda5%Alsb=`9cW$q}eE%1n&%5W@oP+knT}_Wu z^?i9hOkSKCVe+*qrOVYr#WkjX0TkX! AVgLXD literal 0 HcmV?d00001 diff --git a/sandbox/web/tests/animation/animation.ts b/sandbox/web/tests/animation/animation.ts new file mode 100644 index 000000000..94f916f6d --- /dev/null +++ b/sandbox/web/tests/animation/animation.ts @@ -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(() => { + +}); \ No newline at end of file diff --git a/src/engine/Drawing/Animation.ts b/src/engine/Drawing/Animation.ts index 7da1ca14f..5df9f8693 100644 --- a/src/engine/Drawing/Animation.ts +++ b/src/engine/Drawing/Animation.ts @@ -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; } + } /**