Page 1 of 1

[Done] LoadSprite(#PB_Any): The Value is = [object Object]

Posted: Sun Feb 10, 2019 12:38 am
by Charlie
BTW: I'm using SpiderBasic 2.21 (x86)

I couldn't get a sprite to load for my application until I replaced MySprite = LoadSprite(#PB_Any, ...) with a static number: LoadSprite(0, ...)

Doing a little debugging, come to find out LoadSprite(#PB_Any, ...) returns " [object Object] ", so I'm thinking there is a little something wonky with using #PB_Any with LoadSprite to auto-generate an identifier for sprites.

Can anybody else duplicate ?

Re: LoadSprite(#PB_Any): The Value is = [object Object] ???

Posted: Tue Feb 12, 2019 10:41 am
by Fred
[Object object] is not wrong, but there is may be something odd with #PB_Any and LoadSprite(), I will take a closer look.

Re: LoadSprite(#PB_Any): The Value is = [object Object] ???

Posted: Fri Aug 30, 2019 8:46 am
by Fred
I just tested it, it seems to work, can anybody else confirm ?

Modified Sprite.sb example (the variable needs to be declared as Global indeed):

Code: Select all
;
; ------------------------------------------------------------
;
;   SpiderBasic - Sprite example file
;
;    (c) Fantaisie Software
;
; ------------------------------------------------------------
;

Debug "use arrow keys to move"

Global MySprite

OpenScreen(800, 600, 32, "400 sprites")

Procedure RenderFrame()
  Static x, y
 
  ClearScreen(RGB(0, 0, 0))

  If ExamineKeyboard()
   
    If KeyboardPushed(#PB_Key_Left)
      x-1
    ElseIf KeyboardPushed(#PB_Key_Right)
      x+1
    EndIf
   
    If KeyboardPushed(#PB_Key_Up)
      y-1
    ElseIf KeyboardPushed(#PB_Key_Down)
      y+1
    EndIf
   
    ; Reduce the sprite size before display
    ;
    ZoomSprite(0, 60, 60)
   
    ; Display 100 sprites !
    ;
    For xDelta = 0 To 9
      For yDelta = 0 To 9
        DisplayTransparentSprite(MySprite, x+xDelta*60, y+yDelta*60, 128) ; half transparency
      Next
    Next
   
    ; and another 100 sprites !
    ;
    For xDelta = 0 To 9
      For yDelta = 0 To 9
        DisplaySprite(MySprite, x*2+xDelta*60, y*2+yDelta*60)
      Next
    Next
   
  EndIf
 
  FlipBuffers() ; continue the rendering
EndProcedure


Procedure Loading(Type, Filename$)
  Static NbLoadedElements
 
  NbLoadedElements+1
  If NbLoadedElements = 1 ; Finished the loading of all images and sounds, we can start the applications
    FlipBuffers() ; start the rendering
  EndIf
EndProcedure


Procedure LoadingError(Type, Filename$)
  Debug Filename$ + ": loading error"
EndProcedure

; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
BindEvent(#PB_Event_RenderFrame, @RenderFrame())

MySprite = LoadSprite(#PB_Any, "Data/Spider.png")