any way to invert images

hi is there a way I can invert a image e.g. horizontal flip???
Would half my work loud in many areas.

[import]uid: 118379 topic_id: 25971 reply_id: 325971[/import]

yeah.
[lua]image.xScale = -1[/lua] [import]uid: 64174 topic_id: 25971 reply_id: 105100[/import]

Yeeehaa
Thanks. Cant believe how excited thats made me. Ive turned into a mega geek. My game has 10000 lines of code already so this has made me very happy.

Many thanks. [import]uid: 118379 topic_id: 25971 reply_id: 105101[/import]

It is an awesome technique! :slight_smile: Just note that it won’t “flip” a physics body, i.e. a shape or polygon body. Because this method is using “scale”, and scale doesn’t scale physics bodies (unless you scale the entire group/world), this invert method follows the same limitation. If you’re not using physics bodies, then invert away… otherwise you’ll need to consider a workaround.

Brent Sorrentino
Ignis Design
[import]uid: 9747 topic_id: 25971 reply_id: 105125[/import]

@ Ignis

Thx for the entire group flip I will try, Would not of thought of it.

I could create a separate inverted shapes table also, which isn’t to much bother. Might even be able to get a bit of code to do it for me.

Biggest advantage is file size and time saved inverting images for sprite sheets etc.

Whilst im here, do you know if its possible to update a physics shape on the fly? So if it flipped in game could I pass in a new shape?
Cheers Stu. [import]uid: 118379 topic_id: 25971 reply_id: 105150[/import]

It should be possible to remove the “normal” body then swap (add) the “flipped” body, but you might need to do it in 2 consecutive game cycles. Testing will be the only way to know if this works as it should.

Regarding the inverted table (of points to make a polygon shape), I’m going to work on that tomorrow since one of my apps needs to flip shapes too. I wonder if just working backwards through the coordinate series would do the trick, while maintaining the necessary clockwise order of Box2D coordinate declaration. Hmmmm… :wink:

Brent [import]uid: 9747 topic_id: 25971 reply_id: 105151[/import]

Yes that could work if you invert the reference point too I think. Im on it now, if I work it out i’ll let you know.

I would love a feature where we could construct an image sheet with only the required objects for one level during the load phase from multiple sheets. Would be truly awesome. :slight_smile: [import]uid: 118379 topic_id: 25971 reply_id: 105152[/import]

Its easy, just jotted it down. If its horizontal flip, just invert all the X cords and if vertical invert the Y. Keep Centre reference point. Job done. :slight_smile:
Heres my conversion function with all three modes.

[code]
local terrainShapes = {

{-6,24, -14,15, -14,-5, -5,-25, 24,-25, 25,25},
{25,25, -6,25, -5,6, 0,-25, 25,-25},
{-5,25, -15,1, -5,-25, 25,-25, 25,25},
{-5,24, -18,18, -20,-2, -5,-25, 25,-25, 25,25},
{25,25, -6,25, 1,-12, 1,-25, 25,-25},
{25,24, -1,24, -1,3, -8,-10, -5,-25, 25,-25},
{25,24, -10,24, -10,17, 0,4, 0,-25, 24,-25},
{25,25, -15,25, 0,-7, 0,-25, 25,-25},
{-3,25, -16,7, -16,-4, -1,-12, -1,-25, 25,-25, 25,25},
{-6,25, -16,20, -11,13, -10,-9, -5,-25, 25,-25, 25,25},
{25,25, -6,25, 4,14, 4,-25, 25,-25},
{-6,24, -16,12, -12,-6, -5,-25, 25,-25, 25,25},
{25,25, -6,25, -13,17, -5,8, -5,-25, 25,-25},
{-5,25, -13,12, -13,-1, -5,-5, -4,-25, 25,-25, 25,25},
{-6,25, -10,18, -5,-5, -5,-25, 25,-25, 25,25},
{25,25, -6,25, 2,19, 2,-25, 25,-25},
{25,25, -5,25, -10,17, -10,-10, -5,-25, 25,-25},
{-5,25, -10,16, -10,-1, -5,-25, 25,-25, 25,25},
{24,16, 6,8, -6,-25, 24,-25},
{-6,24, 0,7, 11,1, 24,0, 25,25},
{24,27, 17,27, 17,-26, 24,-26}

}

local function invertShapes(mode,terrainInvert)

