Jump to content

Frame for sprite rather then texture


powerfear
 Share

Recommended Posts

Hello, I've been using pixi.js recently and I noticed that you can set a frame basically a subregion of a texture but that is done on the texture itself wich is a bit strange in my opinion. Wouldn't it be better to be able to set the frame on the sprite rather then on the texture? That way example if you have many sprite with a walking animation, you can use the same single texture for all the sprite and simply individually change their frame, so they are able to display a different state of the animation while using the same texture. Most framework I used did it that way but maybe I didn't look at the source properly and we can already do that? If not I think it would be a great thing to change.

Link to comment
Share on other sites

Hi guys! I see where you are coming from. When I first built pixi that was exactly how it worked. In the end I decided to go down the current path as it offers a little more flexibility.

 

This method allows you to store frames and textures together and allows for a simple unified way (setTexture) of modifying a sprites texture regardless of if it is a frame change or a texture change.

 

In pixi terms a "Texture" consists of a frame and a baseTexture. A texture object has a pretty tiny memory footprint its the baseTexture where the actual image is stored. The idea is that for each walking frame you create a a texture with the correct frame and baseTexture. Then each frame you swap textures (These textures could also be shared amongst many entities) Heres an example of how to create textures with various frames: http://renaun.com/blog/2013/03/using-illustrator-from-the-adobe-creative-cloud-and-pixi-js-to-create-an-8-way-character-animation/

 

That said there are plenty of ways to skin a cat! The method you are suggesting would work too. You can create a texture for each sprite and change the frame each time if you prefer. On the surface this may look like you would be creating lots of duplicated images but under the hood they all would share the same baseTexture.

 

Hope that clears things up a bit

 

 

 

 

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