Jump to content

Window resizing and texture updating


mobileben
 Share

Recommended Posts

When a user resizes the window, the render area can become bigger or smaller. This potentially has a visual effect in that if the window started off small and then was increased, the textures could look bad if the render area is simply scaled to fit the canvas bounds. Going from larger to smaller is less of an issue, though one could make the argument that it's doing more work than is needed.

How are most people handling this? For example, if you get a resize event and the canvas say doubles in size, do you simple increase the canvas size but leave the renderer area the same? Or do both? If it is the latter then this would possible require newer textures.

For my setup, I have a defined game area which is currently defined as 480x640. I then support different multiples of this. The plan is to do layout at 480x640 right now (though I may use a higher res multiple later). When the game starts, it will best match which multiple fits the canvas and it will use that.

I'm trying to determine if I should just choose the size of everything at start only and if the user changes the window size, they are stuck with that or if I should add support to find the best matching supported dimensions and then use that. If I decide to support better fitting which multiple works, it also implies I would need to have a method to change textures on the fly. I would imagine something like this would use a multi-pass system where I destroy/dispose of the active textures, load the newer ones, and then apply those new textures to the existing PIXI.Sprites. Obviously any other draw element would need to be updated as well. This seems like a lot of work, so seeing what people's experience is regarding this and if it's worth the effort.

 

Link to comment
Share on other sites

You can make something like proxy textures, i had that before: https://github.com/gameofbombs/pixi-heaven/blob/master/srcOld/base/atlas/TextureRegion.ts

That way you wont need to change "sprite.texture", just adjust baseTexture and frame. Actually you dont even need a class there because setting "texture.baseTexture" works in latest pixijs dev

I also use the same principle in new plugin that'll appear soon.

You are still on a front of the problem, there's no progress from our side.

If you solve it even partially, I suggest to publish your engine on github.

Link to comment
Share on other sites

Thanks. I'll need to experiment. BTW, is the best way to resize the renderer to use `renderer.resize()`? This is why `resizeTo` eventually uses and I assume then this actually modifies the framebuffer size in use. I'm not quite used to following JS code that use "runners" yet.

Link to comment
Share on other sites

It is indeedy an Application thing. 

https://github.com/pixijs/pixi.js/blob/2becb1e4e119d6e03c7f1fe0e65ee9d91a5fb687/packages/app/src/ResizePlugin.js#L22

It takes the HTML Element or window. It works, I tried it. I also tried using renderer.resize(w, h), which seems to work. For now I'll assume it correctly resizes the frame buffer versus scaling. 

Once I get further along I can verify if this hypothesis is correct or not.

Link to comment
Share on other sites

Its strange that at the scale of problems you're trying to solve you're only now getting rid of Application class. I write it to every person here who encounters application-related problems, maybe it wrote it to you too: read https://github.com/pixijs/pixi.js/wiki/v5-Custom-Application-GameLoop and make your own. Otherwise you'll have to wait when someone from pixi team fixes particular problem or adds particular feature in an area that's very game-specific and has no critical WebGL stuff that we have expertise of.

Link to comment
Share on other sites

I very may well have to go this route. I generally try and deviate as little as possible when using 3rd party. I've been burned too many times doing my own things and then running into incompatibilities. Plus my relative lack of JS/TS experience has me focusing a bit more on getting up and running versus getting things cleaner. Up to now, I think my scaling handling has been smattered across different places. This one is more application based.

I'll dabble with the game loop a bit today. I'm still tying some pieces together and then will see if I can handle the resizing of assets dynamically. I don't expect the handling to be real time, since that is dependent on assets.

I also expect the ease of doing this to be dependent upon the actual number of assets involved. My initial stuff here is "toy" in size, so manageable.

 

 

Link to comment
Share on other sites

I took a better look at the custom game loop and it makes sense. Not sure if I'll go that route just quite yet. A question I have when looking at the code. I can't seem to see where Application actual assigns properties such as Ticker. I've run a grep on the code base and it isn't obvious to me how this is done. For the most part, Application.js (in packages/app/src) look pretty "empty".

I also don't see assignment to other things such as view, etc.

Where is this all done?

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