Aristy Posted March 25, 2015 Share Posted March 25, 2015 Hey, I started learning Phaser few hours ago, and I currently have a crappy code like this:var monsterDirection = 'left';function create() { var monster = game.add.sprite(320, game.world.height - 150, 'monster '); game.physics.arcade.enable(monster ); monster.body.bounce.y = 0.2; monster.body.gravity.y = 500; monster.body.collideWorldBounds = true; monster.animations.add('left', [0, 1], 10, true); monster.animations.add('right', [2,3], 10, true);}function update() { game.physics.arcade.collide(monster, objects); canavar.body.velocity.x = 0; // Move monster if(monsterDirection === 'left') { monster.animations.play('left'); monster.body.velocity.x = -200; } else { monster.animations.play('right'); monster.body.velocity.x = 200; } // Check for collisions so we can reverse direction if(monster.body.blocked.left === true) { monsterDirection = 'right'; } if(monster.body.blocked.right === true) { monsterDirection = 'left'; } // Keep jumping if(monster.body.touching.down === true) { monster.body.velocity.y = -500; }}Basically, I have a `monster` object whom keeps jumping around until it gets blocked by a collision, where he reverses the direction. Think it like the monsters from Mario. Anyway, I tried to do this with groups, but couldn't find any examples as the examples in groups section only shows static assets. Can anybody help me about carrying this logic to a `group`, so I can spawn as much monster instances as I like every second? Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts