Note that there are some explanatory texts on larger screens.

plurals
  1. POcoloring with colormatrix in AS3 - please help!
    text
    copied!<p>I got a huge problem trying to color objects that are flying around in my space game.</p> <p>When I shoot and hit them - the affected enemies shall blink. The graphics are pre-rendered (i.e. there's an rotation array and function where the degrees and their appropriate rotation for the objects are stored / calculated for better performance).</p> <p>So - my idea was to enhance that rotation function with a functionality for additional coloring; but the colored AND rotated objects shall be stored apart of the normal rotated objects. To accomplish this I made a nested array: in row one there are 360 rotated graphics of one object and in row two there are 360 graphics of a rotated and colored object.</p> <p>Problem: Coloring works but they are not rotated (always at 0 degrees). Please help me - I was figuring out for hours why it doesn't work so I gave up. It would be so cool if someone could find the problem! Thank you very much!</p> <pre><code>public function createRotationWithColorBlitArrayFromBD(sourceBitmapData:BitmapData, inc:int, offset:int = 0):Array { trace("sourceBitmapData.width=" + sourceBitmapData.width); trace("sourceBitmapData.height=" + sourceBitmapData.height); tileList = []; tileListSec = []; levelArray = []; var rotation:int = offset; while (rotation &lt; (360 + offset)) { var angleInRadians:Number = Math.PI * 2 * (rotation / 360); var rotationMatrix:Matrix = new Matrix(); rotationMatrix.translate(-sourceBitmapData.width * .5, -sourceBitmapData.height * .5); rotationMatrix.rotate(angleInRadians); rotationMatrix.translate(sourceBitmapData.width * .5, sourceBitmapData.height * .5); var matrixImage:BitmapData = new BitmapData(sourceBitmapData.width, sourceBitmapData.height, true, 0x00000000); matrixImage.draw(sourceBitmapData, rotationMatrix); tileList.push(matrixImage.clone()); var colorMatrix:ColorMatrixFilter = new ColorMatrixFilter ( [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0]); matrixImage.applyFilter(sourceBitmapData, sourceBitmapData.rect, point0, colorMatrix); tileListSec.push(matrixImage.clone()); rotation += inc; matrixImage.dispose(); matrixImage = null; rotationMatrix = null; } levelArray = [tileList, tileListSec]; return(levelArray); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload