javascript - Pixi.js Retina display canvas is doubled in size - Stack Overflow

I am having some issues getting pixi.js 2.+ to work with retina displays.scale = window.devicePixelRati

I am having some issues getting pixi.js 2.+ to work with retina displays.

scale = window.devicePixelRatio
width = 960
height = 500

renderer = new (PIXI.CanvasRenderer)(width, height,{resolution:scale})
stage = new PIXI.Stage(0xFFFFFF)    

if scale is 2
    bgImg = '[email protected]'
else
    bgImg = 'img.png'
background = PIXI.Sprite.fromImage bgImg
stage.addChild background

The above code produces a canvas and image both with correct proportions on non-retina. However, when I run this on a retina display the canvas is twice the size and the image is 4 times the size. What am I doing wrong?

I am having some issues getting pixi.js 2.+ to work with retina displays.

scale = window.devicePixelRatio
width = 960
height = 500

renderer = new (PIXI.CanvasRenderer)(width, height,{resolution:scale})
stage = new PIXI.Stage(0xFFFFFF)    

if scale is 2
    bgImg = '[email protected]'
else
    bgImg = 'img.png'
background = PIXI.Sprite.fromImage bgImg
stage.addChild background

The above code produces a canvas and image both with correct proportions on non-retina. However, when I run this on a retina display the canvas is twice the size and the image is 4 times the size. What am I doing wrong?

Share Improve this question edited Mar 19, 2015 at 11:08 Brenwell asked Mar 19, 2015 at 10:38 BrenwellBrenwell 73113 silver badges27 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

@2x is correct. It can be a folder name or appended to the image name.

assets/@2x/image.png or assets/[email protected]

Regarding canvas resize issue, can you run this and see if you have the same issue. http://adireddy.github.io/demos/haxe-pixi/v3/retina.html

Thanks to @Adi I got it working. Perhaps I have to set the width & height on the canvas before appending it. Not really sure, but it worked

@scale = window.devicePixelRatio
width = 960
height = 556

@_canvas = window.document.createElement("canvas")
@_canvas.style.width = width + "px"
@_canvas.style.height = height + "px"
container = document.getElementById 'container'
container.appendChild(@_canvas)

renderingOptions = 
  view: @_canvas
  resolution: @scale

renderer = new PIXI.CanvasRenderer(width, height, renderingOptions)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745003013a4605611.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信