Jump to content

create texture dynamically in preload


markp
 Share

Recommended Posts

I have a graphics object that I use to draw a filled square with a thick border.  I can create a texture using this graphics object and generateTexture() method so that I can create square sprites.  I needed to add some dynamic text layered onto the sprite so I just started with a group, added the sprite for the square and then added text.  The result is text on top of the square.

 

If I create say 100 of these groups my FPS on my test Nexus 7 is down at about 5fps.  Pretty low so I thought I'd just see the effect of replacing the contents of the group with a single sprite created from a single image.  I used the mushroom2.png from the example assets and achieved 60fps on the Nexus which is awesome.

 

My conclusion is that my method of creating my dynamic square sprite with a layered piece of dynamic text in a group is not optimal for the rendering and that a single sprite would be optimal.  So I have 2 questions really:

 

1. Can I draw a filled-in square and write a little text somehow to create a single texture in the preload method of my stage?

 

2. If I can create a texture, is it possible to load the texture at runtime from the variable holding the texture reference as opposed to using a url?

 

Link to comment
Share on other sites

I solved my issue by just using a bitmapData which exposes its own underlying canvas.  I can do whatever graphics and text I want on this canvas.

 

Loading the image drawn on the canvas is simply a case of calling the canvase method toDataUrl() and passing the return value to the second parameter of game.load.image.

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