It is currently Sat Dec 16, 2017 7:42 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: TransformSprite
PostPosted: Sat Feb 04, 2017 5:09 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Dec 23, 2009 3:26 pm
Posts: 164
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


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite
PostPosted: Mon Feb 06, 2017 4:28 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Aug 19, 2003 11:36 am
Posts: 1377
Location: Doubs - France
Code:
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/


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite
PostPosted: Tue Feb 07, 2017 7:24 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Dec 23, 2009 3:26 pm
Posts: 164
Comtois wrote:
Code:
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

thank you very much!

_________________
poor English...

PureBasic & Delphi & VBA


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite
PostPosted: Tue Feb 07, 2017 7:44 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jan 10, 2008 1:30 pm
Posts: 1125
Location: Germany, Glienicke
@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.

_________________
ImageImage


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite
PostPosted: Tue Feb 07, 2017 9:12 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Apr 30, 2009 5:23 pm
Posts: 203
Location: Côtes d'Azur, France
Code de thyphoon from an old topic...
Press Space to flip the sprite.
It should be native in pb...
Code:
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: TransformSprite
PostPosted: Tue Feb 07, 2017 11:20 am 
Offline
Addict
Addict
User avatar

Joined: Sat Feb 19, 2005 2:46 pm
Posts: 1684
Location: Pas-de-Calais, France
Modified to compile on x64 and x86
Code:
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

_________________
Prehistoric games - Bobble Puzzle, Purebreaker 3 ~> http://djes.free.fr


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Baidu [Spider] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye