onlyslightly Posted January 27, 2020 Share Posted January 27, 2020 Ultimately I want to have a canvas that fills the entire viewport width of the browser and have an image on the canvas fill the entire width of that canvas. I'm taking advantage of pixi.js's displacement filter so that I can create a pseudo 3d effect using a depth map underneath it. The code I'm currently using is let app = new PIXI.Application(); var w = window.innerWidth; var h = w / ratio; app.view.style.width = w + 'px'; app.view.style.height = h + 'px'; document.body.appendChild(app.view); let img = new PIXI.Sprite.from("images/horses.png"); img.width = w; img.height = h; app.stage.addChild(img); depthMap = new PIXI.Sprite.from("images/horses-depth.png"); depthMap.renderable = false; depthMap.width = img.width; depthMap.height = img.height; img.addChild(depthMap); app.stage.addChild(depthMap); displacementFilter = new PIXI.filters.DisplacementFilter(depthMap, 0); app.stage.filters = [displacementFilter]; Attached is a screenshot I even tried manually setting the width to the viewport pixel width on the canvas and the sprite to the actual pixel width of the viewport width and it still wasn't the right size. Manually setting the width for the viewport and sprite to the exact same number also doesn't work; the sprite is inexplicably smaller than the canvas. I tried to look at the documentation of the sprite class and see if there is something unusual about how sprites handle widths but I couldn't find anything https://pixijs.download/dev/docs/PIXI.Sprite.html How can I create a pixi.js sprite that fills the entire width of the canvas in order to make both the canvas and the sprite fill the entire viewport width? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.