Jump to content

Stephen Persson

Members
  • Content Count

    12
  • Joined

  • Last visited

Posts posted by Stephen Persson

  1. BitmapData has a setPixel method, or "setPixel32" if you need alpha values.

    It would require you to parse that string, though, since it takes the rgb values separately as numbers.

    It works, but I tried on a 640x480 image and it was prohibitively slow until it crashed.

    This is what I did:

    var image = [[[0, 0, 0], [0, 0, 0], [255, 255, 255], ..., [255, 255, 255], [255, 255, 255], [255, 255, 255]]];var bmd = game.make.bitmapData(game.width, game.height);for (var x = 0; x < image.length; x++) {  for (var y = 0; y < image[x].length; y++) {    bmd.setPixel(x, y, image[y][x][0], image[y][x][1], image[y][x][2]);  }}bmd.addToWorld();

    setPixel uses putImageData. Is this ok?

  2. What's the right way to draw an image pixel by pixel with bitmapdata?

    Assuming I'm getting the data from a matrix.

    var image = [['rgb(  0,  0,  0)', 'rgb(  0,  0,  0)', 'rgb(255,255,255)', 'rgb(  0,  0,  0)', 'rgb(  0,  0,  0)'],             ['rgb(  0,  0,  0)', 'rgb(  0,  0,  0)', 'rgb(255,255,255)', 'rgb(  0,  0,  0)', 'rgb(  0,  0,  0)'],             ['rgb(  0,  0,  0)', 'rgb(255,255,255)', 'rgb(255,255,255)', 'rgb(255,255,255)', 'rgb(  0,  0,  0)'],             ['rgb(  0,  0,  0)', 'rgb(255,255,255)', 'rgb(255,255,255)', 'rgb(255,255,255)', 'rgb(  0,  0,  0)'],             ['rgb(255,255,255)', 'rgb(255,255,255)', 'rgb(255,255,255)', 'rgb(255,255,255)', 'rgb(255,255,255)']];var bmd = game.make.bitmapData(game.width, game.height);for (var x = 0; x < image.length; x++) {  for (var y = 0; y < image[x].length; y++) {    bmd.??????????  }}bmd.addToWorld();
  3. I'm using Phaser 2.3.0 and I want to know the bounds of a rotated sprite.

    But when I change sprite.rotation, the values of sprite.getBounds() don't change:

    var sprite = game.add.sprite(0, 0, "sprite"); // game.load.spritesheet("sprite", "spritesheet.png", 32, 32);console.log(sprite.getBounds()); // Object { x: 0, y: 0, width: 32, height: 32, type: 22 }sprite.rotation = 0.52; // 30°console.log(sprite.getBounds()); // Object { x: 0, y: 0, width: 32, height: 32, type: 22 }
    What's wrong?

    How can I get the correct bounds?

  4. get the original image from the cache with getImage:

    var image = game.cache.getImage('imageKey'); 
    From there you can access all its original properties:

    var height = image.height; 
    Not sure if that's what you're looking for. If you apply transformations to it then yes, you'd have to do calculations to determine the width/height of what is visible on the screen.

     

     

    It seems "real" was too vague. I don't want original data, I want the data from the visual result, after the changes.

    I edited that word and moved my explanation to the first post.

  5. Yes, you can.

    I didn't find out how to skew a sprite, do you have an example?

     

    sprite.width will always give you the sprite's width in screen pixels. If you want to know the sprite's original dimensions, you can use sprite.width * sprite.scale.x and sprite.height * sprite.scale.y

    But negative scaling will screw it.

  6. I'd like to get the visual x/y/width/height of a sprite after scaling/skewing/rotating/anchoring it.
    Can I do that with Phaser?

    The case:

    If you flip horizontally a sprite that has {x: 100, y: 100, width: 64, height: 64},
    what will your eyes see on the screen? {x: 36, y: 100, width: 64, height: 64}. That's what I'm looking for.
    However, Phaser tells you:{x: 100, y: 100, width: -64, height: 64}.

    No big deal, you just do a little math to fix it, kinda like you showed there.
    That is, if you only scale it.

    It gets more mathematical when you also change the anchor, and turns into a geometric nightmare if you rotate it too.

    Phaser is heavily based on Flixel, right?
    Then my hopes are that you could do it like in Flash, where you can solve all of this by wrapping your sprite into a movieclip and getting the container's x/y/width/height.

  7. I want a sprite always in the front. Setting z to max didn't do it.

    game.add.sprite(0, 0, "bg");

     

    var front = game.add.sprite(0, 0, "front");

    front.z = Math.pow(2, 53);

     

    game.add.sprite(300, 200, "object1");

    game.add.sprite(500, 400, "object2");

    What is needed?

×
×
  • Create New...