Search the Community
Showing results for tags 'on'.
-
from this playground file https://www.babylonjs-playground.com/#W2DP7F#3 i managed to add 'click to play' poster frame and made a toggle bit: scene.onPointerUp = function() { if (videoTexture.video.paused === true){ videoTexture.video.play(); } else { videoTexture.video.pause(); } but now i wonder how to add the eventListener("onended") and set currentTime to 0 again AND show the posterFrame. Any ideas?
-
- event handler
- on
-
(and 2 more)
Tagged with:
-
Hi, I'm still pretty new to Phaser and I'm making a character select screen that shows all of the characters (only 3). Each one has a button that looks like a power on/off switch. When you click the button it should toggle the button to the correct frame ("on"), but if you click another character it should switch "off" the button of the previously chosen character and turn the currently chosen button to "on." The toggling was one issue, this was the best thing I could think of (it works, but it ends up being repetitive since there are 3 characters): //Button this.pickPink = game.add.button(game.world.centerX, game.world.centerY+105, "buttons", this.pinkStart, this); this.pickPink.anchor.set(0.5, 0.5); //Start with Pink pinkStart: function () { if(this.pickPink && character !== "pink"){ //set button frame to "ON" this.pickPink.frame = 1; character = "pink"; } else if(this.pickPink && character === "pink"){ //set button frame to "OFF" this.pickPink.frame = 0; character = undefined; } console.log(character); }, But now I need to figure out how I would detect that if another button gets picked, turn the previous one (or all others) to OFF. I don't want more than one of these toggled on at a time. Is there anyway of achieving this? Many thanks and much appreciated!!
-
In the game that I am currently making using Phaser and P2 Physics I am looking to turn off the collisions between 3 objects when the game is paused or when the level has ended and the scoreboard shows so that unnecessary collisions are not being checked and dropping the frame rate (game is intended to run on mobile devices). I am using the following two functions at the moment TurnOffCollisions: function() { console.log("TurnOffCollisions") SavedBallVelX = Ball.body.velocity.x; SavedBallVelY = Ball.body.velocity.y; Ball.body.velocity.x = 0; Ball.body.velocity.y = 0; this.game.physics.p2.gravity.y = 0; FairwayHole.body.clearCollision(); Ball.body.clearCollision(); FairwayHole.body.clearShapes(); Ball.body.clearShapes(); Block.body.clearCollision(); Block.body.clearShapes(); },And to turn on the Collisions again when the game is unpaused or the next level starts: TurnOnCollisions: function() { console.log("TurnOnCollisions"); this.game.physics.p2.enable(FairwayHole); this.game.physics.p2.enable(Ball); this.game.physics.p2.enable(Block); FairwayHole.body.loadPolygon("Physics", "Level1-Hole"); FairwayHole.kinematic = true; Ball.body.loadPolygon("Physics", "Ball2"); Ball.body.velocity.x = SavedBallVelX; Ball.body.velocity.y = SavedBallVelY; Block.body.static = true; this.game.physics.p2.gravity.y = 1400; ballMaterial = this.game.physics.p2.createMaterial("ballMaterial", Ball.body); groundMaterial = this.game.physics.p2.createMaterial("groundMaterial", FairwayHole.body); this.game.physics.p2.setWorldMaterial(groundMaterial, true, true, true, true); contactMaterial = this.game.physics.p2.createContactMaterial(ballMaterial, groundMaterial); contactMaterial.friction = 0.5; contactMaterial.restitution = 0.5; }However when I do this it seems to work OK, until the Level Finishes and the Ball object and FairwayHole object are still touching, even though I think I have turned off the Physics I get the following error: Uncaught TypeError: Cannot read property 'collisionMask' of undefined54.c.runNarrowphasephaser.js:76867 54.c.internalStepphaser.js:76685 54.c.stepphaser.js:78255 c.Physics.P2.updatephaser.js:61785 c.Physics.updatephaser.js:26388 c.Game.updateLogicphaser.js:26327 c.Game.updatephaser.js:44881 c.RequestAnimationFrame.updateRAFphaser.js:44865 c.RequestAnimationFrame.start.window.requestAnimationFrame.forceSetTimeOut._onLoopIs there a better way of turning on and off collisions using P2 Physics? Or Am I doing something wrong with the way I am doing it that is causing the game to crash?