ogramp

Members
  • Content Count

    13
  • Joined

  • Last visited

  1. ogramp

    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. 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. 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.
  4. And the correct answer is: "It is bad practice to mess with the hardware BACK button on mobile devices in Phaser games". Thank you all for participating in this survey and please help yourself yourself to a nice gift basket on your way out. But in all seriousness, I did some more reading and agree with mattstyles, it's not a good idea, messing with the back button on mobile devices. Even if it is possible. And VitaZheltyakov, I think windows phone (i don't have other, don't judge!) is the same way. Tnx for thinking along!
  5. 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. ogramp

    Phaser.Graphics pixel counting

    Those are bitmapdata objects public methods. How do I use'em on graphics object? Am I missing something?
  7. ogramp

    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. ogramp

    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. ogramp

    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.
  10. ogramp

    Lawnmower concept

    var game = new Phaser.Game(500, 375, Phaser.AUTO, 'phaser-example', { preload: preload, create: create }); var sprite; var mask; function preload() { game.load.image('shortgrass', 'assets/img/grass.jpg'); } function create() { shortgrass = game.add.sprite(0, 0, 'shortgrass'); mask = game.add.graphics(0, 0); mask.beginFill(0x000000); mask.drawCircle(0, 0, 1); shortgrass.mask = mask; game.input.addMoveCallback(move, this); } function move(pointer, x, y) { mask.drawCircle(x, y, 50); } So I tried this masking thing, and it almost works as I want to. For some reason it works only for some time and then turns weird. I suspect it might be because I draw to mask every move of the cursor and maybe that is too much? It's weird because all I actually do is paint mask graphic and through that I expose the sprite of shortgrass. Why would it stop working mid drawing? Can someone see something totally wrong here?
  11. Top-down lawnmower driving around in a yard with flowers. I'm checking collisions between flowers and the lawnmower. Problem is when I'm driving the lawnmower at a 45 degree angle past a flower (sprites do not overlap) the game cuts the flower down. I t tried troubleshooting and the debug.body(flower) and game.debug.body(lawnmower) show my their Bounds boxes (they overlap) and from there comes my question. Why doesn't the bounding box rotate when I change the sprite angle? I've tried looking for ways to change the angle but game.debug.body(lawnmower).angle does nothing. EDIT: I think I found the answer myself. From Phaser.io API docsumentation: ... the collision Body itself never rotates, it is always axis-aligned ...
  12. ogramp

    Lawnmower concept

    I've thought of that. I was unable to generate the "mowed" mask at run time. But I'm smarter than I was yesterday. I'll try again!
  13. ogramp

    Lawnmower concept

    (PS, I'm new to Phaser, so this might as well be a dumb question but I'm still asking ) I am trying to create a lawnmower game with Phaser where you basically drive around top-down view and cut grass. I got something working and at the moment I use bitmap data object to paint a circle of light green color (short grass) on top of the background color that is supposed to be the tall grass. Now the problem is that grass is not just a solid green colored area. It needs texture. Putting texture on the background seems easy and tall grass is then textured. But running around and painting with bitmap data object I don't see a way to do so that it would leave a texture as a trail. Does anyone have a good idea how to do it or something they can point me to.