simpleyuji

cacheAsBitmap [power of 2]

Recommended Posts

I have a tiled based game, where i use cacheAsBitMap to render tiles as chunks (16x16 tiles). The way I'm currently doing is grouping tiles into a chunk instance which is basically a PIXI.Container . If all 16x16 tiles are filled, then cacheAsBitmap would generate a texture of 512x512 which is great. However, if there are some tiles that are not filled (i.e empty spaces), the generated texture (ie. 224x416) would not become power of 2 and I'll get console errors. The error looks something like "texture bound to texture unit 0 is not renderable. It maybe non-power-of-2 and have incompatible texture filtering". 

What's the best way to set the bounds of my container such that its fixed at 512 width and 512 height. My current planned solution is to make new custom class FixedContainer that inherits from PIXI.Container, and overriding getBounds function to return the proper values. Is there a better way?

Share this post


Link to post
Share on other sites

It shouldn't do that, but I have an idea how can that happen. Whats the version that you are using? Please provide a demo.

The best idea is actually to manually create RenderTexture of desired size and maintain it. "renderer.render(container, renderTexture)" will re-cache it. Then you can use a sprite instead.Basically, that's what cacheAsBitmap does.

There are other ways to make a tilemap, but it really depends on your case. Please tell me more.

Share this post


Link to post
Share on other sites

I was using 4.8.5, but I was able to reproduce it on 5.0.3 . Here's a demo. https://jsfiddle.net/aehsqLcf/2/ . I've used chunk size of 4 tiles so things are easily viewable on jsfiddle. Notice that some textures could be 96x96, 100x100, etc. You can change the CHUNK_SIZE variable to 8 to see more non-power of 2 textures

To give you a bit more context, i'm making a sandbox game where players can modify each tile (place blocks and destroy them). What I'm doing is calling cacheAsBitmap (false, then true) on a chunk if its been modified. 

You mentioned RenderTexture. I can see how it can be initialized with a fixed size. So should I do 

PIXI.RenderTexture.create(512, 512)

for my chunk instead of using cacheAsBitmap?  

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

  • Recently Browsing   0 members

    No registered users viewing this page.