xyrix Posted December 11, 2013 Share Posted December 11, 2013 Hi, I have code along the lines of: bmd = game.add.bitmapData(100, 100);bmd.fillColor(0xFFFFFF);bmd.rect(0, 0, 100, 100); sprite = game.add.sprite(0, 0, bmd); I expect to see from this a white rectangle in the top left of my screen, but do not :-/. The documentation states that BitmapData as a class is experimental and subject to change, and the bitmap wobble demo does not work on either of my browsers (Chromium and Firefox latest versions for Linux). I'm wondering where the problem lies - do I have the incorrect idea for using this part of the API?Thanks in advance for any help :-). Link to comment Share on other sites More sharing options...
rich Posted December 11, 2013 Share Posted December 11, 2013 Try '#ffffff' for the colour value. Link to comment Share on other sites More sharing options...
xyrix Posted December 11, 2013 Author Share Posted December 11, 2013 Hi, Thanks for the fast reply!I looked back at the API and found the function I used was called "fillStyle" not "fillColor", so that was wrong, too. I've now tried changing it to: var bmd = game.add.bitmapData(100, 100);bmd.fillStyle('#ffffff');bmd.rect(0, 0, 100, 100);sprite = game.add.sprite(0, 0, bmd); Still, though, nothing gets drawn. In case it's of any use, here is a version of the full code I expect to draw a rectangle but that does not: var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { create: create });function create() { var bmd = game.add.bitmapData(100, 100); bmd.fillStyle('#ffffff'); bmd.rect(0, 0, 100, 100); sprite = game.add.sprite(0, 0, bmd);} Hopefully there is something obvious I've overlooked . Link to comment Share on other sites More sharing options...
rich Posted December 11, 2013 Share Posted December 11, 2013 It probably just doesn't work yet You can always do it directly on the context:bmd.context.fillStyle = '#fff';bmd.context.fillRect(0,0,100,100);That will definitely work. Link to comment Share on other sites More sharing options...
xyrix Posted December 11, 2013 Author Share Posted December 11, 2013 Excellent! Yes, that does work perfectly :-) - thankyou!What exactly is the context? Will this work with both Canvas and WebGL? I don't think suppose that matters much - I'm just curious. Link to comment Share on other sites More sharing options...
rich Posted December 11, 2013 Share Posted December 11, 2013 It's the canvas that the bitmapData is using. Yes it'll work on WebGL if you update the bmd after drawing on it. Link to comment Share on other sites More sharing options...
xyrix Posted December 11, 2013 Author Share Posted December 11, 2013 if you update the bmd after drawing on it.I'm sorry - I don't know what that means :-/. Link to comment Share on other sites More sharing options...
Recommended Posts