HTML and CSS Reference
In-Depth Information
Listing 8-33. paintPixels() Function
function paintPixels(newColour, pixels) {
var i = 0;
for ( ; i < pixels.length ; ++i ) {
ctx.fillStyle = '#' + newColour;
As you can see, the paintPixels() function accepts two arguments, the first one with the new color, and the
second one with the array of pixels that need to be repainted. All you need to do now is to cycle the new order and call
the function, as shown in Listing 8-34.
Listing 8-34. Calling the paintPixels() Function
for ( ; i < currentColourOrder.length ; ++i ) {
paintPixels(currentColourOrder[i], pixelGroups[colourIndexes[i]]);
This entire example can be found within the chapter folder.
In this chapter, I've only covered a handful of the performance-improvement techniques used in old-school video
games. It was my intention not only to share some of these things with the readers of this topic, but, as an author, also
to inspire you to think outside the box when you believe that something can't be done.
Search WWH ::

Custom Search