Search the Community
Showing results for tags 'enemy movement'.
-
Howdy, Please excuse any ignorance of this, I checked the Tanks example but I think I am after something a bit different, yet simpler: I have a platform and I want to have 'enemies' moving randomly left and right. With my current code, I just have 1 enemy (the plan was to just get one working and then look at groups/objects later), it creates and starts moving using a timer but once the timer hits its first iteration the game stops and I get the following console error: Uncaught TypeError: Cannot read property 'apply' of undefined phaser.js:40106 This is the code I have in the create function for the droid // Create Droiddroidsprite = this.add.sprite(this.world.randomX, 450, 'droid');droidsprite.animations.add('walk');this.physics.arcade.enable(droidsprite);droidsprite.enableBody = true;droidsprite.body.bounce.y = 0.2;droidsprite.body.gravity.y = 500;droidsprite.body.collideWorldBounds = true;// Droid Movement Timer Creationgame.time.events.repeat(Phaser.Timer.SECOND * 3, 10, moveDroid(), game);Then I have a separate function to handle the movement: function moveDroid() { //randomise the movement droidmover = game.rnd.integerInRange(1, 3); //simple if statement to choose if and which way the droid moves if (droidmover == 1) { droidsprite.body.velocity.x = 100; droidsprite.animations.play('walk', 20, true); } else if(droidmover == 2) { droidsprite.body.velocity.x = -100; droidsprite.animations.play('walk', 20, true); } else { droidsprite.body.velocity.x = 0; droidsprite.animations.stop('walk', 20, true); } }Is it the fact I am using a Sprite or maybe I should have something in the update function? I am banging my head here as I thought the timer would just simply keep going? Thanks in advance.