gauravD

Members
  • Content count

    9
  • Joined

  • Last visited

  1. Text taking click without adding input

    The text objects accept input because they are added as the button's children: https://jsfiddle.net/2fet6pLf/ In your case, the hierarchy also seems a bit incorrect logically. The texts and the button should have a common parent (perhaps, call it a TextButton ). //TextButton pseudocode TextButton : Sprite { titleText: Phaser.Text //TOP_CENTER descText: Phaser.Text //CENTER button: Phaser.Button //BOTTOM_CENTER TextButton(){ this.addChild(titleText); this.addChild(button); this.addChild(descText); } }
  2. How to double jump with phaser ?

    @samme's answer should work just fine. Regardless, since jump1() and jump2() are equivalent, why not just use jump()?
  3. Quad like object in Phaser 2?

    Ha! https://gaurav-dixitv.github.io/phaser/2017/07/27/texture-repeat.html There you go. This shows you how to do exactly that (except you can ignore the texture code if you want to).
  4. how to destroy onBeginContact sprite body

    Try this.game.physics.p2.removeBodyNextStep( equation[0].bodyA ); and this.game.physics.p2.removeBodyNextStep( equation[0].bodyB );
  5. Quad like object in Phaser 2?

    Shameless plug: https://gaurav-dixitv.github.io/phaser/2017/06/08/phaser-shaders.html should help you use your own quads. But I am guessing this would be an overkill. What do you want to achieve?
  6. Relative values of vertices of polygon in sprite

    Vertices of a p2 polygon are relative to the center of the polygon. Supposed you wanted a 2x2 square, the vertices would be [ [-1, -1], [1, -1], [1, 1], [-1, 1] ] (CCW direction). When your sprite is at [100, 100], the first vertex would be at 100 + game.p2.mpx(-1) = 80. Where, game.p2.mpx() converts meters(p2 units) to px(Phaser units). If you scale the sprite, you need to take that into account as well. If you rotate a sprite and the p2 vertices stay the same, you can calculate them like so: function myFunction(){ //get rotated vertex[0] in screen coordinates. let p2x = sprite.x + game.p2.mpx(vertices[0][0]); let p2y = sprite.y + game.p2.mpx(vertices[0][1]); let transformedCoordinates = transformed(p2x, p2y, sprite.x, sprite.y, sprite.rotation); console.log("x0: "+transformedCoordinates[0]+ "y0: "+transformedCoordinates[1]); } function transformed(x: number, y: number, cx: number, cy: number, slope: number) { let nx = x - cx; let ny = y - cy; let tx = nx * Math.cos(slope) - ny * Math.sin(slope); let ty = nx * Math.sin(slope) + ny * Math.cos(slope); return [tx + cx, ty + cy] }
  7. Clear miniMap in update() - creating miniMap in online game

    By the looks of things, you seem to be doing drawnObject = game.add.sprite(270, game.height - 150, miniMap); every update? If that is true, you are creating a new sprite every frame = after some time, you will have way too many sprites. AFAIK, when you update your bitmapdata, the sprite also uses the updated texture. So you can safely remove all these lines drawnObject = game.add.sprite(270, game.height - 150, miniMap); //The sprite will use your updated texture drawnObject.anchor.setTo(0.5, 0.5); //You already set the anchor before (I reckon you were doing this every update because you were creating a new sprite :)) drawnObject.fixedToCamera = true; //Same as above; This is not needed This should help with the framerate. Typically, a call to clear() is also 'expensive', but I think you can get away with this.
  8. Shake Camera but don't shake UI

    Ideally, only the world should shake (and everything within it). All 'camera' transformations are applied to the world. So when you have a sprite in a huge world that the camera follows, the world translates/rotates, but the stage's transformation matrix remains unchanged - so any UI that goes on the stage will remain static. For some reason, the shake is applied to all display objects (the stage too). @rich Perhaps the `offsetVector uniform` can be removed and Camera's `update()` modified to account for `_shake.x` and `_shake.y` when you update `this.displayObject.position` with `this.view`? Or am I missing something?