最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - KineticJS - Any way to repeat images? - Stack Overflow

programmeradmin2浏览0评论

I've switched over to kineticJS and I'm trying to have a background image repeat itself. Here is the code I am using:

var background_image = new Image();
background_image.onload = function() {
    var image = new Kinetic.Image({
        image: background_image,
        width: this.width,
        height: this.height
    });
    mainLayer.add(image);
    stage.add(mainLayer); // now mainLayer is available
};

Now what I'd like to do is essentially what this tutorial does: / :

That tutorial makes use of the canvas/context objects to repeat the image. I couldn't find an image repeat in the docs, so I was wondering if maybe I could access the main context element of my stage (or layer?) and then use that similar to the tutorial.

I've switched over to kineticJS and I'm trying to have a background image repeat itself. Here is the code I am using:

var background_image = new Image();
background_image.onload = function() {
    var image = new Kinetic.Image({
        image: background_image,
        width: this.width,
        height: this.height
    });
    mainLayer.add(image);
    stage.add(mainLayer); // now mainLayer is available
};

Now what I'd like to do is essentially what this tutorial does: http://www.html5canvastutorials./tutorials/html5-canvas-patterns-tutorial/ :

That tutorial makes use of the canvas/context objects to repeat the image. I couldn't find an image repeat in the docs, so I was wondering if maybe I could access the main context element of my stage (or layer?) and then use that similar to the tutorial.

Share Improve this question edited Feb 18, 2014 at 16:23 VividD 10.5k8 gold badges66 silver badges112 bronze badges asked Jun 21, 2012 at 3:42 JDSJDS 17k47 gold badges171 silver badges234 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 8

Try using a Rect with an image fill. Image fills are repeated by default. Here's an example:

http://www.html5canvastutorials./kineticjs/html5-canvas-set-fill-with-kineticjs/

You can also change the pattern repeat type, use offsets, and scale the pattern image

Cheers!

发布评论

评论列表(0)

  1. 暂无评论