Flip sprite horizontally
Posted: Wed Feb 04, 2026 4:40 pm
Hello, is there no native way to flip a sprite horizontally? At most with Transform?
Thanks!
Thanks!
http://www.purebasic.com
https://www.purebasic.fr/english/
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?
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()
ForEverCode: 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()
ForEverYes. 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...
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()
ForEver