Jump to content

collide method doesn't work when spirite is fixed to camera


solomax
 Share

Recommended Posts

Hey guyz.

collide method doesn't work when  spirite is fixed to camera. I attached an image to show you what is the problem.

Here's my code:

var playState = {	xPosition: 0,	create: function(){		game.world.setBounds(0, 0, 500, 5000);		//Create the World		this.createWorld();		//Change background color		game.stage.backgroundColor = "#ffffaf";			//Add Player to the World		this.player = game.add.sprite(0,0,"player");		game.physics.arcade.enable(this.player);		this.player.anchor.setTo(0.5,0.5);		this.player.fixedToCamera = true;		this.xPosition = game.world.centerX; 		this.player.cameraOffset.setTo(this.xPosition, game.world.height - 300);		//Access to Arrow Keys		this.cursor = game.input.keyboard.createCursorKeys();		//Initialize		this.emitter = game.add.emitter(0, 0, 20);		this.emitter.makeParticles('tear');		this.emitter.setYSpeed(-150,150);		this.emitter.setXSpeed(-150,150);		this.emitter.gravity = -20;		game.camera.follow(this.player);	},	update: function(){		game.physics.arcade.overlap(this.layer,this.player,this.playerDie, null, this);		game.physics.arcade.collide(this.layer,this.emitter);		this.movePlayer();			},	createWorld: function(){		//Starter Map		this.startMap = game.add.tilemap('start_map');		this.startMap.addTilesetImage('rect');		this.layer = this.startMap.createLayer('Tile Layer 1');		this.layer.resizeWorld();		this.startMap.setCollision(1);		//game.camera.y += -200;	},	movePlayer: function(){		if(this.cursor.left.isDown){			this.xPosition += -20;			this.player.cameraOffset.setTo(this.xPosition, game.world.height - 300);		}else if(this.cursor.right.isDown){			this.player.body.velocity.x = 150;		}else{			this.player.body.velocity.x = 0;		}	},	playerDie: function(){		if(!this.player.alive){			return;		}		this.player.kill();		// Set the position of the emitter on the player				this.emitter.x = this.player.x;		this.emitter.y = this.player.y;		// Start the emitter, by exploding 15 particles that will live for 600ms		this.emitter.start(true, 900, null, 15);		game.time.events.add(1000, this.startMenu, this);				//Start Menu	},};

post-16510-0-71628200-1443300058.png

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...