fazz

Members
  • Content Count

    10
  • Joined

  • Last visited

About fazz

  • Rank
    Member

Contact Methods

  • Twitter
    Roh_Foh

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. fazz

    Phaser 3 texture getPixels (plural)

    Thanks @Milton, @rich. It wasn't quite as trivial as I'd hoped, so I've probably gone around the houses with my solution. In case anyone's interested, I added the following method to the TextureManager to provide getPixels functionality. /** * Given a Texture this method will return an Object containing w, h and Uint8ClampedArray * of pixel data at the location in the Texture. * * @param {string} key - The unique string-based key of the Texture. * @param {(string|integer)} frame - The string or index of the Frame. * * @return An object populated with the w, h and Uint8ClampedArray of pixel values of the requested texture * or `null` if not found were out of bounds. */ game.textures.getPixelsData = function(key, frame) { let textureFrame = this.getFrame(key, frame); if (textureFrame) { let w = textureFrame.width; let h = textureFrame.height; // have to create new as _tempCanvas is only 1x1 let cnv = this.createCanvas('temp', w, h); // CONST.CANVAS, true); let ctx = cnv.getContext('2d'); ctx.clearRect(0, 0, w, h); ctx.drawImage(textureFrame.source.image, 0, 0, w, h, 0, 0, w, h); // cnv.destroy(); let rv = ctx.getImageData(0, 0, w, h); // add handy little method for converting specific pixel to Color object rv.getColorAt = function(x, y) { return new Phaser.Display.Color( this.data[(x+y*this.width)*4], this.data[(x+y*this.width)*4+1], this.data[(x+y*this.width)*4+2], this.data[(x+y*this.width)*4+3] ); }; return rv; } return null; }; And it can be used in the following way. // get all pixel data for cached image let data = this.textures.getPixelsData('myImage'); // get colour of pixel at x = 3, y = 2 let col = data.getColorAt(3, 2) This is significantly faster than repeatedly calling this.textures.getPixel(3, 2, 'myImage') but I'm sure it could be optimised further. Thanks for the help!
  2. fazz

    Clicks on Object and Background

    I don't think you're testing input on the cookie correctly, you're passing *this* instead of *this.cookie* to your handler method. Try this instead, this.cookie = this.physics.add.sprite(400, 400, "cookie"); this.cookie.setInteractive(); this.cookie.on('pointerup', function() { // do something to the cookie this.doSomething(); }, this.cookie);
  3. Hi all, I have been unable to find a method to get all the pixel data from a cached image / texture in Phaser 3. Is anyone aware of a way? I am aware of the textures.getPixel method https://photonstorm.github.io/phaser3-docs/Phaser.Textures.TextureManager.html#getPixel__anchor but this is only a single pixel method, is incredibly inefficient / slow when iterating across a whole image. There were a number of ways to get all the image pixel data in Phaser 2 in one go; you could use getPixels from a renderTexture or a bitmapData.context. There is no such method in Phaser3 renderTexture, and there is no bitmapData any more. Any help will be greatly appreciated! Thanks
  4. fazz

    Ways to debug low FPS of my game

    You'll need to look at a wider area than that, and make sure you're covering the part of the game that runs slowly in your mobile browser. Then expand some of those functions (see the little grey arrow next to Gecko), looks at what methods are being called, and then look at your code to see why it might be running slowly. Optimisation is an open ended problem. Without seeing your code it is quite difficult to offer any advice.
  5. fazz

    Ways to debug low FPS of my game

    That's pretty normal. Even a top spec mobile is going to struggle against an average PC. I mainly use FF, but Chrome definitely has a performance tool. Just run it on desktop, see what methods top your flame chart / call tree, and optimise those. In FF it gives you a handy percentage total performance cost for each function over the selected period. They might not be the exact issue with your mobile performance but they might be a good indicator.
  6. You're game is topdown so you'd need friction to work in the Z direction, not X and Y. Without seeing your code it's hard to tell, but depending on what Physics you're using you might be able to use setFrictionAir to slow your cars down. Player1.setFrictionAir(1); Failing that you might have to roll your own Z friction.
  7. fazz

    Question about asset loading

    I believe you need to load the assets when the scene starts. You can create objects whenever you like, but the assets need to be loaded first. If you want to load the same scene with different assets, you could pass data to the scene when you start it, and use that data to define which assets to load. An example of passing data to a scene can be found here https://labs.phaser.io/edit.html?src=src\scenes\passing data to a scene.js
  8. fazz

    Load from URL

    Hi, Might this help https://github.com/samme/phaser3-faq/wiki#how-do-i-load-cross-origin-assets
  9. Hi, I think I've found an issue with the normal map spot light. Either that or I've done something daft in my code. I believe the spot light system correctly selects which pixels to illuminate, but it doesn't consider the sprite's rotation, only the pixel normal value, when calculating per pixel lightness. This only becomes apparent when a sprite is rotated, and it is difficult to demonstrate when using very flat normal maps, like in this spot light demo http://labs.phaser.io/view.html?src=src\game objects\lights\spotlight.js You can see my below code snippet running here https://madcarrot.itch.io/phaser3-demo?secret=70SZ1Whbm3Wsf9onEXXdRM2deQ If you position the spot light (attached to pointer) behind the insect to highlight the abdomen, when the insect is facing downward, the light angle is correct, when the insect is facing upward, the light angle is 180 degs off. var config = { type: Phaser.AUTO, width: 800, height: 600, scene: { preload: preload, create: create, update: update } }; var game = new Phaser.Game(config); var insect; function preload () { this.load.image('insect', [ 'assets/images/bug-99x103.png', 'assets/images/bug-nm-99x103.png' ]); } function create () { this.lights.enable().setAmbientColor(0x333333); insect = this.add.image(400, 300, 'insect').setOrigin(0.5).setScale(3); insect.setPipeline('Light2D'); var light = this.lights.addLight(180, 80, 200).setColor(0xffffff).setIntensity(2); this.input.on('pointermove', function (pointer) { light.x = pointer.x; light.y = pointer.y; }); } function update() { insect.angle += 0.5; } Can anyone see if I've done anything daft here? Or whether this is worth raising as a bug? Thanks in advance
  10. fazz

    Sphere rotation

    Apologies for the necropost. I've been adapting your http://phaser.io/sandbox/kQxhfHbb for a project of mine. I wanted to slow the movement of the bitmapData object. In the update function there is the code, earthBMD.move(-1,0); If I adjust that to -0.1 the image blurs. It seems that http://phaser.io/docs/2.6.2/Phaser.BitmapData.html#move only operates correctly with integer values. Can anyone recommend a workaround for this? I can slow the movement by only calling the above code a few times a second, rather than every frame, and although this does slow the movement, it produces quite a noticeable stutter. Thanks in advance!