1 decade ago by Silent
Hi :)
I'm trying to make a plugin that will allow me to recolor fonts and images on the fly, so I can do cool stuff such as colored fonts and glowing NPCs.
Right now I'm just trying to see if I can apply a simple effect on the image, just like in this tutorial -
http://www.html5canvastutorials.com/advanced/html5-canvas-invert-image-colors-tutorial/
The problem is that I can't figure out how to properly clone the image to a new canvas. What I want is to basically make a copy of the original image, apply my effect, and draw the clone(so the original remains untouched).
Here is some modded font.js code:
As a result, instead of characters I get weird symbols that resemble the original characters a little bit. Please help me solve this.
Thanks in advance :D
I'm trying to make a plugin that will allow me to recolor fonts and images on the fly, so I can do cool stuff such as colored fonts and glowing NPCs.
Right now I'm just trying to see if I can apply a simple effect on the image, just like in this tutorial -
http://www.html5canvastutorials.com/advanced/html5-canvas-invert-image-colors-tutorial/
The problem is that I can't figure out how to properly clone the image to a new canvas. What I want is to basically make a copy of the original image, apply my effect, and draw the clone(so the original remains untouched).
Here is some modded font.js code:
_drawChar: function( c, targetX, targetY ) { if( !this.loaded || c < 0 || c >= this.indices.length ) { return 0; } var scale = ig.system.scale; var charX = this.indices[c] * scale; var charY = 0; var charWidth = this.widthMap[c] * scale; var charHeight = (this.height-2) * scale; var colored = ig.$new('canvas'); var coloredCtx = colored.getContext('2d'); var coloredData = coloredCtx.getImageData( 0, 0, this.width, this.height ); var thisData = ig.getImagePixels( this.data, 0, 0, this.width, this.height ); coloredCtx.putImageData(thisData, 0, 0); ig.system.context.drawImage( //this.data, colored, charX, charY, charWidth, charHeight, ig.system.getDrawPos(targetX), ig.system.getDrawPos(targetY), charWidth, charHeight ); return this.widthMap[c] + this.letterSpacing; }
As a result, instead of characters I get weird symbols that resemble the original characters a little bit. Please help me solve this.
Thanks in advance :D