sinanqd10 Posted July 19, 2016 Share Posted July 19, 2016 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.load('test'); 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.beginPath(); this.bmd.ctx.rect(0,0,50,50); this.bmd.ctx.fillStyle = color; this.bmd.ctx.fill(); this.sprite = this.game.add.sprite(x, y, this.bmd); }, pickColor: function(pointer, x, y) { console.log(this.bmd.getPixelRGB(x,y)); } Link to comment Share on other sites More sharing options...
TickleMeElmo Posted July 19, 2016 Share Posted July 19, 2016 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 More sharing options...
sinanqd10 Posted July 20, 2016 Author Share Posted July 20, 2016 @TickleMeElmo I want to pick color and paint to the png sprite. Link to comment Share on other sites More sharing options...
Recommended Posts