Coloring Sprites?

Hi Dyson… I would like to do something like this:

http://www.coronalabs.com/blog/2012/10/09/dynamically-optimized-sprite-sheets/

How would you go about using this with MTE?  

I’m thinking I’d create a sprite with each body part of my character.  Then I’d just use… say… his head as the main “sprite” I’d set my camera’s focus on.  When I press each direction on the d-pad, the button event listener would move all character body sprites together to the same space.  I’m guessing this is the only way to do it…

Anyways, the actual part I’m having trouble with that I need your help on is coloring each body-part sprite.  I’m gussing with your tintLayer and tintTile functions they are messing with the ability for me to use :setFillColor() on any of my sprites.  Could you make a tintSprite() function possibly?  I can’t seem to fix it myself.

Hello cjc83486,

You can achieve both things by using a group and an as-yet undocumented feature built into addSprite(). Create the sprites for each body part, add those sprites to a group, and add that group to MTE using addSprite. In the setup table you’ll have to change kind = “sprite” to kind = “line”. Line is the shorthand I’m using for “groups containing vector objects” at the moment, but it will work for groups of any object type. You can then use setFillColor() on your body part sprites whenever you like without MTE overriding it. The movement functions work the same for groups as they do for sprites: a single command will move the entire group.

For example, in this code I’ve altered RotateConstrainStoryboard 0v872 to create three identical sprites side by side, place them in a group, add that group to MTE, and tint one of the sprites red.

--CREATE PLAYER SPRITE ------------------------------------------------------------ local spriteSheet = graphics.newImageSheet("spriteSheet.png", {width = 32, height = 32, numFrames = 96}) local sequenceData = { {name = "up", sheet = spriteSheet, frames = {85, 86}, time = 400, loopCount = 0}, {name = "down", sheet = spriteSheet, frames = {49, 50}, time = 400, loopCount = 0}, {name = "left", sheet = spriteSheet, frames = {61, 62}, time = 400, loopCount = 0}, {name = "right", sheet = spriteSheet, frames = {73, 74}, time = 400, loopCount = 0} } player1 = display.newSprite(spriteSheet, sequenceData) player2 = display.newSprite(spriteSheet, sequenceData) player2.x = player2.x - 40 player3 = display.newSprite(spriteSheet, sequenceData) player3.x = player3.x + 40 player = display.newGroup() player:insert(player1) player:insert(player2) player:insert(player3) local setup = { kind = "line", layer = mte.getSpriteLayer(1), locX = locX, locY = locY, levelWidth = 64, levelHeight = 32 } mte.addSprite(player, setup) mte.setCameraFocus(player) player1:setFillColor(255, 0, 0)

@dyson-

Brilliant, looks like it’ll work perfectly, thank you for the prompt response!

It seems changeSpriteLayer() (i think its called that dont have my computer on me) isnt working and throwing a setFillColor() error in mte. If you comment setFillColor out it works… Though i guess youll need to change it somehow.

Thanks for letting me know. Looks like I missed that when I added the “line” kind. 

Hello cjc83486,

You can achieve both things by using a group and an as-yet undocumented feature built into addSprite(). Create the sprites for each body part, add those sprites to a group, and add that group to MTE using addSprite. In the setup table you’ll have to change kind = “sprite” to kind = “line”. Line is the shorthand I’m using for “groups containing vector objects” at the moment, but it will work for groups of any object type. You can then use setFillColor() on your body part sprites whenever you like without MTE overriding it. The movement functions work the same for groups as they do for sprites: a single command will move the entire group.

For example, in this code I’ve altered RotateConstrainStoryboard 0v872 to create three identical sprites side by side, place them in a group, add that group to MTE, and tint one of the sprites red.

--CREATE PLAYER SPRITE ------------------------------------------------------------ local spriteSheet = graphics.newImageSheet("spriteSheet.png", {width = 32, height = 32, numFrames = 96}) local sequenceData = { {name = "up", sheet = spriteSheet, frames = {85, 86}, time = 400, loopCount = 0}, {name = "down", sheet = spriteSheet, frames = {49, 50}, time = 400, loopCount = 0}, {name = "left", sheet = spriteSheet, frames = {61, 62}, time = 400, loopCount = 0}, {name = "right", sheet = spriteSheet, frames = {73, 74}, time = 400, loopCount = 0} } player1 = display.newSprite(spriteSheet, sequenceData) player2 = display.newSprite(spriteSheet, sequenceData) player2.x = player2.x - 40 player3 = display.newSprite(spriteSheet, sequenceData) player3.x = player3.x + 40 player = display.newGroup() player:insert(player1) player:insert(player2) player:insert(player3) local setup = { kind = "line", layer = mte.getSpriteLayer(1), locX = locX, locY = locY, levelWidth = 64, levelHeight = 32 } mte.addSprite(player, setup) mte.setCameraFocus(player) player1:setFillColor(255, 0, 0)

@dyson-

Brilliant, looks like it’ll work perfectly, thank you for the prompt response!

It seems changeSpriteLayer() (i think its called that dont have my computer on me) isnt working and throwing a setFillColor() error in mte. If you comment setFillColor out it works… Though i guess youll need to change it somehow.

Thanks for letting me know. Looks like I missed that when I added the “line” kind.