Jump to content

RenderTexture won't render Texture


Wolfos
 Share

Recommended Posts

So I got this whole tile renderer, that I think should work (followed the docs pretty closely) but it doesn't. So I put together some minimal code to render an image to a renderTexture and that doesn't work either (nothing in the log, just doesn't work).

 

This code doesn't work:

var renderTexture = new PIXI.RenderTexture(1024, 1024);var sprite = new PIXI.Sprite(renderTexture);stage.addChild(sprite);	var texture = PIXI.Texture.fromImage("Assets/Sprites/Image.png");var textureSprite = new PIXI.Sprite(texture);renderTexture.render(textureSprite);

But rendering text to the RenderTexture (as in this blog post) works just fine, as well as just rendering the image to the stage directly. What am I doing wrong here?

 

EDIT: It seems that the RenderTexture example uses Pixi 1.2.0, which is almost 2 years old. Can anyone confirm RenderTextures being broken in the latest release?

Link to comment
Share on other sites

RenderTextures are working fine in the last version I worked with which I think is 2.1.

It's possible that the problem you are having might be caused by a timing issue. You might be trying to draw the sprite to the render texture before the png has finished loading. I'm guessing from your rendertexture dimensions of 1024 squared that it is quite a large image which would add credibility to this notion.

A quick way of testing this would be moving the call to renderTexture.render into a setTimeout of some arbitrary number of milliseconds, just to be sure there is enough time following your call to Texture.fromImage before you then try to draw the image to your rendertexture. Obviously don't leave the setTimeout in there though, it's just meant as a test! At the end of the day you would probably be better off preloading your images, then you can be sure they are ready to use.

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