Jump to content

Responsive Background Cover Tiling Sprite


Camila S
 Share

Recommended Posts

Hi, I'm trying to make a responsive game that suits mobile devices and desktops, but I'm not being able to figure out the background.

Here's what I have at the moment:

 

// other stuff ...

function initLevel() {  

    bgBack = createTilingAsset(app.loader.resources["bgBack"].texture, window.innerWidth, window.innerHeight);
    bgMiddle = createTilingAsset(app.loader.resources["bgMiddle"].texture, window.innerWidth, window.innerHeight);
    bgFront = createTilingAsset(app.loader.resources["bgFront"].texture, window.innerWidth, window.innerHeight);                                        
                    
    app.ticker.add(gameLoop);
}

function createTilingAsset(texture, width, height) {

    let ratio = Math.max(width / texture.width, height / texture.height);
    width = texture.width * ratio;
    height = texture.height * ratio;   

    let tiling = new PIXI.TilingSprite(texture, width, height);                    
    app.stage.addChild(tiling);

    return tiling;
}

//more stuff...


And the result is attached in here.

Does anyone know how can I make the background cover the entire screen in a way it doesn't repeat in the Y?

Captura de Tela 2020-06-23 às 15.35.37.png

Link to comment
Share on other sites

If you know how WebGL works (went through webglfundamentals), you can read source of pixi textures ( https://github.com/pixijs/pixi.js/tree/dev/packages/core/src/textures , https://pixijs.io/examples/#/textures/gradient-resource.js , https://github.com/pixijs/pixi.js/blob/dev/packages/core/src/textures/TextureSystem.ts#L385 ) , make custom texture resource with "style" that uploads different wraps by U and V, first REPEAR, second CLAMP.

Alternatively, use several sprites instead of TilingSprite.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...