Search the Community
Showing results for tags 'call'.
-
Hello, So I actually have the following code that works: var player; var box_tnt; function create (){ this.physics.add.collider(player, box_tnt, hitTnt, null, this); } //the function hitTnt stop the game because the player died function hitTnt (player, boxes){ this.physics.pause(); player.setTint(0xff0000); player.anims.play('default'); gameOver = true; } and I want to do something like: var player; var box_tnt; function create (){ this.physics.add.collider(player, box_tnt, hitTnt, null, this); } //the function hitTnt stop the game because the player died function hitTnt (player, boxes){ gameOver(); //other stuff here } function gameOver (){ this.physics.pause(); console.log('Game Over!'); textGameOver.setText('GAME OVER'); player.setTint(0xff0000); player.anims.play('default'); gameOver = true; } but I have the following message: Do you have please any ideas how to do it properly?
-
Refer to the link below, for billboard enabled meshes, I added mouse pick event so the camera will target to the mesh which being clicked. However, after click on the mesh which BILLBOARDMODE_ALL is enabled, I got the following error. I'd be really appreciated if anyone can fix this issue. Thanks. https://www.babylonjs-playground.com/#9XBPW4#2 if (!m.actionManager){ m.actionManager = new BABYLON.ActionManager(scene); } var act = new BABYLON.ExecuteCodeAction( BABYLON.ActionManager.OnPickTrigger, pick ); m.actionManager.registerAction(act); function pick(evt){ var mesh = evt.meshUnderPointer; camera.setTarget(mesh); }
- 5 replies
-
- exceeded
- billboardmode_all
- (and 8 more)
-
Hello, I am new to Phaser and I am trying to get a player extends from a sprite and display it in the screen but I am not being able and I don't know why. If anyone could help me It would be appreciated. Thank you. this is my code play.js player.js game.js
-
Hello, recently I found code that is defining objects inheriting from Phaser.Sprite (if I google'd it and understood correctly). Can someone explain a little more about Phaser.Sprite.call() function? I haven't found it anywhere in docs. Also, what are the possible parameters? I found an example of code on some flappy bird tutorial : Pipe = function (game, x, y, speed) { Phaser.Sprite.call(this, game, x, y, "pipe"); game.physics.enable(this, Phaser.Physics.ARCADE, this); this.body.velocity.x = speed; this.giveScore = true; }; Pipe.prototype = Object.create(Phaser.Sprite.prototype); Pipe.prototype.constructor = Pipe; Pipe.prototype.update = function() { if(this.x+this.width<bird.x && this.giveScore){ score+=0.5; intro.prototype.updateScore(); this.giveScore = false; } if(this.x<-this.width){ this.destroy(); } }; I understand that "this" in the code is object (Pipe) right? I also have a question if I can (and how) create another sprite inside that Pipe - for example if I can have Pipe object that have two sprites (pipe1 and pipe2 which will have different properties). Or should I just define two objects and spawn both of them instead one with 2 sprites?
- 2 replies
-
- inheritance
- sprite.call
-
(and 2 more)
Tagged with:
-
So typically you have a function that switch to another state that call be call via a button or sprites this.btn_gameOver = this.game.add.button(this.game.width/2, 500, 'btn_play', this.start_gameOver, this);this.btn_gameOver.anchor.setTo(0.5,0.5);},start_gameOver: function(){ this.game.state.start('gameover', true, false, GameScore); } However when I use it within another function (updateTimer), once the countdown reached 0 and triggered, it return an error Uncaught TypeError: Cannot read property 'game' of undefined updateTimer: function(){ GameTimer--; txt_timer.text = GameTimer; if(GameTimer != 0){ console.log('it works!'); }else{ console.log('dingding'); //start_gameOver(); this.game.state.start('gameover', true, false, GameScore); } },What am I missing?
-
Hello everyone! apologize in advance for my poor English. The thing is I've been working on a mini game of roulette machines, I have divided my game with gameStates(boot, gameStates, load, stand, play, win and lose). so some mechanics is: to start the state of play should create an image preloaded on my state of load, this will be a zodiac sign, then press the space key image should be removed and display a sprite sheet which is appended an animation. Something like this: var winState = { create: function(){ //Este estado servira de test para presion/accion de boton... var sta1 = game.add.image(300, 150, 'geminis'); sta1.scale.setTo(0.2); game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)){ rotateAnim(); } }, rotateAnim: function(sta1){ sta1.destroy(); var sta2 = game.add.image(300, 150, 'signos'); sta2.animations.add('rotate'); sta2.animations.play('rotate', 1, true); }};BUT I didn't get the expected result. The only thing I desired result is obtained with the method onInputDown (Mouse): //In Create: Function();var sta1 = game.add.sprite(170, 360, 'leo');sta1.scale.setTo(0.17);sta1.anchor.set(0.5);sta1.inputEnabled = true;sta1.events.onInputDown.add(this.stopAnim, this);stopAnim: function(sta1){ //game.state.start('stand'); sta1.destroy(); var signos = game.add.sprite(170, 360, 'signos'); signos.scale.setTo(0.17); signos.anchor.set(0.5); signos.animations.add('change'); signos.animations.play('change', 5, true); }could someone tell me I'm doing wrong or that I needed to get the same result when you press a key. Thanks a lot for answers!
-
- animations
- function
-
(and 2 more)
Tagged with: