[Example/Tips] Sprite Plugin & its mysteries.

Post your own tutorials, guides and demos.

Post » Tue Jun 05, 2012 4:11 pm

Hi on this delivery, i'll treat Sprite Plugin and some features, and its usage with other plugins like Tiled Background,Image Manipulatior, Canvas and TextureSetter.

In the recent days i was experimenting with a world creator, a tile-based map editor i'm creating, and i had an issue trying to load textures dynamically, and i'd dicovered a sort of facts what many of us, i think still dont know about textures in CC.

Fact 1. In the CC editor, every time we create a Sprite object, construct assigns a unique texture in the heap(VRAM), so that Sprite points to that texture, if you create additional instances of such Sprite, you'll notice each will get the same texture, at given time you try to change texture to some of them, eihter using Image Manipulator or TextureSetter, really you are changing that one texture created at beginning.

Fact 2. Unlike Sprite object, the Tiled Background(TB) has property to create textures dynamically, that means, in runtime when creating instances of a base TB object construct assigns for each new instance an texture in the VRAM, so as you create more instances you are inflating VRAM. Having minded texture creates by this way always should be power of 2 8x8, 16x16, ... , 512x512 and so on...

Now making usage of these facts, we can create an dynamic texture loader, using the ability to load texture files from disk for the TB or Sprite objects, manipulate images with IM and assign with TextureSetter.

The canvas can be used for mixing differents images into one due to its 'Paste Sprite' action. By using a sprite as referencer of images contained in several TB objects. After mixing assign to another sprite by first assigning it to an empty TB then assign it to the Sprite. The Assigning process is made by TextureSetter Object.

I expect this be helpful to someone.

NOTE: Tomorrow i'll publish the respective caps... (too lazy :P)
Sorry for my English

Yaottabyte2012-06-05 16:16:49
B
4
S
1
G
1
Posts: 69
Reputation: 863

Post » Tue Jun 05, 2012 8:18 pm

Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Jun 05, 2012 8:51 pm

Well there is a couple of image to try illustrate my idea and concepts.

this is how normally construct manages Sprites.


This is how must be the VRAM after apply my method.


above you see 1 Sprite object, 3 Tiled Background and 5 more instances of Sprite. So just 3 textures was used, reducing VRAM usage and texture still reusable... Using UniqueSprite you will have a texture for each sprite created so inflating VRAM as many instances you create.

My idea is use external images(textures) but same time reducing VRAM. Because when creating tile-based maps some tiles get repeated so you dont need waste VRAM on an image previously used.

Notice that all tiled background objects may be created on runtime, every time you needs a new different texture, too the sprite has checked 'destroy on startup' and they are created on demand in runtime, as you like and assign texture from texture pool provided by the tiled background objects, using the Texture Setter object.Yaottabyte2012-06-05 21:02:36
B
4
S
1
G
1
Posts: 69
Reputation: 863

Post » Tue Jun 05, 2012 9:17 pm

And here a quickly overview as the process to load dynamical textures from disk.



All texture assignments made with Texture Setter object.

EDIT: important to be warning... when using this method, before destroy any textured TiledBackground being used by any other sprite object, must destroy first all sprites using that TiledBackground textures, so then you can create TiledBackground again and use their texture in your sprites as well.Yaottabyte2012-06-08 14:53:07
B
4
S
1
G
1
Posts: 69
Reputation: 863


Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 0 guests