Flip sprite

Sujets variés concernant le développement en PureBasic
Avatar de l’utilisateur
microdevweb
Messages : 1798
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Flip sprite

Message par microdevweb »

Bonjour à tous,

Je trouve quand même vraiment malheureux qu'après autant d'année Freed n'aie toujours pas implémenté une fonction pour faire un flip d'un sprite.

Si vous avez des solutions je suis preneur
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Avatar de l’utilisateur
Ar-S
Messages : 9472
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Flip sprite

Message par Ar-S »

Avec les machines d'aujourd'hui ce n'est pas très important coté ressources mais en amont ça éviterait tout de même de se faire une symétrie de ses images et/ou de clipspriter ses spriteSheets à gogo. Je suis en plein dedans pour un petit contest halloween. :)
Image
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
Thyphoon
Messages : 2697
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

Re: Flip sprite

Message par Thyphoon »

microdevweb a écrit :Bonjour à tous,

Je trouve quand même vraiment malheureux qu'après autant d'année Freed n'aie toujours pas implémenté une fonction pour faire un flip d'un sprite.

Si vous avez des solutions je suis preneur
Je suis tout a fait d'accord... il manque quelques trucs pour les sprites de base.. c'est dommage ... :cry:
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: Flip sprite

Message par Ollivier »

TransformSprite() gère ça bien pourtant...

Et, par hasard, ZoomSprite avec un coefficient négatif...

Je ne comprends pas votre demande...
Avatar de l’utilisateur
Thyphoon
Messages : 2697
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

Re: Flip sprite

Message par Thyphoon »

Ollivier a écrit :TransformSprite() gère ça bien pourtant...

Et, par hasard, ZoomSprite avec un coefficient négatif...

Je ne comprends pas votre demande...
ça fonctionne avec transFormSprite() ? faut que je reteste, car avant ça fonctionnait uniquement en faisant une bidouille en assembleur pour activer le fait que si on retourne le sprite que ce ne soit pas transparent. 8O
boby
Messages : 261
Inscription : jeu. 07/juin/2007 22:54

Re: Flip sprite

Message par boby »

@microdevweb je suis plutot d'accord avec toi, mais en attendant, une solution alternative : http://forums.purebasic.com/english/vie ... 16&t=67701
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: Flip sprite

Message par Ollivier »

Mon code source est dans la section Hors Sujet, tout comme un tas d'autres données, références et autres, qui représentent un tas d'heures d'investissement, réduit à la seule propriété de Fred, tout comme à ceux qui ont téléchargé ces mêmes codes sources, données et références. Donc c'est de mémoire que j'informe qu'effectivement TransformSprite() cache systématiquement les faces retournées.

Seulement, Idle m'avait mailé les possibilités de TransformSprite() : un quad affiché en forme de Z permet d'activer l'effet de perspective du texturing sous Windows seulement.

Donc le FlipSprite() est effectivement impossible avec TransformSprite().

Et un coefficient négatif avec ZoomSprite() ? Ça marche?
Avatar de l’utilisateur
microdevweb
Messages : 1798
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: Flip sprite

Message par microdevweb »

@boby,

Le problème avec ce code est qu'il ne fonctionne que dans le cas on l'on flip en horizontal et vertical

Exemple avec ce code (flèche droite flip vertical haut horizontal)

Code : Tout sélectionner

