Monster9800 Posted July 31, 2017 Report Share Posted July 31, 2017 Hey, I've got again problem. I have done respwan my monsters: function createMonster() { if(nextMonster>game.time.now) { return; } else { var monster = monsters.getFirstExists(false); if (monster) { monster.hp = 2; monster.velocityx = -50; monster.reset(ufo.x, ufo.y + 70); } } nextMonster = game.time.now + 4000; } Update: game.time.events.add(Phaser.Timer.SECOND * 4, createMonster, this); monsters.forEachAlive(function velocit (monster) { if(hitPlatform){ monster.body.velocity.x = monster.velocityx; } }); In my game monster falls down and if colide with platform gets speed. At first all it's ok, but next monsters gets speed at the time of fall. How can I solve my problem? PS. My create group code: monsters = game.add.group(); monsters.enableBody = true; monsters.physicsBodyType = Phaser.Physics.ARCADE; monsters.createMultiple(20, 'monster'); monsters.callAll('anchor.setTo', 'anchor', 0.5, 1.0); Quote Link to comment Share on other sites More sharing options...
samid737 Posted July 31, 2017 Report Share Posted July 31, 2017 my guess is that either hitPlatform is not reset to false, which results in all your group objects having -50 velocity... or you are setting the velocity of all your group objects when your using monsters.forEachAlive()... try console.log(monsters) and inspect your monster sprites, its probably because they all have -50 velocity in x direction. If you want your monsters to move only when colliding with platform, then you can do something like this (mostly your code): here you are using the collide function with callBacks when colliding. The createMonster() is now called via A loop event set in create() instead of .add in update(). Monster9800 1 Quote Link to comment Share on other sites More sharing options...
Monster9800 Posted August 1, 2017 Author Report Share Posted August 1, 2017 Ok, thanks a lot Now, works correctly. Previously, hitPlatform not reset to false. But i will use "game.physics.arcade.collide(platform,monsters,move);" samid737 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.