It seems to be ctx2.canvas.width, not ctx.width. Fixed missing } at end of simple battle.js