Skip to main content
deleted 5 characters in body; edited title
Source Link
user1430
user1430

Repeat How can I repeat only a partportion of spritesheet as backgroundan image in Javascript?

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

My code so So far, I have attempted this:

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 asAs you can see, it repeat the whole spriteimage, not just a part of it, and I just can't figure out how to do it D:that last part.

Repeat a part of spritesheet as background

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:

How can I repeat only a portion of an image in Javascript?

So I'm trying to repeat a portion of my spritesheet as a background. So far, I have attempted this:

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);
}

As you can see, it repeat the whole image, not just a part of it, and I just can't figure out how to do that last part.

Source Link

Repeat a part of spritesheet as background

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: