Repeat a part of spritesheet as background

Posted by Moiblpadde on Game Development See other posts from Game Development or by Moiblpadde
Published on 2012-10-07T14:54:13Z Indexed on 2012/10/07 15:50 UTC
Read the original article Hit count: 269

Filed under:
|
|

So I'm trying to repeat a part of my spritesheet as a background (js, canvas).

My code so far:

var canvas = $("#board")[0],
    ctx = canvas.getContext("2d"),
    sprite = new Image();
    sprite.src = "spritesheet.png";
sprite.onload = function(){
    ctx.fillStyle = ctx.createPattern(spriteBg, "repeat");
    ctx.fillRect(0, 25, 500, 500);
}

This is fine, but as you can see, it repeat the whole sprite, not just a part of it, and I just can't figure out how to do it D:

© Game Development or respective owner

Related posts about JavaScript

Related posts about html5