Jump to content

BitmapData Pick color and paint


Recommended Posts

Hi guys,

Could anyone kindly shows me a little bit of code about pick and paint color to the sprite?

here is my code that I have played around, but I still cannot find out and achieve it. 

Thanks you in advance for your time and consideration.

        preload: function() {
		this.game.load.image('test', 'test.png');
	create: function() {
		this.color1 = this.drawRec('rgb(141,243,160)', 20, 20);
		this.color2 = this.drawRec('#6bd4e0', 100, 20);
		this.color3 = this.drawRec('#cb6be0', 20, 100);
		this.color4 = this.drawRec('#8df3a0', 100, 100);
		this.square = this.game.make.bitmapData();
		this.square.addToWorld(this.game.world.centerX, this.game.world.centerY, 0.5, 0.5);		
		this.game.input.onDown.add(this.pickColor, this);
	drawRec: function(color, x, y) {
		this.bmd = this.game.make.bitmapData(100, 100);
		this.bmd.ctx.fillStyle = color;
		this.sprite = this.game.add.sprite(x, y, this.bmd);		
	pickColor: function(pointer, x, y) {



Link to comment
Share on other sites

Don't really understand what you want to do, but maybe something like this will help


var pickedColor = {r:0, g:0, b:0}

function pickColor(pointer, x, y) {

   var color =  this.bmd.getPixelRGB(x,y) ;

   pickedColor.r = color.r;

   pickedColor.g = color.g;

   pickedColor.b = color.b;


function onClick(x, y) {

    var pixel = this.bmd.getPixel(x, y);

    pixel.r = pickedColor.r;

    pixel.g = pickedColor.g;

    pixel.b = pickedColor.b;



Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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