Search the Community
Showing results for tags 'collsion-callback'.
-
Hi guys! I'd like to make a computer object in my game, such that when player approches to the computer,it triggers onEnter callback ( where I can for example show a message on screen to press certain key ) and when player goes away it triggers onLeave callback ( where I can hide the message ). In order to achieve that I need two colliders, one for regular collision ( red one ), and the other to detect if the player entered computer's zone ( green one, this is the one that I want to trigger callback ). this.computer = this.game.add.sprite( 9 * TILE_WIDTH + COMPUTER_WIDTH / 2, TILE_HEIGHT + COMPUTER_HEIGHT / 2, 'computer' ); this.game.physics.p2.enable( this.computer ); this.computer.body.static = true; this.computer.body.addRectangle( TILE_WIDTH, TILE_HEIGHT, COMPUTER_WIDTH / 2, COMPUTER_HEIGHT / 2 ); this.computersCollisionGroup = this.game.physics.p2.createCollisionGroup( this.computer ); this.computer.body.collides( this.playerCollisionGroup, () => console.log( 'player in range' ) ); this.player.body.collides( this.computersCollisionGroup ); My question is: How do I turn off physical collision in green collider and what to do to make green collider trigger onEnter and onLeave callbacks ?
- 9 replies
-
- collsion-callback
- phaser
-
(and 1 more)
Tagged with: