flipping sprites from a spritesheet ?

haloa Corona 

I have a spritesheet different people in different positions, and it works well.

I have a few sequence to animate them a bit, nothing fancy.

However i’d like to duplicate these people and flip them around so it looks like more ‘different’ people.

the sprites are identical, just … flipped around.

do I have to flip all my pictures and therefore double them up in the spritesheet ?. Or is there a way in the newSpriteSheet sequence to flip the sprite ?

If there is a way… Great … but then … these people have physic interaction, is there a way to flip the physic representation of them ?

thanks !

Edualc

object:scale(-1,1) will flip a display object horizontally.

Flipping physics objects is a bit more complicated. Here’s an example: https://gist.github.com/ignisdesign/8964841

thanks _memo

I’m impressed with the flipping physics objects. Was hoping for something out of the box though…

Now lots of the one i want to flip do not have physics e.g. people passing by.

I know about object:scale(-1,1) however my sprites come from a spritesheet so i need the whole sequence to be flipped.

I have about 50 sprites that i need to use both sides/ways so i’d like to avoid to have them duplicated in the spritesheet itself.

e.g.

local options = {width = 148, height = 124, numFrames = 40, sheetContentWidth = 1480, sheetContentHeight = 496}local peoplesheet = graphics.newImageSheet("people.png", options ) local sequenceData = { --   { name = "all", start=1, count=4, time=500,   loopCount=2 },    { name = "pl\_std", frames={37,38,39,40,33,34}, time=500, loopCount=1 }, -- standing    { name = "pl\_lef", frames={31,32,39,40,33,34}, time=500, loopCount=1 }, --  left, 1    { name = "pl\_rig", frames={31,32,39,40,33,34}, time=500, loopCount=1 }, --  right, 1 } for ip = 1,maxPeople do     if ip % 2 == 0 then            players[ip] = display.newSprite( peoplesheet, sequenceData )            players[ip].xScale = 0.4 ; players[ip].yScale = 0.4 ;            players[ip]:setSequence( "pl\_lef" )     else            players[ip] = display.newSprite( peoplesheet, sequenceData )            players[ip].xScale = 0.4 ; players[ip].yScale = 0.4 ;            players[ip]:setSequence( "pl\_rig" )     end end

Hi @edualc,

In your tests, does flipping the sprite require that you flip every frame? In a little game I’m developing, I flipped a sprite and the entire sequence remained flipped… I didn’t need to do anything further once the object itself was flipped.

Brent

Hi Brent

it does !! flip the entire sequence ! didn’t even think about trying that.

Probably because right now my sequence there are sprites I want to flip and some I dont want to flip.

so flipping the entire sequence will force me to split the sequence left and when finished right. 

or to bounce it back and do something like this:

if (player[2].frame == 4) then players[2].xScale = players[2].xScale \* -1 end

it’s not perfect because i have to hard code the sprite in the sequence where it has to flip the sprites and also the index of the player itself. (players[2] being ‘guy who cross the road’) 

But it’s doable.

what would be really good would be 

 { name = "pl\_lef", frames={31,32,39,40,33,34}, time=500, loopCount=1 }, --  left, 1  { name = "pl\_rig", frames={31,32,39,40,flip(33),flip(34)}, time=500, loopCount=1 }, --  right, 1

hmmm … am I asking too much ? :wink:

It’s technically doable but you’d end up rewriting chunks of Corona’s animation system to do it. 

object:scale(-1,1) will flip a display object horizontally.

Flipping physics objects is a bit more complicated. Here’s an example: https://gist.github.com/ignisdesign/8964841

thanks _memo

I’m impressed with the flipping physics objects. Was hoping for something out of the box though…

Now lots of the one i want to flip do not have physics e.g. people passing by.

I know about object:scale(-1,1) however my sprites come from a spritesheet so i need the whole sequence to be flipped.

I have about 50 sprites that i need to use both sides/ways so i’d like to avoid to have them duplicated in the spritesheet itself.

e.g.

local options = {width = 148, height = 124, numFrames = 40, sheetContentWidth = 1480, sheetContentHeight = 496}local peoplesheet = graphics.newImageSheet("people.png", options ) local sequenceData = { --   { name = "all", start=1, count=4, time=500,   loopCount=2 },    { name = "pl\_std", frames={37,38,39,40,33,34}, time=500, loopCount=1 }, -- standing    { name = "pl\_lef", frames={31,32,39,40,33,34}, time=500, loopCount=1 }, --  left, 1    { name = "pl\_rig", frames={31,32,39,40,33,34}, time=500, loopCount=1 }, --  right, 1 } for ip = 1,maxPeople do     if ip % 2 == 0 then            players[ip] = display.newSprite( peoplesheet, sequenceData )            players[ip].xScale = 0.4 ; players[ip].yScale = 0.4 ;            players[ip]:setSequence( "pl\_lef" )     else            players[ip] = display.newSprite( peoplesheet, sequenceData )            players[ip].xScale = 0.4 ; players[ip].yScale = 0.4 ;            players[ip]:setSequence( "pl\_rig" )     end end

Hi @edualc,

In your tests, does flipping the sprite require that you flip every frame? In a little game I’m developing, I flipped a sprite and the entire sequence remained flipped… I didn’t need to do anything further once the object itself was flipped.

Brent

Hi Brent

it does !! flip the entire sequence ! didn’t even think about trying that.

Probably because right now my sequence there are sprites I want to flip and some I dont want to flip.

so flipping the entire sequence will force me to split the sequence left and when finished right. 

or to bounce it back and do something like this:

if (player[2].frame == 4) then players[2].xScale = players[2].xScale \* -1 end

it’s not perfect because i have to hard code the sprite in the sequence where it has to flip the sprites and also the index of the player itself. (players[2] being ‘guy who cross the road’) 

But it’s doable.

what would be really good would be 

 { name = "pl\_lef", frames={31,32,39,40,33,34}, time=500, loopCount=1 }, --  left, 1  { name = "pl\_rig", frames={31,32,39,40,flip(33),flip(34)}, time=500, loopCount=1 }, --  right, 1

hmmm … am I asking too much ? :wink:

It’s technically doable but you’d end up rewriting chunks of Corona’s animation system to do it.