; ***********************************************************************
; Project            : FLIP SPRITE
; ORIGINAL CODE FROM : Comtois
; UPGRADER BY        : microdevWeb
; ***********************************************************************
; GAME INITIALIZE
#MAIN_FORM = 0
If Not InitSprite()
  MessageRequester("Game engine error","Cannot run sprite engine",#PB_MessageRequester_Error)
  End
EndIf
If Not InitKeyboard()
  MessageRequester("Game engine error","Cannot run keyboard engine",#PB_MessageRequester_Error)
  End
EndIf
If Not OpenWindow(#MAIN_FORM,0,0,800,600,"Flappy bird",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  MessageRequester("Window engine error","Cannot open window",#PB_MessageRequester_Error)
  End
EndIf
If Not OpenWindowedScreen(WindowID(#MAIN_FORM),0,0,800,600)
  MessageRequester("Game engine error","Cannot open window screen",#PB_MessageRequester_Error)
  End
EndIf
If Not InitSound()
  MessageRequester("Game engine error","Cannot init sound engine",#PB_MessageRequester_Error)
  End
EndIf
; FLIP FUNCTION
Procedure flipSprite(sprite,vertical.b,horizontal.b)
  ; default sprite vertices
  ; X1         X2
  ;   ---------
  ;   |      /|
  ;   |    /  |
  ;   |  /    |
  ;   |/      |
  ;   ---------
  ; x4         x3
  Protected w = SpriteWidth(sprite),
            h = SpriteHeight(sprite),
            x1 = 0,
            y1 = 0,
            x2 = w,
            y2 = 0,
            x3 = w,
            y3 = h,
            X4 = 0,
            y4 = h
  If vertical 
    ; X4         X3
    ;   ---------
    ;   |      /|
    ;   |    /  |
    ;   |  /    |
    ;   |/      |
    ;   ---------
    ; x1         x2
    x1 = 0 
    y1 = h
    x2 = 0
    y2 = h
    x3 = w
    y3 = 0
    X4 = 0 
    y4 = 0
  EndIf
  If horizontal 
    ; X2         X1
    ;   ---------
    ;   |      /|
    ;   |    /  |
    ;   |  /    |
    ;   |/      |
    ;   ---------
    ; x3         x4
    x1 = w 
    y1 = 0
    x2 = w
    y2 = 0
    x3 = 0
    y3 = h
    X4 = w 
    y4 = h
  EndIf
  If vertical And horizontal
    ; X3         X4
    ;   ---------
    ;   |      /|
    ;   |    /  |
    ;   |  /    |
    ;   |/      |
    ;   ---------
    ; x2         x1
    x1 = w 
    y1 = h
    x2 = 0
    y2 = h
    x3 = 0
    y3 = 0
    X4 = w 
    y4 = 0
  EndIf
;   TransformSprite(1,167,34,0,34,0,0,167,0)
  TransformSprite(sprite,x1,y1,x2,y2,x3,y3,x4,y4)          
EndProcedure
#PB_SPRITE = 0
; load pureBasic Sprite
LoadSprite(#PB_SPRITE, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")
Global gEvent,gExit.b,gHorizontal.b,gVertical.b,gKeyPushed.b
Repeat  ; game loop
  Repeat ; window loop
    gEvent = WindowEvent()
    If gEvent = #PB_Event_CloseWindow
      gExit = #True ; exit to game loop
      Break         ; exit to window loop
    EndIf
  Until gEvent = 0
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    gExit = #True ; exit to game loop
  EndIf
  If KeyboardPushed(#PB_Key_Up) And Not gKeyPushed
    ; reverse horizontal flip
    gHorizontal =  ~ gHorizontal
    gKeyPushed = #True
  EndIf
  If KeyboardPushed(#PB_Key_Right) And Not gKeyPushed
    ; reverse vertical flip
    gVertical = ~ gVertical
    gKeyPushed = #True
  EndIf
  If KeyboardReleased(#PB_Key_All)
    gKeyPushed = #False
  EndIf
  ClearScreen(0)
  flipSprite(#PB_SPRITE,gVertical,gHorizontal)
  DisplayTransparentSprite(#PB_SPRITE,100,100)
  FlipBuffers()
Until gExit

End

Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Avatar de l’utilisateur
microdevweb
Messages : 1798
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: Flip sprite

Message par microdevweb »

Ollivier a écrit : Et un coefficient négatif avec ZoomSprite() ? Ça marche?
Malheureusement non
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Avatar de l’utilisateur
microdevweb
Messages : 1798
Inscription : mer. 29/juin/2011 14:11
Localisation : Belgique

Re: Flip sprite

Message par microdevweb »

Voici un code qui fonctionne avec un gros bidouillage en asm qui désactive les faces cachée(pas de moi car je serais incapable de pondre ça)

Code : Tout sélectionner

; ***********************************************************************
; Project            : FLIP SPRITE
; ORIGINAL CODE FROM : Comtois/thyphoon/djes
; UPGRADED BY        : microdevWeb
; ***********************************************************************
; GAME INITIALIZE
#MAIN_FORM = 0

If Not InitSprite()
  MessageRequester("Game engine error","Cannot run sprite engine",#PB_MessageRequester_Error)
  End
EndIf
If Not InitKeyboard()
  MessageRequester("Game engine error","Cannot run keyboard engine",#PB_MessageRequester_Error)
  End
EndIf
If Not OpenWindow(#MAIN_FORM,0,0,800,600,"Flappy bird",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
  MessageRequester("Window engine error","Cannot open window",#PB_MessageRequester_Error)
  End
EndIf
If Not OpenWindowedScreen(WindowID(#MAIN_FORM),0,0,800,600)
  MessageRequester("Game engine error","Cannot open window screen",#PB_MessageRequester_Error)
  End
EndIf
If Not InitSound()
  MessageRequester("Game engine error","Cannot init sound engine",#PB_MessageRequester_Error)
  End
EndIf

; setting flip asm
;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)

; FLIP FUNCTION
Procedure flipSprite(sprite,vertical.b,horizontal.b)
  ; default sprite vertices
  ; X1         X2
  ;   ---------
  ;   |      /|
  ;   |    /  |
  ;   |  /    |
  ;   |/      |
  ;   ---------
  ; x4         x3
  Protected w = SpriteWidth(sprite),
            h = SpriteHeight(sprite),
            x1 = 0,
            y1 = 0,
            x2 = w,
            y2 = 0,
            x3 = w,
            y3 = h,
            X4 = 0,
            y4 = h
  If vertical 
    ; X4         X3
    ;   ---------
    ;   |      /|
    ;   |    /  |
    ;   |  /    |
    ;   |/      |
    ;   ---------
    ; x1         x2
    x1 = 0 
    y1 = h
    x2 = w
    y2 = h
    x3 = w
    y3 = 0
    X4 = 0 
    y4 = 0
  EndIf
  If horizontal 
    ; X2         X1
    ;   ---------
    ;   |      /|
    ;   |    /  |
    ;   |  /    |
    ;   |/      |
    ;   ---------
    ; x3         x4
    x1 = w 
    y1 = 0
    x2 = 0
    y2 = 0
    x3 = 0
    y3 = h
    X4 = w 
    y4 = h
  EndIf
  If vertical And horizontal
    ; X3         X4
    ;   ---------
    ;   |      /|
    ;   |    /  |
    ;   |  /    |
    ;   |/      |
    ;   ---------
    ; x2         x1
    x1 = w 
    y1 = h
    x2 = 0
    y2 = h
    x3 = 0
    y3 = 0
    X4 = w 
    y4 = 0
  EndIf
  TransformSprite(sprite,x1,y1,x2,y2,x3,y3,x4,y4) 
;   TransformSprite(sprite,w,0,0,0,0,h,w,h)
EndProcedure
#PB_SPRITE = 0
; load pureBasic Sprite
LoadSprite(#PB_SPRITE, #PB_Compiler_Home + "examples/sources/Data/PureBasic.bmp")

Global gEvent,gExit.b,gHorizontal.b,gVertical.b,gKeyPushed.b
Repeat  ; game loop
  Repeat ; window loop
    gEvent = WindowEvent()
    If gEvent = #PB_Event_CloseWindow
      gExit = #True ; exit to game loop
      Break         ; exit to window loop
    EndIf
  Until gEvent = 0
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Escape)
    gExit = #True ; exit to game loop
  EndIf
  If KeyboardPushed(#PB_Key_Right) And Not gKeyPushed
    ; reverse horizontal flip
    gHorizontal =  ~ gHorizontal
    gKeyPushed = #True
  EndIf
  If KeyboardPushed(#PB_Key_Up) And Not gKeyPushed
    ; reverse vertical flip
    gVertical = ~ gVertical
    gKeyPushed = #True
  EndIf
  If KeyboardReleased(#PB_Key_All)
    gKeyPushed = #False
  EndIf
  ClearScreen(0)
  flipSprite(#PB_SPRITE,gVertical,gHorizontal)
  DisplayTransparentSprite(#PB_SPRITE,100,100)
  FlipBuffers()
Until gExit

End

Mais une chose aussi élémentaire qu'un flip devrait faire partie des commande de pureBasic
Dernière modification par microdevweb le lun. 29/oct./2018 15:33, modifié 1 fois.
Windows 10 64 bits PB: 5.70 ; 5.72 LST
Work at Centre Spatial de Liège
Ollivier
Messages : 4190
Inscription : ven. 29/juin/2007 17:50
Localisation : Encore ?
Contact :

Re: Flip sprite

Message par Ollivier »

A plus les amis.
Avatar de l’utilisateur
SPH
Messages : 4722
Inscription : mer. 09/nov./2005 9:53

Re: Flip sprite

Message par SPH »

microdevweb a écrit :Je trouve quand même vraiment malheureux qu'après autant d'année Freed n'aie toujours pas implémenté une fonction pour faire un flip d'un sprite.
+1

et egalement, "spriter" un sprite !!
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
Ar-S
Messages : 9472
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Flip sprite

Message par Ar-S »

SPH a écrit :et egalement, "spriter" un sprite !!
Heu :?: ça veut dire quoi spriter un sprite...
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
SPH
Messages : 4722
Inscription : mer. 09/nov./2005 9:53

Re: Flip sprite

Message par SPH »

Ar-S a écrit :
SPH a écrit :et egalement, "spriter" un sprite !!
Heu :?: ça veut dire quoi spriter un sprite...
Dessiner un sprite dans un sprite. Avec ca, bonjour les effets speciaux !! 8)
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
boby
Messages : 261
Inscription : jeu. 07/juin/2007 22:54

Re: Flip sprite

Message par boby »

Code : Tout sélectionner

StartDrawing(SpriteOutput())
???
Verrouillé