Skip to content

Instantly share code, notes, and snippets.

@geoffb
Created August 14, 2010 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geoffb/523975 to your computer and use it in GitHub Desktop.
Save geoffb/523975 to your computer and use it in GitHub Desktop.
A simple example of changing the alpha of a sprite.
ctx.save();
// 50% opacity
// Anything drawn after this call (but before call .restore) will be drawn at 50% opacity
ctx.globalAlpha = 0.5;
ctx.drawImage(
spriteSourceImage,
sourceX, sourceY, sourceWidth, sourceHeight,
destX, destY, destWidth, destHeight
);
ctx.restore();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment