Search the Community
Showing results for tags 'downduration'.
-
hi everyone I'm going to build a simple game with phaser. there's a ball which you can click on it and hold for seconds, longer you hold longer ball throws when you release click. here's my code wich works fine with pc and mouse but not working with mobile touch screen. I don't understand what's the problem and why it's not working on touch screen(android): function create() { ball = game.add.sprite(32, game.world.height - 100, 'ball'); game.physics.arcade.enable(ball); ball.body.bounce.y = 0.2; ball.body.gravity.y = 400; ball.inputEnabled = true; } var power = 0; function update() { if(ball.input.downDuration()>0){ power = ball.input.downDuration(); } //if(star.input.pointerUp()==true && power > 0) { if(game.input.activePointer.isDown==false && power > 0) { ball.body.velocity.x = power*2; ball.body.velocity.y = -400; power=0 } } Edit: I changed my code as below still not working on touch screen devices but works fine with mouse: function create() { ball = game.add.sprite(32, game.world.height - 100, 'ball'); game.physics.arcade.enable(ball); ball.body.bounce.y = 0.2; ball.body.gravity.y = 400; game.input.onUp.add(onBallDownHold, this); } var power = 0; function update() { if(ball.input.downDuration()>0) power = star.input.downDuration(); if(game.input.activePointer.isDown==false && power > 0) { power=0; } } function onBallDownHold(pointer) { if( power > 0) { ball.body.velocity.x = pointer.duration * 2; ball.body.velocity.y = -400; } }
-
Hello, I'm trying to trigger a function when a sprite is tapped and holded for 1sec. For the moment, I just capture the x/y position of the pointer on the inputDown of the sprite, and check the position 1sec after that, with a boolean to check if the input has been released. It works fine, but it's a bit buggy, specially when you massively tap the sprite, so I'd like to do it better. I've been trying the onHold function, but unfortunatelly this is not a sprite function but a 'game.input' function, so i'd have to iterate through all of my sprites if I want to check it, and as I have lots of sprites, it doesn't seem to me like the best answer. So I found this 'sprite.downDurration' function, sounds simple and fancy, but I couldn't find out the way to get that working. I've seen this post here, but It didn't help either, here's what I've tried: console.log('Time: ' + sprite.input.downDuration().toFixed(0)); // Returns -1console.log('Time: ' + sprite.input.downDuration(this.game.input.activePointer)); // Crashesconsole.log('Time: ' + sprite.input.downDuration);// Returs " function (a){return a=all0, this._pointerData[a].isDown?this.game.time.time-this.pointerData[a].timeDown:-1;}What am I missing? I've been searching in Phaser Examples but there isn't any example regarding holding an input or something like that.
- 3 replies
-
- sprite
- downDuration
-
(and 1 more)
Tagged with: