AlexArroyoDuque Posted March 17, 2014 Share Posted March 17, 2014 Hi game developers! The player of my game uses P2 physics. I need that when an enemy dies and drop coins the player can catch them. Therefore, the player must be able to collide with the coins. Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 17, 2014 Author Share Posted March 17, 2014 It is possible to define the collision system in P2 emitters. But I can not know how to use "setCollisionGroup" with the generated particles. pice of code: this.emitterCoin = this.game.add.emitter(0, 0, 50); this.emitterCoin.enableBody = true; this.emitterCoin.physicsBodyType = Phaser.Physics.P2JS; this.emitterCoin.body.setCollisionGroup(this.coinCG); // error this.emitterCoin.makeParticles('coin', [0], 100, true, true); Any help with this? Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 18, 2014 Author Share Posted March 18, 2014 anyone? I believe that I need to assign a collisionGroup to my emitter. Anyone would think otherwise that generated particles collide with the player? Link to comment Share on other sites More sharing options...
george Posted March 18, 2014 Share Posted March 18, 2014 Hi alejandro,the particles created by the emitter class are currently fixed to the Arcade Physics Engine. I believe it was a quick port from Rich so it can be included in the 2.0 release of Phaser. You cannot simply change the physics type without touching the original source or creating your own class either by inheriting Phaser.Particles.Arcade.Emitter or creating your very own Emitter Class. Look at the source from phaser.Phaser.Particles.Arcade.Emitter.prototype.makeParticles = function (keys, frames, quantity, collide, collideWorldBounds) { //[...] other code parts removed particle = new Phaser.Sprite(this.game, 0, 0, rndKey, rndFrame); this.game.physics.arcade.enable(particle, false);Here you can see where the physics engine gets activated. There is no attribute 'physicsBodyType' involved in the particle creation (anyway, nice try). How many coins do you want to create ? Maybe the easiest solution for you is to create a loop which creates each coin after another - including the correct physics behaviour and collision group. In other words: Try to forget the emitter, try to create ONE coin and if this works you should be able to create a hundred coins. Have funRegards George Link to comment Share on other sites More sharing options...
valueerror Posted March 18, 2014 Share Posted March 18, 2014 i'd go with george's approach for now.. if enemy dies - get enemy.body.x and enemy.body.y and create as much coins as you need at the x and y coordinates...@george the docs suggest that you CAN define another physics engine for the particles... maybe rich planned to implement this but didnt find the time yet.. Link to comment Share on other sites More sharing options...
AlexArroyoDuque Posted March 18, 2014 Author Share Posted March 18, 2014 Well, we have to wait ... Sure later, Rich gives us something about particles in P2. Right now I have chosen to do a manual simulation. A piece of code. It works ok: for (var i = 0; i < obj.sprite.coins; i = i + 1) { var newCoin = theGame.emitterCoinGroup.getFirstExists(false); if (newCoin) { newCoin.reset(obj.x + utils.rangeRandom(-15, 15), obj.y - utils.rangeRandom(10, 50), 'coin'); newCoin.body.velocity.x = utils.rangeRandom(- 50, 50); newCoin.body.data.gravityScale = 0.25; newCoin.anchor.setTo(0.5, 0.5); newCoin.body.setCollisionGroup(theGame.coinCG); newCoin.body.collides([theGame.playerCG, theGame.layerCG]); newCoin.lifespan = 20000; newCoin.body.mass = 0.01; newCoin.alpha = 0.8; } } Thank you very much gamers. Link to comment Share on other sites More sharing options...
Recommended Posts