Note that there are some explanatory texts on larger screens.

plurals
  1. POCraftyjs animation not changing properly
    primarykey
    data
    text
    <p>I'm using <a href="http://craftyjs.com/" rel="nofollow">http://craftyjs.com/</a> for the Github Game Off, and I'm having some trouble with animation. The first time I start the animation (when I initialize the player entity in the main scene) it works. But when I set the animation via my CustomControls component, it only plays the first frame of the animation.</p> <p>I believe the problem is in the CustomControls component, so here's the code for that: <a href="https://gist.github.com/3992392" rel="nofollow">https://gist.github.com/3992392</a></p> <p>Here's all the code if you want to clone it and test: <a href="https://github.com/RylandAlmanza/dragons-suck" rel="nofollow">https://github.com/RylandAlmanza/dragons-suck</a></p> <p>If anyone knows what the problem might be, let me know. Thanks!</p> <p>EDIT: Here's a minimal jsfiddle example with everything stripped out except for movement and what should be animation: <a href="http://jsfiddle.net/x7FDF/" rel="nofollow">http://jsfiddle.net/x7FDF/</a></p> <pre><code>var SPRITE_SIZE = 32; Crafty.init(); Crafty.canvas.init(); Crafty.sprite(SPRITE_SIZE, "http://i.imgur.com/9sN9V.png", { player_east_1: [0, 0], player_east_2: [1, 0], player_east_3: [2, 0], player_west_1: [0, 1], player_west_2: [1, 1], player_west_3: [2, 1], player_south_1: [0, 2], player_south_2: [1, 2], player_south_3: [2, 2], player_north_1: [0, 3], player_north_2: [1, 3], player_north_3: [2, 3] }); Crafty.scene("loading", function() { Crafty.background("#000"); Crafty.e("2D, DOM, Text") .attr({ w: 100, h: 20, x: 150, y: 120 }) .text("Loading") .css({"text-align": "center"}); Crafty.load(["http://i.imgur.com/9sN9V.png"], function() { Crafty.scene("main"); }); }); Crafty.scene("main", function() { Crafty.background("#000"); var player = Crafty.e("2D, DOM, SpriteAnimation, player_east_1, Collision, TileCollision, CustomControls") .attr({ x: 0, y: 0, x_velocity: 0, y_velocity: 0, w: SPRITE_SIZE, h: SPRITE_SIZE }) .animate("stand_east", 0, 0, 0) .animate("stand_west", 0, 1, 0) .animate("stand_south", 0, 2, 0) .animate("stand_north", 0, 3, 0) .animate("walk_east", [[0, 0], [1, 0], [0, 0], [2, 0]]) .animate("walk_west", [[0, 1], [1, 1], [0, 1], [2, 1]]) .animate("walk_south", [[0, 2], [1, 2], [0, 2], [2, 2]]) .animate("walk_north", [[0, 3], [1, 3], [0, 3], [2, 3]]) .animate("stand_east", 45, -1) .CustomControls(); }); Crafty.c("CustomControls", { CustomControls: function() { this.bind("EnterFrame", function() { var up = Crafty.keydown[Crafty.keys.UP_ARROW]; var down = Crafty.keydown[Crafty.keys.DOWN_ARROW]; var left = Crafty.keydown[Crafty.keys.LEFT_ARROW]; var right = Crafty.keydown[Crafty.keys.RIGHT_ARROW]; if (up) { this.y_velocity = -2; if (!this.isPlaying("walk_north")) { this.stop().animate("walk_north", 45, -1); } } if (down) { this.y_velocity = 2; if (!this.isPlaying("walk_south")) { this.stop().animate("walk_south", 45, -1); } } if (left) { this.x_velocity = -2; if (!this.isPlaying("walk_west")) { this.stop().animate("walk_west", 45, -1); } } if (right) { this.x_velocity = 2; if (!this.isPlaying("walk_east")) { this.stop().animate("walk_east", 45, -1); } } if (!left &amp;&amp; !right) { this.x_velocity = 0; this.stop(); } if (!up &amp;&amp; !down) { this.y_velocity = 0; this.stop(); } this.x += this.x_velocity; this.y += this.y_velocity; }); } }); Crafty.scene("loading");​ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload