looking for an object.fill "mirror" method

I have 2 large landscapes that meet to form an annoying and visible line.  Each landscape is a display.newPolygon with an object.fill that is a textured wrapped bitmap image.  I’m hoping to mirror one of the landscapes to facilitate a smooth transition. 

[lua] object.fill.rotation [/lua]

object.fill.rotation only rotates the fill and I need a mirrored effect.  I’m hoping to achieve this without having to use another bitmap that has been manually mirrored.

Any ideas?

Haven’t tried this but setting .xScale to -1 might work?

as per nick_sherman, either

object.xScale = -1

or

object.fill.scaleX = -1

(no idea why they didn’t keep consistent property naming)

Now that’s a nifty trick guys!  I’ve never tried that.  It worked fine on some little tests I did but, unfortunately, it doesn’t seem to work for my landscapes and I think it has something to do with the texture wrapping.  I’ll keep investigating.

Can you not use setDefault() to do this?

display.setDefault( “textureWrapX”, “repeat” )

display.setDefault( “textureWrapY”, “mirroredRepeat” )

https://docs.coronalabs.com/guide/graphics/repeatFill.html

@SGS 

I like that idea.  I forgot there was a mirrored repeat.  I only every us clamp and regular repeat.  I’ll give it a shot!

After further investigation, I have a feeling that both suggested methods would work, however, I think the real problem is that each landscape has it’s own fill scaling to keep the texture consistent so only two landscapes with an identical width or height will be easily mirrored.  They would probably also need to each match the bitmap fill file in width or height as well - otherwise the fill might get cropped before it can match it’s mirror image.

[lua]

– fillSize is the size of the bitmap texture file 512 x 512 in this case.

object.fill.scaleX = fillSize/object.width

object.fill.scaleY = fillSize/object.height

[/lua]

I’ll think about ways to normalize this that won’t require a massive rewrite.  I’ll keep it stewing on the backburner for now . . . 

@spork a visualisation would really help here?

I use multiple polygons and apply shaders to those polygons and they play nicely together.

Each “water tile” is a polygon and each has a texture applied and a shader to animate the water.

just negate it:

object.fill.scaleX = -fillSize/object.width

I think the solution will be to offset the fill of the landscapes with consideration to their height and width variations.

[lua] 

object.fill.x = offsetX

object.fill.y = offsetY [/lua]

That is some math I’m going to save for another day.

The suggestions for -xScale and -fillSize were great but since variation in each landscape’s dimensions will lead to a different offset of the fill, the great mirroring suggestions don’t solve that more basic problem that I failed to take into account - landscape height and width variability (with regard to texture wrapping).

I’m attaching an image to illustrate

texture_wrap_524.gif

A. texture is applied to a polygon with a wrap (ignore the green “grass”)

B. In the game environment, when two landscapes meet a hard line between the textures forms

C. and D. If the scaling is identical the textures wrap beautifully but if the textures vary in scaling (like the landscapes) the smooth wrap is lost

E.   A landscape is generated and paired with it’s twin (F.)  They have identical scaling but a hard line forms where they meet.

G.  Mirroring the bottom landscape visual blends the textures of the two landscapes - removing the hard line.

Rather and doing all the math to figure out the varying offset values, I might just normalize the landscapes somehow - keeping all the landscapes variations but capping (or expanding) them to a predictable height and width that corresponds to the base texture file.

OK, I solved this by normalizing the landscapes so that the overall dimensions of each landscape are identical.  At some point I will try to do the mathematical fix and figure out the best way to adjust the fill x and y.

Thanks @nick_sherman, @davebollinger, @sgs for the tips.  While the answer involved a more base problem that I had failed to identify, I learned some new tricks from playing around with your suggestions.  Now I have several answers to problems that don’t exist for me. . . yet!  :wink:

texture_wrap_fix.gif

Haven’t tried this but setting .xScale to -1 might work?

as per nick_sherman, either

object.xScale = -1

or

object.fill.scaleX = -1

(no idea why they didn’t keep consistent property naming)

Now that’s a nifty trick guys!  I’ve never tried that.  It worked fine on some little tests I did but, unfortunately, it doesn’t seem to work for my landscapes and I think it has something to do with the texture wrapping.  I’ll keep investigating.

Can you not use setDefault() to do this?

display.setDefault( “textureWrapX”, “repeat” )

display.setDefault( “textureWrapY”, “mirroredRepeat” )

https://docs.coronalabs.com/guide/graphics/repeatFill.html

@SGS 

I like that idea.  I forgot there was a mirrored repeat.  I only every us clamp and regular repeat.  I’ll give it a shot!

After further investigation, I have a feeling that both suggested methods would work, however, I think the real problem is that each landscape has it’s own fill scaling to keep the texture consistent so only two landscapes with an identical width or height will be easily mirrored.  They would probably also need to each match the bitmap fill file in width or height as well - otherwise the fill might get cropped before it can match it’s mirror image.

[lua]

– fillSize is the size of the bitmap texture file 512 x 512 in this case.

object.fill.scaleX = fillSize/object.width

object.fill.scaleY = fillSize/object.height

[/lua]

I’ll think about ways to normalize this that won’t require a massive rewrite.  I’ll keep it stewing on the backburner for now . . . 

@spork a visualisation would really help here?

I use multiple polygons and apply shaders to those polygons and they play nicely together.

Each “water tile” is a polygon and each has a texture applied and a shader to animate the water.

just negate it:

object.fill.scaleX = -fillSize/object.width

I think the solution will be to offset the fill of the landscapes with consideration to their height and width variations.

[lua] 

object.fill.x = offsetX

object.fill.y = offsetY [/lua]

That is some math I’m going to save for another day.

The suggestions for -xScale and -fillSize were great but since variation in each landscape’s dimensions will lead to a different offset of the fill, the great mirroring suggestions don’t solve that more basic problem that I failed to take into account - landscape height and width variability (with regard to texture wrapping).

I’m attaching an image to illustrate

texture_wrap_524.gif

A. texture is applied to a polygon with a wrap (ignore the green “grass”)

B. In the game environment, when two landscapes meet a hard line between the textures forms

C. and D. If the scaling is identical the textures wrap beautifully but if the textures vary in scaling (like the landscapes) the smooth wrap is lost

E.   A landscape is generated and paired with it’s twin (F.)  They have identical scaling but a hard line forms where they meet.

G.  Mirroring the bottom landscape visual blends the textures of the two landscapes - removing the hard line.

Rather and doing all the math to figure out the varying offset values, I might just normalize the landscapes somehow - keeping all the landscapes variations but capping (or expanding) them to a predictable height and width that corresponds to the base texture file.