Hello, is there no native way to flip a sprite horizontally? At most with Transform?
Thanks!
Flip sprite horizontally
Re: Flip sprite horizontally
Yes. The backface culling was deactivated for sprites.PHP wrote: Wed Feb 04, 2026 4:40 pm Hello, is there no native way to flip a sprite horizontally? At most with Transform?
So you can use ZoomSprite() with negative height or width to flip vertically or horizontally.
However, you have to keep in mind that the sprite anchor is than on the other side, not on the left top corner.
Code: Select all
Enumeration
#Window
#Sprite
EndEnumeration
InitSprite()
OpenWindow(#Window, 0, 0, 300, 300, "Sprite", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window), 0, 0, 0)
SpriteQuality(#PB_Sprite_BilinearFiltering)
CreateSprite(#Sprite, 80, 80)
StartDrawing(SpriteOutput(#Sprite))
Box(0, 0, 80, 80, $303030)
Box(16, 16, 8, 48, $FFFFFF)
Box(24, 16, 24, 8, $FFFFFF)
Box(24, 32, 16, 8, $FFFFFF)
StopDrawing()
Define Vertex.d
Repeat
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
End
Case #Null
Break
EndSelect
ForEver
ClearScreen(0)
ZoomSprite(#Sprite, 80, 80)
DisplaySprite(#Sprite, 20, 20)
ZoomSprite(#Sprite, 80, -80)
DisplaySprite(#Sprite, 20, 200)
ZoomSprite(#Sprite, -80, 80)
DisplaySprite(#Sprite, 200, 20)
FlipBuffers()
ForEverPB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Re: Flip sprite horizontally
Crazy! Why isn't that mentioned in the help section?! 
Re: Flip sprite horizontally
Question: The mirroring works, but apparently doesn't work in FullHD without the two black pixel borders?
When I set it to -1920, the sprite disappears completely...
When I set it to -1920, the sprite disappears completely...
Code: Select all
Enumeration
#Window
#Sprite
EndEnumeration
InitSprite()
OpenWindow(#Window, 0, 0, 1920, 1080, "Sprite", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window), 0, 0, 0)
CreateSprite(#Sprite, 1920,1080)
StartDrawing(SpriteOutput(#Sprite))
Box(0, 0, 1920, 1080, RGB(255,0,0))
StopDrawing()
Repeat
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
End
Case #Null
Break
EndSelect
ForEver
ClearScreen(0)
ZoomSprite(#Sprite, -1918, 1080) ; flip horizontally
DisplaySprite(#Sprite, 1919, 0) ; works but left/right black border
FlipBuffers()
ForEverRe: Flip sprite horizontally
Yes. This is due to the optimization in DisplaySprite() which do not display the sprite if its position is outside the screen, and DisplaySprite() do not know, that it was zoomed negatively.PHP wrote: Thu Feb 05, 2026 5:50 pm Question: The mirroring works, but apparently doesn't work in FullHD without the two black pixel borders?
When I set it to -1920, the sprite disappears completely...
Instead, you can use TransformSprite() and define all 4 vertices (x,y) and then display it at 0,0:
Code: Select all
Enumeration
#Window
#Sprite
EndEnumeration
InitSprite()
OpenWindow(#Window, 0, 0, 1920, 1080, "Sprite", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window), 0, 0, 0)
CreateSprite(#Sprite, 1920,1080)
StartDrawing(SpriteOutput(#Sprite))
Box(0, 0, 960, 1080, RGB(255,0,0))
Box(960, 0, 960, 1080, RGB(192,0,0))
StopDrawing()
Repeat
Repeat
Select WindowEvent()
Case #PB_Event_CloseWindow
End
Case #Null
Break
EndSelect
ForEver
ClearScreen(0)
;TransformSprite(#Sprite, 0,0, 1920,0, 1920,1080, 0,1080) ; normal
TransformSprite(#Sprite, 1920,0, 0,0, 0,1080, 1920,1080) ; hor. fliped
DisplaySprite(#Sprite, 0, 0)
FlipBuffers()
ForEverPB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module

