Search the Community
Showing results for tags 'emitter overlap detection'.
-
Hello there, I am not getting any results with particle collision detection. I am able to detect collision on sprite (bird touching ground or branch), but I am unable to detect collision or even overlap with the particle emitter (rain). The rain (particles) fall on the bird, yet there is no detection or error in the code. Very confusing. If anyone can see what am I doing wrong / what did I forgot to add to the code I will be very thankful. var GameState = { init: function() { this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 1000; this.game.world.setBounds(0,0,game.width + 100, game.height); }, create: function() { var bounds = new Phaser.Rectangle(0 - 50, 0, game.width + 50, 400); this.background = this.game.add.sprite(0, 0, 'background'); this.background.inputEnabled = true; this.background.events.onInputDown.add(moveBird, this); this.ground = this.game.add.sprite(0, game.height-355, 'ground'); this.underground = this.game.add.sprite(0, game.height-49, 'underground'); //this.underground.inputEnabled = true; this.game.physics.arcade.enable(this.underground); this.underground.body.allowGravity = false; this.underground.body.immovable = true; this.cloud1 = this.game.add.sprite(10, 10, 'cloud1'); this.cloud1.anchor.setTo(0.5); this.cloud1.inputEnabled = true; this.cloud1.input.enableDrag(true); this.cloud1.input.boundsRect = bounds; this.game.physics.arcade.enable(this.cloud1); this.cloud1.body.allowGravity = false; this.branch = this.game.add.sprite(900, 350, 'branch'); this.branch.anchor.setTo(0.5); this.game.physics.arcade.enable(this.branch); this.branch.body.allowGravity = false; this.branch.body.immovable = true; this.bird = this.game.add.sprite(800,120, 'bird'); this.bird.anchor.setTo(0.5); this.game.physics.arcade.enable(this.bird); this.bird.inputEnabled = true; this.bird.input.enableDrag(); this.game.camera.follow(this.bird); //create an emitter rain = game.add.emitter(0, 0, 1000); rain.makeParticles('rain'); // Attach the emitter to the sprite this.cloud1.addChild(rain); //position the emitter relative to the sprite's anchor location rain.y = 30; rain.x = 0; //rain.lifespan = 500; rain.width = 160; // setup options for the emitter rain.minParticleScale = 0.1; rain.maxParticleScale = 0.5; rain.setYSpeed(300, 500); rain.setXSpeed(-5, 5); rain.minRotation = 0; rain.maxRotation = 0; this.cloud1.events.onInputDown.add(cloudDrag1, this); cloud1Moving = game.add.tween(this.cloud1).to({ x: game.width + 300 }, 120000, Phaser.Easing.Linear.None, true, 0, 1000, true) function cloudDrag1(sprite, pointer) { rain.start(false, 1600, 5, 0); this.game.physics.arcade.enable(rain); console.log(rain); game.time.events.add(Phaser.Timer.SECOND * 7, stopRaining, this); function stopRaining(){ rain.on = false; } } this.cloud1.events.onDragStart.add(onDragStart, this); this.cloud1.events.onDragStop.add(onDragStop, this); function onDragStart(sprite, pointer) { cloud1Moving.stop(); cloud1Moving.pendingDelete = false; } function onDragStop(sprite, pointer) { cloud1Moving.updateTweenData(5000); cloud1Moving.start(); } function moveBird(sprite, event) { var x = event.position.x; var y = event.position.y; var birdMovement = this.game.add.tween(this.bird); birdMovement.to({x: x, y: y}, 700); this.bird.body.allowGravity = false; console.log('bird is flying'); birdMovement.start(); } }, update: function() { this.game.physics.arcade.collide(this.bird, this.underground, this.landedGround); this.game.physics.arcade.collide(this.bird, this.branch, this.landedBranch); this.game.physics.arcade.overlap(this.bird, rain, this.change); }, landedGround: function(bird, underground){ console.log('bird landed on ground...'); //console.log(rain); }, landedBranch: function(bird, branch){ console.log('bird landed on branch...'); }, change: function(l, r){ console.log('touched rain...'); }, };
- 2 replies
-
- collision detection with sprite
- sprite and particles
- (and 2 more)