local function updateShapeList(increment)
for i=1, #terrainInvert do

for e=increment, #terrainInvert[i], 2 do
local n = terrainInvert[i][e]

if n > 0 then
n = n * -1
elseif n < 0 then
n = math.abs(n)
end

terrainInvert[i][e] = n
end
end
end

if mode == “horizontal” then
updateShapeList(1)
elseif mode == “vertical” then
updateShapeList(2)
elseif mode == “both” then
updateShapeList(1)
updateShapeList(2)
end

return terrainInvert

end

–Centre reference point required - 3 modes
local invertedTerrain = invertShapes(“horizontal”,terrainShapes)
[/code] [import]uid: 118379 topic_id: 25971 reply_id: 105155[/import]

Only issue is how to invert the collision response, as Im getting no bounce on the inverted shapes.
[import]uid: 118379 topic_id: 25971 reply_id: 105157[/import]

No bounce: this sounds suspiciously like the inverted shape isn’t being declared in the proper clockwise point order. I remember that I made that mistake once and the collisions were basically occurring, but not behaving properly in other regards. You might want to check that your inversion algorithm is keeping the coordinates clockwise. This is my guess as to why it’s quite not working yet.
[import]uid: 9747 topic_id: 25971 reply_id: 105180[/import]

Sussed, you are right thats what it is:

[code]
local terrainShapes = {

{-6,24, -14,15, -14,-5, -5,-25, 24,-25, 25,25},
{25,25, -6,25, -5,6, 0,-25, 25,-25},
{-5,25, -15,1, -5,-25, 25,-25, 25,25},
{-5,24, -18,18, -20,-2, -5,-25, 25,-25, 25,25},
{25,25, -6,25, 1,-12, 1,-25, 25,-25},
{25,24, -1,24, -1,3, -8,-10, -5,-25, 25,-25},
{25,24, -10,24, -10,17, 0,4, 0,-25, 24,-25},
{25,25, -15,25, 0,-7, 0,-25, 25,-25},
{-3,25, -16,7, -16,-4, -1,-12, -1,-25, 25,-25, 25,25},
{-6,25, -16,20, -11,13, -10,-9, -5,-25, 25,-25, 25,25},
{25,25, -6,25, 4,14, 4,-25, 25,-25},
{-6,24, -16,12, -12,-6, -5,-25, 25,-25, 25,25},
{25,25, -6,25, -13,17, -5,8, -5,-25, 25,-25},
{-5,25, -13,12, -13,-1, -5,-5, -4,-25, 25,-25, 25,25},
{-6,25, -10,18, -5,-5, -5,-25, 25,-25, 25,25},
{25,25, -6,25, 2,19, 2,-25, 25,-25},
{25,25, -5,25, -10,17, -10,-10, -5,-25, 25,-25},
{-5,25, -10,16, -10,-1, -5,-25, 25,-25, 25,25},
{24,16, 6,8, -6,-25, 24,-25},
{-6,24, 0,7, 11,1, 24,0, 25,25},
{24,27, 17,27, 17,-26, 24,-26}

}

local function invertShapes(mode,terrainInvert)

local function updateShapeList(increment)
for i=1, #terrainInvert do

for e=increment, #terrainInvert[i], 2 do
local n = terrainInvert[i][e]

if n > 0 then
n = n * -1
elseif n < 0 then
n = math.abs(n)
end

terrainInvert[i][e] = n
end
end
end

local function changeVectorDirection(shapes)
local tempTerrain = {}

for i=1, #shapes do
local c = 1
tempTerrain[i] = {}
for e=#shapes[i], 1, -2 do

tempTerrain[i][c] = shapes[i][e-1]
c = c + 1
tempTerrain[i][c] = shapes[i][e]
c = c + 1

end

end

return tempTerrain
end

if mode == “horizontal” then
updateShapeList(1)
terrainInvert = changeVectorDirection(terrainInvert)
elseif mode == “vertical” then
updateShapeList(2)
terrainInvert = changeVectorDirection(terrainInvert)
elseif mode == “both” then
updateShapeList(1)
updateShapeList(2)
end

return terrainInvert

end

–Centre reference point required - 3 modes
local invertedTerrain = invertShapes(“horizontal”,terrainShapes)

[/code] [import]uid: 118379 topic_id: 25971 reply_id: 105184[/import]