TransformSprite
TransformSprite
hello every one, if I want to flip a sprite in vertical or horizontal dircection, how to use the function TransformSprite? for example, a normal sprite is a left arrow, how to display it as a right arrow? thanks!
poor English...
PureBasic & Delphi & VBA
PureBasic & Delphi & VBA
Re: TransformSprite
Code: Select all
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sprite system can't be initialized", 0)
End
EndIf
;
; Now, open a 800*600 - 32 bits screen
;
If OpenScreen(800, 600, 32, "Sprite")
; Load our 16 bit sprite (which is a 24 bit picture in fact, as BMP doesn't support 16 bit format)
;
LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")
;Image = 168x35
CopySprite(0,1)
;Vertices
;3------4
;| |
;2------1
TransformSprite(1,167,34,0,34,0,0,167,0)
Repeat
; Inverse the buffers (the back become the front (visible)... And we can do the rendering on the back)
FlipBuffers()
ClearScreen(RGB(0,0,0))
; Draw our sprite
DisplaySprite(0, 100, 100)
DisplaySprite(1, 100, 200)
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error", "Can't open a 800*600 - 32 bit screen !", 0)
EndIf
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Re: TransformSprite
thank you very much!Comtois wrote:Code: Select all
If InitSprite() = 0 Or InitKeyboard() = 0 MessageRequester("Error", "Sprite system can't be initialized", 0) End EndIf ; ; Now, open a 800*600 - 32 bits screen ; If OpenScreen(800, 600, 32, "Sprite") ; Load our 16 bit sprite (which is a 24 bit picture in fact, as BMP doesn't support 16 bit format) ; LoadSprite(0, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp") ;Image = 168x35 CopySprite(0,1) ;Vertices ;3------4 ;| | ;2------1 TransformSprite(1,167,34,0,34,0,0,167,0) Repeat ; Inverse the buffers (the back become the front (visible)... And we can do the rendering on the back) FlipBuffers() ClearScreen(RGB(0,0,0)) ; Draw our sprite DisplaySprite(0, 100, 100) DisplaySprite(1, 100, 200) ExamineKeyboard() Until KeyboardPushed(#PB_Key_Escape) Else MessageRequester("Error", "Can't open a 800*600 - 32 bit screen !", 0) EndIf
poor English...
PureBasic & Delphi & VBA
PureBasic & Delphi & VBA
Re: TransformSprite
@Comtois:
Your code rotates the sprite! leonhardt want to flips the sprite.
But this is not possible with TransformSprite()!
You have to mirror the sprite before in the buffer.
Your code rotates the sprite! leonhardt want to flips the sprite.
But this is not possible with TransformSprite()!
You have to mirror the sprite before in the buffer.
PB 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: TransformSprite
Code de thyphoon from an old topic...
Press Space to flip the sprite.
It should be native in pb...
Press Space to flip the sprite.
It should be native in pb...
Code: Select all
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 800, 600, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0),WindowHeight(0))
;Disable Backface Culling
;from : http://www.forums.purebasic.com/english/viewtopic.php?f=16&t=43718
Define pd3d.IDirect3DDevice9
EnableASM
!extrn _PB_Screen_Direct3DDevice
!MOV dword EAX, [_PB_Screen_Direct3DDevice]
!MOV dword [v_pd3d],EAX
DisableASM
pd3d\SetRenderState(22,1)
pd3d\SetRenderState(7,0)
;-create sprite
CreateSprite(0,128,128)
StartDrawing(SpriteOutput(0))
Circle(32,32,64,#Red)
Box(64,32,64,32,#Green)
StopDrawing()
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event=0
ExamineKeyboard()
ClearScreen(#Black)
If KeyboardPushed(#PB_Key_Space)
TransformSprite(0,SpriteWidth(0),0,0,0,0,SpriteHeight(0),SpriteWidth(0),SpriteHeight(0))
Else
TransformSprite(0,0,0,SpriteWidth(0),0,SpriteWidth(0),SpriteHeight(0),0,SpriteHeight(0))
EndIf
DisplaySprite(0,32,32)
FlipBuffers()
Delay(1)
ForEver
There are 2 methods to program bugless.
But only the third works fine.
Win10, Pb x64 5.71 LTS
But only the third works fine.
Win10, Pb x64 5.71 LTS
Re: TransformSprite
Modified to compile on x64 and x86
Code: Select all
InitSprite()
InitKeyboard()
OpenWindow(0, 0, 0, 800, 600, "", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,WindowWidth(0),WindowHeight(0))
;Disable Backface Culling
;from : http://www.forums.purebasic.com/english/viewtopic.php?f=16&t=43718
Define pd3d.IDirect3DDevice9
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
EnableASM
!extrn _PB_Screen_Direct3DDevice
!MOV dword EAX, [_PB_Screen_Direct3DDevice]
!MOV dword [v_pd3d],EAX
DisableASM
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
EnableASM
!extrn PB_Screen_Direct3DDevice
!MOV dword EAX, [PB_Screen_Direct3DDevice]
!MOV dword [v_pd3d],EAX
DisableASM
CompilerElse
Debug "Unsupported processor"
End
CompilerEndIf
pd3d\SetRenderState(22,1)
pd3d\SetRenderState(7,0)
;-create sprite
CreateSprite(0,128,128)
StartDrawing(SpriteOutput(0))
Circle(32,32,64,#Red)
Box(64,32,64,32,#Green)
StopDrawing()
Repeat
Repeat
Event = WindowEvent()
Select Event
Case #PB_Event_CloseWindow
End
EndSelect
Until Event=0
ExamineKeyboard()
ClearScreen(#Black)
If KeyboardPushed(#PB_Key_Space)
TransformSprite(0,SpriteWidth(0),0,0,0,0,SpriteHeight(0),SpriteWidth(0),SpriteHeight(0))
Else
TransformSprite(0,0,0,SpriteWidth(0),0,SpriteWidth(0),SpriteHeight(0),0,SpriteHeight(0))
EndIf
DisplaySprite(0,32,32)
FlipBuffers()
Delay(1)
ForEver