Jump to content

Keep ascept-ratio of PIXI.Sprite with fullscreen fullscreen canvas


JanV
 Share

Recommended Posts

var Container = PIXI.Container,    loader = PIXI.loader,    Sprite = PIXI.Sprite,    resources = PIXI.loader.resources;var renderer = PIXI.autoDetectRenderer(256, 256);document.body.appendChild(renderer.view);var stage = new Container();renderer.backgroundColor = 0xffffff;renderer.render(stage);loader    .add("images/ant.png")    .on("progress", loadProgressHandler)    .load(setup);function loadProgressHandler(loader, resource) {    console.log(loader.progress);}var ant;function setup() {    ant = new Sprite.fromImage("images/ant.png");    stage.addChild(ant);    renderer.render(stage);    renderer.view.style.position = "absolute"    renderer.view.style.width = window.innerWidth + "px";    renderer.view.style.height = window.innerHeight + "px";    renderer.view.style.display = "block";        gameLoop();}function gameLoop() {    requestAnimationFrame(gameLoop);    renderer.render(stage);}

This is how my game.js script actually looks like and so far I'm quite happy with what it's doing.

 

But my problem is that all sprites I render on my canvas are distorted and do not keep their original sizes. So what am I doing wrong here?

I just want to keep the original sizes of all objects I'll render on the canvas.

 

(The ant.png image is 250x250px)

 

How the result looks like:

 

post-14932-0-07245700-1435441544_thumb.p

 

How the ant.png looks like:

 

post-14932-0-49475100-1435441585.png

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...