DELETE THIS ACC PLS Posted August 10, 2014 Share Posted August 10, 2014 Hi, I'm trying to make a pause function for my Open Source game, Flappy Box. I got the pause to work, but when you click "pause" text, the Box jumps. So I want to trigger the jump function only when pause is not touched.Here's what I use to trigger the jump function:game.input.onDown.add(this.jump, this);Simple, right? Thanks in advance. Link to comment Share on other sites More sharing options...
lewster32 Posted August 10, 2014 Share Posted August 10, 2014 At the very top of your jump function, add something like this:if (game.paused === true) { return;}This will stop execution of the rest of function if the game is paused. Link to comment Share on other sites More sharing options...
DELETE THIS ACC PLS Posted August 10, 2014 Author Share Posted August 10, 2014 @lewster32 I guess I haven't thought of that .. It makes sense but it seems that the box jumps then game's paused. I guess there's another solution? Link to comment Share on other sites More sharing options...
lewster32 Posted August 10, 2014 Share Posted August 10, 2014 Oh I see, so clicking 'pause' sets off the jump too? I guess you should have something to check if it's over the pause text:if (game.paused === true || game.input.hitTest(pauseText, game.input.activePointer)) { return;}I think that should work. Not entirely sure about the third parameter in hitTest. Link to comment Share on other sites More sharing options...
DELETE THIS ACC PLS Posted August 10, 2014 Author Share Posted August 10, 2014 @lewster32 You're right, that third parameter is suspicious ... Gave me an error:Uncaught TypeError: Cannot read property 'worldVisible' of undefinedWish that docs had code examples in them. Link to comment Share on other sites More sharing options...
lewster32 Posted August 10, 2014 Share Posted August 10, 2014 In that case try this:if (game.paused === true || Phaser.Rectangle.containsPoint(pauseText.getBounds(), game.input.activePointer.position)) { return;}You may want to store the result of getBounds() somewhere rather than calculating it each frame if your pauseText doesn't move or change size. DELETE THIS ACC PLS 1 Link to comment Share on other sites More sharing options...
DELETE THIS ACC PLS Posted August 10, 2014 Author Share Posted August 10, 2014 @lewster32 Thanks, Works like a charm. Now I've to get the box to stop jumping when un-pausing the game and v1.0 is halfway done. Is this the correct getBounds result? (ie What I have to save in a variable..)Phaser.Rectangle {x: 220, y: 20, width: 68, height: 28, offset: function…} Link to comment Share on other sites More sharing options...
lewster32 Posted August 10, 2014 Share Posted August 10, 2014 Yes, getBounds creates a Rectangle object containing the bounds of the object. If the object doesn't move or change shape, you can just save that result and check against it much faster. Link to comment Share on other sites More sharing options...
DELETE THIS ACC PLS Posted August 10, 2014 Author Share Posted August 10, 2014 Okay, thanks @lewster32 Link to comment Share on other sites More sharing options...
Recommended Posts