photonstorm/phaser — pull request #960 by Phaiax (2014-06-29 16:15:02+00:00)
Title: Return type of Phaser.Color.packPixel changed

Hey

I had a problem with BitmapData.replaceColor, it worked sometimes and sometimes not.

I figured out that the problem was the different representation of the pixel data types.

The Uint32Array pixel[] value is compared to the return value of a packPixel() call.
Phaser.Color.packPixel(0,0,0,255) = -16777216
The same bits interpreted as uint32 are 4278190080.
The color comparisation will fail even if the color is the same.

This example does not work for me also:
http://examples.phaser.io/_site/view_full.html?d=display&f=bitmapdata+replace+color.js&t=bitmapdata%20replace%20color

I used this hack from stackoverflow to directly fix the packPixel() function.
http://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32

The function Phaser.Color.toRGBA() still implements the "old" behaviour which can result in negative numbers.

Greetings
-- Phaiax