Log In  

Is there an easy way to flip sprites both horizontally AND/OR vertically via code?

P#11163 2015-06-07 03:58 ( Edited 2015-06-08 22:40)

I used this function in the river riddle to h flip sprites.
It only works for 8x8 but you can easily translate for other size or for flip vertical

function fspr(fr,ex,ey)
 for x=0,7 do
P#11172 2015-06-07 18:56 ( Edited 2015-06-07 22:56)

For horizontal flip, sspr() has a flip parameter flag but it does not seem to work. Maybe this will be fixed in v0.1.1.

Benjamin, a minor suggestion for your example: I think you should define sx and sy as local variables in order to avoid creating more costly global variables.

P#11179 2015-06-08 11:55 ( Edited 2015-06-08 15:55)

After some research in the forum, I have found this thread describing a direct way to flip a sprite horizontally: https://www.lexaloffle.com/bbs/?tid=1859

In short, there is an undocumented flip parameter to spr:

spr n x y [w h [flip]]

When flip is set to TRUE, it flips the displayed sprite.

    -- draw a 8x8 flipped sprite at pixel location (32,32)

    -- draw a 16x16 flipped sprite at pixel location (32,32)

Strangely, this extra parameter is documented for sspr but has no effect on it. So maybe it is just a documentation issue. Maybe Zep can comment about it.

Anyway, thanks to QuantumFlux42 for this trick.

P#11181 2015-06-08 13:11 ( Edited 2015-06-08 17:11)
:: zep

The sspr() behaviour in 0.1.0 is a bug in the implementation rather than a mistake in the docs.

0.1.1 has working fiip_h and flip_v parameters (for horizontal and vertical flipping), and also allows you to use negative target dimensions with sspr()

P#11191 2015-06-08 18:40 ( Edited 2015-06-08 22:40)

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2022-01-22 15:36:15 | 0.009s | Q:16