Jump to content

Can't render anything.


karhu
 Share

Recommended Posts

So it's been a while since i played with pixi.js, there has been new version etc. I have used version 4.4.0 last time. Has lots of things changed?

Anyhow, here is my jsfiddle: https://jsfiddle.net/hp4yn6kz/2/

As you can see, you cant see any text in the canvas. I also tried with texture atlas, but it renders nothing. Did i do something wrong? This worked before.

Link to comment
Share on other sites

Hi,

Your resize method is on a loop there.

Try this:

resize() {
        render.app.view.style.width = $('#mainRender').offsetWidth + "px";
        render.app.view.style.height = $('#mainRender').offsetHeight + "px";
        //render.app.renderer.resize($('#mainRender').offsetWidth,$('#mainRender').offsetHeight);
        render.app.renderer.resize(window.innerWidth, window.innerHeight);
    }

Don't forget to scale the stage too, if you need so...

Link to comment
Share on other sites

5 minutes ago, nmiguelmoura said:

Hi,

Your resize method is on a loop there.

Try this:


resize() {
        render.app.view.style.width = $('#mainRender').offsetWidth + "px";
        render.app.view.style.height = $('#mainRender').offsetHeight + "px";
        //render.app.renderer.resize($('#mainRender').offsetWidth,$('#mainRender').offsetHeight);
        render.app.renderer.resize(window.innerWidth, window.innerHeight);
    }

Don't forget to scale the stage too, if you need so...

Thanks! I was looking for mistakes from the wrong place. :D

Link to comment
Share on other sites

14 minutes ago, karhu said:

Just going to ask what is the best way to scale the stage? Or is there some kind of function inside the stage object? 

Just change stage's scale.

stage.scale.set( app.screen.width / MY_PREFERRED_WIDTH, app.screen.height / MY_PREFERRED_HEIGHT ) 

// app.screen.width is same as innerWidth that you passed in resize

I wont explain how to preserve aspect ratio, you have to write your own logic for it.

Link to comment
Share on other sites

Instead of the previous code, I use something close to this:

resize() {
        let width = window.innerWidth;
				let height = window.innerHeight;
        let defaultWidth = 1024;
        let defaultHeight = 768;

        let scaleX = width / defaultWidth,
            scaleY = height / defaultHeight;

        // Choose minor scale value.
        let scale = Math.min(scaleX, scaleY);

        // Round values, or firefox and chrome render blurred images.
        let finalWidth = Math.floor(defaultWidth * scale);
        let finalHeight = Math.floor(defaultHeight * scale);

				console.log(width, height, scale, finalHeight);
        // Set render size.
        render.app.renderer.resize(finalWidth, finalHeight);

        // Scale scene stage.
        render.app.stage.scale.x = scale;
        render.app.stage.scale.y = scale;
    }

I don't know if there's a simpler or better way, this one works for me.

I also keep track of those values (width, height, scale) for later use.

Link to comment
Share on other sites

1 hour ago, ivan.popelyshev said:

Just change stage's scale.


stage.scale.set( app.screen.width / MY_PREFERRED_WIDTH, app.screen.height / MY_PREFERRED_HEIGHT ) 

// app.screen.width is same as innerWidth that you passed in resize

I wont explain how to preserve aspect ratio, you have to write your own logic for it.

 

1 hour ago, nmiguelmoura said:

Instead of the previous code, I use something close to this:


resize() {
        let width = window.innerWidth;
				let height = window.innerHeight;
        let defaultWidth = 1024;
        let defaultHeight = 768;

        let scaleX = width / defaultWidth,
            scaleY = height / defaultHeight;

        // Choose minor scale value.
        let scale = Math.min(scaleX, scaleY);

        // Round values, or firefox and chrome render blurred images.
        let finalWidth = Math.floor(defaultWidth * scale);
        let finalHeight = Math.floor(defaultHeight * scale);

				console.log(width, height, scale, finalHeight);
        // Set render size.
        render.app.renderer.resize(finalWidth, finalHeight);

        // Scale scene stage.
        render.app.stage.scale.x = scale;
        render.app.stage.scale.y = scale;
    }

I don't know if there's a simpler or better way, this one works for me.

I also keep track of those values (width, height, scale) for later use.

Thanks! I was thinking about calculating it like this. I just gotta find the "typical aspect ratio" and if the screen doesn't fit i will add black letterbox -thingy. Just gotta find the best way to do it.

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