Sign in to follow this  
Tumetsu

Replacing textures on runtime to high definition

Recommended Posts

I'm building my first Pixi game and working on basic services for asset management. My game should support few different resolution asset packs. Pixi handles this fine with resolution values and scaling.

Next part I'm working on is to reload higher definition assets when required. Lets say that player starts game on 800x500 embedded window but presses full screen toggle. In this case I'd like to load HD assets on background and then replace the SD assets with newer ones once loading is ready. Before implementation I'd like to know if there is any existing mechanism in Pixi for this kind of operation? Or if not, should I know something specific about Pixi's texture handling to avoid some pitfalls? 

My current idea is as follows: When user moves to HD mode, trigger reloadAssets event, which kicks of my AssetLoader which loads the set of resources I require at the moment. Loader stores the names and textures to a map in AssetStorage -service. Once this is finished, an updateAssets event is broadcasted. Each Sprite can listen this event and they will update their texture from my AssetStorage  -service.

The reason I'm slightly insecure about my design is because I don't know exact inner workings of Pixi's resource management. For example does Pixi clear assets automatically, which might mess up my AssetStorage -service? What exactly I need to do when I reload new versions of assets especially regarding the old assets?BaseTexture seems to have update() function, can I sue it for this case?

I'm reading about this stuff but decided to drop a question here since these are things I couldn't yet find any clear examples. Also, I'm afraid I'll implement something which is already done better in Pixi :)

Share this post


Link to post
Share on other sites

Better to change Textures themselves: change their baseTexture and frame. That way you wont have to notify sprites. In most cases you wont even have to change frame/trim/crop things, they are the same for HD. Don't forget to scale your stage accordingly that pixel still stays 1:1. Also its better not to change "renderer.resolution" on fly. There are many things that can go wrong, but the main idea is:

1. coordinates of sprites must stay the same

2. coordinates in textures (frame/crop/trim) better to stay same. At least width height are same, multiply texture resolution and not its width/height

Summary: Learn how Texture/BaseTexture work. Modify Textures and not sprites for it.

Share this post


Link to post
Share on other sites

Alright, I think I tried something like that but didn't figure to modify my existing textures' baseTextures. Thanks.

Btw, is the TextureCache in PIXI in state of flux atm? I keep finding mentions that it should be in utils, but on Pixi4 rc I found it from TextureManager which I couldn't find from docs. 

Share this post


Link to post
Share on other sites

Hello guys - is there a prebuilt or easy way to select the spritesheet to load based on resolution? I was going to make a function that switches things out if the resolution changes, or is above or below a certain threshold  - I guess I'd just replace the spritesheet already loaded for another? Is there something more elegant than a switch statement in my scene loader that checks the resolution and if HD, loads the @2x spritesheet instead of the regular one?

Thanks in advance.

Share this post


Link to post
Share on other sites

It's not as hard as it seems, our system handles from 0.25 to x3 resolution.

The basic idea is > resource reference by resolution > get reference in app according to resolution. The resource reference can include scale and dimension, etc ... Stronger system define a target resolution and go through references until it finds the closest match. eg. target is 0.5, system tries to find a 0.5, then a 1, then a 2, etc .. until it finds one. 

here's an example of what we do in our apps, it's all plugged to a CDN. An asset can be defined 5 times with different density but at the end we only get one in app.

new BitmapResource('contextresources/default_density/resource_7571.png', 'bitmap', 'TL', 1024, 688, 2);
new BitmapResource('contextresources/low_density/resource_7571.png', 'bitmap', 'TL', 1024, 688, 1);
new BitmapResource('contextresources/ultra_low_density/resource_7571.png', 'bitmap', 'TL', 1024, 688, 0);

Share this post


Link to post
Share on other sites
1 hour ago, botmaster said:

It's not as hard as it seems, our system handles from 0.25 to x3 resolution.

The basic idea is > resource reference by resolution > get reference in app according to resolution. The resource reference can include scale and dimension, etc ... Stronger system define a target resolution and go through references until it finds the closest match. eg. target is 0.5, system tries to find a 0.5, then a 1, then a 2, etc .. until it finds one. 

here's an example of what we do in our apps, it's all plugged to a CDN. An asset can be defined 5 times with different density but at the end we only get one in app.

new BitmapResource('contextresources/default_density/resource_7571.png', 'bitmap', 'TL', 1024, 688, 2);
new BitmapResource('contextresources/low_density/resource_7571.png', 'bitmap', 'TL', 1024, 688, 1);
new BitmapResource('contextresources/ultra_low_density/resource_7571.png', 'bitmap', 'TL', 1024, 688, 0);

How is your flash coming, buddy? Mine will be completed in 6 months, i think. We've got ALL vector graphics operations, and ALL BLUR-RELATED FILTERS. All blendModes, FILTER CACHE, many other things.

Share this post


Link to post
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...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.