# ogramp

Members

13

• Rank
Member
1. ## P2 physics trajectory on a physics body.

Ok, fresh eyes are best eyes. Let a friend take a look at it and the Phaser's own example and var tpx = startX + n * stepVelocityX + 0.05 * (n * n * n) * stepGravityX; var tpy = startY + n * stepVelocityY + 0.05 * (n * n * n) * stepGravityY; those two lines have to be var tpx = startX + n * stepVelocityX + 0.5 * (n * n + n) * stepGravityX; var tpy = startY + n * stepVelocityY + 0.5 * (n * n + n) * stepGravityY; And the power needs a bit fiddlin but it works! Yay!
2. ## P2 physics trajectory on a physics body.

Hey, I'm trying to make a basketball game with predicted trajectory and I am having trouble with the trajectory. chargeBall: function(Pointer, x, y) { // If the button is down we charge the ball. if( Pointer.isDown && !isBallMoving ) { // Clear the graphics, set the style and draw the line from the ball to the Pointer. trajectoryGraphics.clear(); trajectoryGraphics.lineStyle( 2, '0xCCCCCC' ); trajectoryGraphics.moveTo( ball.x, ball.y ); trajectoryGraphics.lineTo( x, y ); // Calculate the velocity variables for the ball body to use in launchBall. launchVelocity.x = ( ball.x - x ) * 5; launchVelocity.y = ( ball.y - y ) * 5; // Make the line narrower. trajectoryGraphics.lineStyle( 1, '0xCCCCCC' ); // Lets make 11 segmented trajectory line. For every segment get the point and draw a small square. for( var i = 0; i < 15; i++ ) { var trajectoryPoint = this.getTrajectoryPoint( ball.x, ball.y, launchVelocity.x, launchVelocity.y, i ); trajectoryGraphics.drawRect( trajectoryPoint.x, trajectoryPoint.y, 2, 2 ); } } }, launchBall: function() { if( !isBallMoving ) { // Clear the graphics if the ball has been launched. trajectoryGraphics.clear(); // Set the ball velocity. ball.body.velocity.x = launchVelocity.x; ball.body.velocity.y = launchVelocity.y; // Flag the ball as moving. isBallMoving = true; // Set the ball physics to enabled. ball.body.data.gravityScale = 1; ball.body.data.collisionResponse = true; // Create a new ball after 4 seconds. this.time.events.add( Phaser.Timer.SECOND * 4, this.createNewBall, this ); } }, getTrajectoryPoint: function( startX, startY, velocityX, velocityY, n ) { var t = 1 / 60; var stepVelocityX = t * this.physics.p2.pxm(-velocityX); var stepVelocityY = t * this.physics.p2.pxm(-velocityY); var stepGravityX = t * t * this.physics.p2.pxm(-this.physics.p2.gravity.x); var stepGravityY = t * t * this.physics.p2.pxm(-this.physics.p2.gravity.y); startX = this.physics.p2.pxm(-startX); startY = this.physics.p2.pxm(-startY); var tpx = startX + n * stepVelocityX + 0.05 * (n * n * n) * stepGravityX; var tpy = startY + n * stepVelocityY + 0.05 * (n * n * n) * stepGravityY; tpx = this.physics.p2.mpx(-tpx); tpy = this.physics.p2.mpx(-tpy); return { x: tpx, y: tpy }; } The code is from Phaser Box2D physics example I think, but I am using the P2 physics system. It works. Kind of. The trajectory is wrong. I am absolutely not sure but I think it has got to do something with the ball physics body. I'd love it if you'd take a quick look and tell me if I'm doing something very wrong.
3. ## Is overriding hardware back button good practice?

I suppose it depends on the kind of app it is. My game is going to be a canvas on a webpage with other things as well and I don't want to confuse the user who is using the webpage.

5. ## Is overriding hardware back button good practice?

Hello. Is it good practice to override hardware back button on a mobile device if the game is a web game played from a web browser, not a native app? Seems like a wrong thing to change the default expected behavior of a browser app. Actually, is it even possible? Maybe it's not. Has anyone tried doing this kind of thing? (I was thinking of making a pause menu appear in a Snake game if I pressed the hardware back button on my phone or tablet)
6. ## Phaser.Graphics pixel counting

Those are bitmapdata objects public methods. How do I use'em on graphics object? Am I missing something?
7. ## Phaser.Graphics pixel counting

Is it possible to count the number of visible pixels that have been drawn on a graphics object? I know its possible on BitmapData object through ImageData.data array, but I can't find that sort of thing in the graphics object and I need to use the graphics for masking. I want to calculate the percentage of how much of a sprite has been painted over by the graphics.
8. ## Lawnmower concept

Alright alright alright. I think I figured something out. It doesn't like the drawCircle method. Or any other primitive shape that calculates corners I think. I used console.log to print out how many times I was able to call the drawCircle() method and turns out it crashes every time it reaches 799nth time. I have no idea why it does it like that but changing the method to drawRect() does not crash. I tried the other primitive shapes as well (ellipse, rounded rectangle) and same thing. This is the crashing circle version. This is the working rectangle version. At this point I'm done trying to draw circles. Rectangles are the way to go
9. ## Lawnmower concept

I attached two images. The green grass is a sprite with a mask applied to it. I draw the mask every time I move the mouse. But every time at some point it freaks out, some weird lines appear and it stops drawing the mask.