So I have an issue with Flash's Graphics class. Consider this code (I'm using Flixel):
public static function CreateSolid(dimensions:FlxPoint, color:uint): FlxSprite {
var sprite:FlxSprite = new FlxSprite();
sprite.makeGraphic(dimensions.x, dimensions.y, 0xffffffff);
var gfx:Graphics = FlxG.flashGfx;
gfx.clear();
gfx.beginFill(color, 1);
gfx.drawRect(0, 0, sprite.frameWidth, sprite.frameHeight);
gfx.endFill();
sprite.pixels.draw(FlxG.flashGfxSprite);
sprite.dirty = true;
return sprite;
}
All the code does is return a new FlxSprite object that is solidly colored according the the input argument. This of course isn't the best way to do it, it's just simplified from another piece of code I have.
If I use this method to create a solid red 50x50 square, it works fine:
a = CreateSolid(new FlxPoint(50, 50), 0xff0000);
//draw a
Now, if I create two squares side by side, one red and one green, in this order:
a = CreateSolid(new FlxPoint(50, 50), 0xff0000);
b = CreateSolid(new FlxPoint(50, 50), 0x00ff00);
b.x += 50
//draw a & b
You'd expect the two boxes to be colored correctly. However, to me, they are both green. This was strange to me. Even stranger: if I make one square a different size (even by a little bit):
a = CreateSolid(new FlxPoint(50, 50), 0xff0000);
b = CreateSolid(new FlxPoint(51, 50), 0x00ff00);
b.x += 50
//draw a & b
The colors are drawn correctly. Is there an explanation to this? And how do I color them correctly?
Thanks!