Skip to content

Instantly share code, notes, and snippets.

@McFunkypants
Created January 12, 2013 04:12
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 McFunkypants/4516029 to your computer and use it in GitHub Desktop.
Save McFunkypants/4516029 to your computer and use it in GitHub Desktop.
function redraw()
{
if (!spritesheetLoaded) return;
console.log('redrawing...');
var spriteNum = 0;
// clear the screen
ctx.fillStyle = '#000000';
ctx.fillRect(0, 0, canvas.width, canvas.height);
for (var x=0; x < worldWidth; x++)
{
for (var y=0; y < worldHeight; y++)
{
// choose a sprite to draw
switch(world[x][y])
{
case 1:
spriteNum = 1;
break;
default:
spriteNum = 0;
break;
}
// draw it
// ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);
ctx.drawImage(spritesheet,
spriteNum*tileWidth, 0,
tileWidth, tileHeight,
x*tileWidth, y*tileHeight,
tileWidth, tileHeight);
}
}
// draw the path
console.log('Current path length: '+currentPath.length);
for (rp=0; rp<currentPath.length; rp++)
{
switch(rp)
{
case 0:
spriteNum = 2; // start
break;
case currentPath.length-1:
spriteNum = 3; // end
break;
default:
spriteNum = 4; // path node
break;
}
ctx.drawImage(spritesheet,
spriteNum*tileWidth, 0,
tileWidth, tileHeight,
currentPath[rp][0]*tileWidth,
currentPath[rp][1]*tileHeight,
tileWidth, tileHeight);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment