Identification PIXIJS of a sprite

Just starting out? Need help? Post your questions and find answers here.
falsam
Posts: 286
Joined: Mon May 05, 2014 9:49 pm
Location: France
Contact:

Identification PIXIJS of a sprite

Post by falsam »

Hello

How can I get the PixiJS object from a sprite?

For example, I'd like to perform a vertical and/or horizontal split, change the anchor point, etc. ...

More generally, I'd like to be able to use PIXIJS functionalities on these sprites.

I hope this is possible. Here's some basic code. For each sprite, I'd like to obtain its PIXIJS object.

Thanks in advance for your answers ;)

Code: Select all

EnableExplicit

;
; Evenement chargement des éléments de jeu (Images et sons)
Procedure Loading(Type, Filename.s, ObjectId)
  Protected MaxElements = 5
  Static NbLoadedElements 
  
  Debug "Load " + Filename
  NbLoadedElements + 1
  
  ; Est ce que tous les éléments sont chargés ?
  If NbLoadedElements = MaxElements 
    ; Full screen du background
    ZoomSprite(4, ScreenWidth(), ScreenHeight())
    
    ; Démarrage du rendu visuel
    Debug "■ Use the arrow keys"
    Debug "■ Space bar to change sprite" 
        
    FlipBuffers()
  EndIf
EndProcedure

;
; Evenement erreur de chargement d'un element de jeu
Procedure LoadingError(Type, Filename.s, ObjectId)
  Debug Filename + " : Loading error"
EndProcedure

; Affichage du rendu
Procedure RenderFrame()
  Static PosX = 100, PosY = 100
  Static CurrentSprite = 0
  
  ; Préparation de l'affichage
  ClearScreen(RGB(0, 0, 0))
  
  ; Affichage du background
  DisplaySprite(4, 0, 0)
  
  ; Evenements clavier
  If ExamineKeyboard()
    ; Gauche ou droite
    If KeyboardPushed(#PB_Key_Left)
      PosX-2
    ElseIf KeyboardPushed(#PB_Key_Right)
      PosX+2
    EndIf
    
    ; En haut ou en bas
    If KeyboardPushed(#PB_Key_Up)
      PosY-2
    ElseIf KeyboardPushed(#PB_Key_Down)
      PosY+2
    EndIf
    
    ; Changement de sprite
    If KeyboardReleased(#PB_Key_Space)
      CurrentSprite + 1
      If CurrentSprite = 4
        CurrentSprite = 0
      EndIf
    EndIf
    
    ; Affichage du personnage 
    DisplaySprite(CurrentSprite, PosX, PosY)
  EndIf
 
  
  ; Affichage du rendu actuel
  FlipBuffers()
EndProcedure

;- Start
;
; Ouverture d'une fenetre en plein écran
OpenWindow(0, 0, 0, 0, 0, "Basic example", #PB_Window_Background)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0))
SetFrameRate(60)


;
; Enregistrement des événements du jeu dans la file d'attente evenentielle 
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
BindEvent(#PB_Event_RenderFrame, @RenderFrame())

;
; Chargement des sprites
LoadSprite(0, "https://pixijs.com/assets/eggHead.png")    ;Sprite 0
LoadSprite(1, "https://pixijs.com/assets/flowerTop.png")  ;Sprite 1
LoadSprite(2, "https://pixijs.com/assets/helmlok.png")    ;Sprite 2
LoadSprite(3, "https://pixijs.com/assets/skully.png")     ;Sprite 3
LoadSprite(4, "https://pixijs.com/assets/bg_rotate.jpg")  ;Background


➽ Windows 11 - jdk-11.0.2 - SB 3.00 - Android 15
https://falsam.com

Sorry for my poor english
Fred
Site Admin
Posts: 1820
Joined: Mon Feb 24, 2014 10:51 am

Re: Identification PIXIJS of a sprite

Post by Fred »

There is no easy access to PIXI sprite, as it's handled in the DisplaySprite() routine, because unless other GFX API, you need one sprite per display, so it was needed to do it dynamically. But if you think that some built-in PIXIJS functions could be useful, feel free to post a command list with args !
Post Reply