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

javascript - Is it possible to create a PIXI.Texture from multiple image sources in pixi.js? - Stack Overflow

programmeradmin3浏览0评论

I have about 10 different image files that I need to dynamically load into one PIXI.Texture object. Is that a possibility with pixi.js? Think of a slot machine reel; I have each individual slot symbol as an image and need to construct a reel strip texture from those images.

Thank you in advance.

I have about 10 different image files that I need to dynamically load into one PIXI.Texture object. Is that a possibility with pixi.js? Think of a slot machine reel; I have each individual slot symbol as an image and need to construct a reel strip texture from those images.

Thank you in advance.

Share Improve this question asked Nov 21, 2016 at 14:42 hanesjwhanesjw 2,5944 gold badges27 silver badges38 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Yes, you can use a RenderTexture for this. You need to create each of your image sprites first and add them to a container. Then you can render that container into a texture, which you can then re-use throughout your application.

var stage = new PIXI.Container();

//Create the sprites and add them into a container.
//I'm using 10 images at 200 x 200px each.
var reel = new PIXI.Container();
for(var i=0; i<10; i++)
{    
    var img = PIXI.Sprite.fromImage('img' + i + '.png');
    img.y = 200 * i;
    reel.addChild(img);
}

//Create a Texture that will render each of the reels
var texture = new PIXI.RenderTexture(
        new PIXI.BaseRenderTexture(200, 2000, PIXI.SCALE_MODES.LINEAR, 1)
);

//Add some new sprites using the texture
for(var i=0; i<5; i++)
{
    var s = new PIXI.Sprite(texture);
    s.x = 200 * i;
    stage.addChild(s);
}

animate();
function animate()
{
    //Render the texture
    renderer.render(reel, texture);

    //Render the stage
    renderer.render(stage);
    requestAnimationFrame(animate);
}
发布评论

评论列表(0)

  1. 暂无评论