Jump to content

BitmapData setPixel() some times results in black pixels?


Raicuparta
 Share

Recommended Posts

I'm making some BitmapData squares, and painting each individual pixel randomly, like this. It works like 90% of the time, but for some reason, some times, it generates something like this.

The code that generates the BMD:

  generatePattern (size) {
    let pattern = this.game.make.bitmapData(size, size)
    for (let x = 0; x < size; x++) {
      for (let y = 0; y < size; y++) {
        let color = this.randomColor()
        pattern.setPixel(x, y, color.r, color.g, color.b, true)
      }
    }
    return pattern
  }

I then use the generated BMD as textures for my sprites with Phaser.Sprite.loadTexture()

I know it's not a problem with the way I'm generating the color, since even if I try to just set the RGB values to 255 255 255 (skipping my randomColor function), the problem persists. So it seems to be something related to the setPixel function.

Using Phaser CE 2.8.0

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...