gnarf

Members
  • Content Count

    6
  • Joined

  • Last visited

About gnarf

  • Rank
    Newbie

Contact Methods

  • Website URL
    http://jarofoj.tumblr.com
  • Twitter
    @thegnarf

Profile Information

  • Gender
    Male
  1. Yeah, sorry, I should have been more clear. I want the idle to play every 2.5 seconds if the player isn't moving at all, not to loop constantly. But that makes me wonder, is there a way to check when an animation is complete?
  2. Hi, I'm working on a simple platformer and I'm trying to get the player to play his idle animation when a timer reaches 0. I looked at the Basic Repeat Event example to get a sense of things. I tried two ways but didn't get the correct results. V1: Sprite will flicker with the first frame of the idle animation, but does not play it through. function create() { player.animations.add('idle', [4, 15], 10, false); game.time.events.repeat(Phaser.Timer.SECOND * 2.5, 10, idleAnim, this);}function idleAnim() { if (player.body.velocity.x === 0 && player.body.touching.down) { player.animations.play('idle'); }}V2: After the timer ticks, nothing happens until I move my character left or right, in which case, he gets stuck in the first frame of the idle. var goIdle = 0;function create() { player.animations.add('idle', [4, 15], 10, false); game.time.events.repeat(Phaser.Timer.SECOND * 2.5, 10, idleAnim, this);}function idleAnim() { if (player.body.velocity.x === 0 && player.body.touching.down) { goIdle = 1; } else goIdle = 0;}function update() { if (goIdle === 1) { player.animations.play('idle'); };I feel like I'm missing something totally obvious. Also, as a side note, does the repeat function need to have a repeat count? Could I leave that out if I wanted it to tick infinitely? Thanks!
  3. Ah, that explains a ton. I kept wondering why "enemies" was being found, but suddenly there was an error when it reached "baddie". It helps to split them up the way you did, so I'll keep that in mind as I update my code. Thanks!
  4. You know, variable scope was confusing me and I remember reading through it and thinking I'd figure it out when it came up. That didn't happen, but I understand it now. Thanks a ton, the example does exactly what I wanted and it makes sense to me. This was particularly helpful: createdBaddie.name = "alien_" + i; Part of the reason I was logging the created baddies was because I wanted to know how they were being named when out of my control. Should have thought of this though. Thanks again!
  5. Whoops, sorry about that. I'll ask a mod to move it over. Thanks for the reply, I think it's already putting me in the right direction.
  6. Hello, I'm new to Phaser and Javascript but I'm slowly getting the hang of things. I ran into a problem while messing with the first tutorial ("Making your first game"). I'm trying to play through a sprite sheet based on the x velocity of each object created within a certain group. I've tried messing with all the values, changing the names of variables, etc. I searched the docs and looked for examples that were similar but the closest I got was finding the forEach method. I'm not sure if I'm using it correctly, though. I created an enemies group and added a series of baddie objects to it. All of that works, but when I go to the update function to try and animate them, the console returns: Uncaught TypeError: Cannot read property 'play' of undefined. Here's my code (I left out some things like collision checks because that all works correctly): var baddie;function createBaddie() { baddie = enemies.create(game.world.randomX, game.world.RandomY, 'baddie'); baddie.body.gravity.y = 300; baddie.body.bounce.set(0.8); baddie.body.velocity.x = Math.floor((Math.random() * 100) + 1); baddie.body.collideWorldBounds = true; baddie.animations.add('left', [0, 1], 10, true); baddie.animations.add('right', [2, 3], 10, true);};// in the create functionenemies = game.add.group();enemies.enableBody = true;game.physics.arcade.enable(enemies);for (var i = 0; i < 5; i++) { createBaddie(); //logging baddies to check what they're named console.log(baddie); };// in the update function (none of this works)enemies.forEach(function() { if (baddie.body.velocity.x > 0) { this.animation.play('right'); } else if (baddie.body.velocity.x < 0) { this.animation.play('left'); } }, this);I'd appreciate any help I can get on this topic or how to do this in a better way. Thanks!