Trying to get a bit of player customisation for my game. At the moment I'm using a layered sprite by it's not ideal and would love to build the atlas at runtime. What's the best way to do it?
Well my characters need to be built from different layers of graphics (eyes, mouth, nose, clothing) mixed together. This has to be done at runtime once the player has chosen his options. So I need to be able to generate a sheet of sprites in gideros that I can then reference in game. The sheet does not have to be saved but it will be generated again at every new game (or change of options).
Yep, I found that. The problem is that I need to layer 2 or 3 different graphics on top of each other (face+different eyes+mouth) and unless I'm mistaken I can't do that with the texture pack command.
local character = Sprite.new()local head = Bitmap.new(Texture.new("head.png", true))
head:setPosition(50, 0)
character:addChild(head)local arms = Bitmap.new(Texture.new("arms.png", true))
arms:setPosition(0, 50)
character:addChild(arms)--etc--in the endlocal texture = RenderTarget.new(100, 100, true)
texture:draw(character)--and here is a result image to uselocal neededImage = Bitmap.new(texture)--you can then update the character again if you need it--and call
texture:draw(character)--contents of neededImage will be updated automatically
Sorry to be so dense, but when you say you can update the character and call texture:draw(character) to update the contents of neededImage, how do you actually update the character? Do you, for example, set a new image for the head? And do the changes just show when you call texture:draw(character) or do you have to do something else?
The idea was that you can change the head position for example, of add another head to the character sprite and then call texture:draw(character) and you don't have to change neededImage, reassign its texture etc. It will get updated automatically from character changes after the draw method is called.
Thanks. What if I wanted to change the head image rather than add another one? Would I have to remove the first one or can I somehow just change the image used for the head? Normally I just play with things to get the hang of them but I'm not having much joy this time. I told you I was confused!
You can manipulate character sprite hierarchy as you would with any other simple sprite hierarchy added to the stage. In the case of changing the head, you could remove head image and add other one, or simply use Bitmap's setTexture method to change head texture
Comments
So....render to texture?
In a way I have multiple layers of images and I want to collapse them before using it in game
Oh well, time to experiment with render to texture!
http://docs.giderosmobile.com/reference/gideros/TexturePack#TexturePack
Can I nil the loaded images or is the render to texture just referencing them?
I'm struggling with this!
Thanks
In the case of changing the head, you could remove head image and add other one, or simply use Bitmap's setTexture method to change head texture