[Example/Tips] Sprite Plugin & its mysteries.

This forum is currently in read-only mode.
From the Asset Store
The I18N (Translation) is a Construct plugin created to translate text in game.
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well there is a couple of image to try illustrate my idea and concepts.

    this is how normally construct manages Sprites.

    <img src="http://dl.dropbox.com/u/74660811/examples/sprite_facts1.png" border="0" />

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

    <img src="http://dl.dropbox.com/u/74660811/examples/sprite_facts2.png" border="0" />

    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.

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

    <img src="http://dl.dropbox.com/u/74660811/examples/sprite_facts3.png" border="0" />

    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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)