Jump to content

How I can simulate css property 'background-size: cover'?


Recommended Posts

I make a sprite with large texture (1920x1080) in the scene with size 1200x900, set anchor 0.5 and set position to center of the scene.

Of course part of the sprite go out from scene.


How I can repeat css property 'background-size: cover' or see fig.2 on the screen?

Do i need make special calculations or this feature already sold in pixijs?


My code:

// set object width big texturevar texture = PIXI.Texture.fromImage('/images/bg__main-scene.jpg');		var stageItemBackground = new PIXI.Sprite(texture);stageItemBackground.anchor.x = 0.5;stageItemBackground.anchor.y = 0.5;stageItemBackground.position.x = screenWidth/2;stageItemBackground.position.y = screenHeight/2;// set scenerenderer = PIXI.autoDetectRenderer(screenWidth, screenHeight, {backgroundColor: 0x000});document.getElementById('scene').appendChild(renderer.view);stage = new PIXI.Container();


Link to comment
Share on other sites

Am I right that all exterior is static? If so, do it in DOM :)

I made it in https://github.com/ivanpopelyshev/railways/

That's the code: https://github.com/ivanpopelyshev/railways/blob/master/src/ui/canvasContainer.js

DOM is good decision, but I need animate this. Because I collect elements of scene in JS. Do I right what pixijs can not control DOM? And I should use addChild?
Link to comment
Share on other sites

Pixi is a canvas rendering library, so it does not manipulate any DOM.

CSS can support a wide range of animations, transforms and transitions so still might be the best option for you.

You right, response layout best making in html5. Pixi better working with static size elements as I can understand

Link to comment
Share on other sites

  • 10 months later...

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.

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.


  • Recently Browsing   0 members

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