Hi,
I have a linked list with 57 sprites, i can load them and display them, then when the user is pushes a button the window containing the windowed screen is closed and a new window is opened with a new windowed screen.
When i want to display some of the images from the linked list on the new screen, the sprites become invalid sprites. The list still had 57 items.
Sprites in a linked list
Re: Sprites in a linked list
No problem here so far:
Code: Select all
EnableExplicit
Global ImagesToLoad = 3
Global NewList Image()
Enumeration
#BackgroundWindow
#Button
#Window
EndEnumeration
Procedure CloseWindowEvent()
CloseWindow(#Window)
DisableGadget(#Button, #False)
EndProcedure
Procedure OpenImageWindow()
Protected newY
OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 150, 500, "Images", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
newY = 20
ForEach Image()
ImageGadget(#PB_Any, 10, newY, 128, 128, Image())
newY + 150
Next
BindEvent(#PB_Event_CloseWindow, @CloseWindowEvent())
EndProcedure
Procedure ButtonEvent()
OpenImageWindow()
EndProcedure
Procedure Loaded(Type, Filename$, ObjectId)
AddElement(Image())
Image() = ImageID(ObjectId)
If ListSize(Image()) = ImagesToLoad
OpenImageWindow()
EndIf
EndProcedure
Procedure LoadingError(Type, Filename$, ObjectId)
Debug Filename$ + ": loading error"
EndProcedure
OpenWindow(#BackgroundWindow, 0, 0, 0, 0, "", #PB_Window_Background)
ButtonGadget(#Button, 20, 20, 150, 50, "Open Image-Window")
DisableGadget(#Button, #True)
BindGadgetEvent(#Button, @ButtonEvent())
; Register the loading event before calling any resource load command
BindEvent(#PB_Event_Loading, @Loaded())
BindEvent(#PB_Event_LoadingError, @LoadingError())
LoadImage(#PB_Any, "http://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/128/apple-watch-blue-icon.png")
LoadImage(#PB_Any, "http://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/128/owl-icon.png")
LoadImage(#PB_Any, "http://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/128/snowman-icon.png")
Re: Sprites in a linked list
Tnx for your reply, i will try to shorten my code to the root cause of this problem then i will share it.Peter wrote:No problem here so far:
Code: Select all
EnableExplicit Global ImagesToLoad = 3 Global NewList Image() Enumeration #BackgroundWindow #Button #Window EndEnumeration Procedure CloseWindowEvent() CloseWindow(#Window) DisableGadget(#Button, #False) EndProcedure Procedure OpenImageWindow() Protected newY OpenWindow(#Window, #PB_Ignore, #PB_Ignore, 150, 500, "Images", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) newY = 20 ForEach Image() ImageGadget(#PB_Any, 10, newY, 128, 128, Image()) newY + 150 Next BindEvent(#PB_Event_CloseWindow, @CloseWindowEvent()) EndProcedure Procedure ButtonEvent() OpenImageWindow() EndProcedure Procedure Loaded(Type, Filename$, ObjectId) AddElement(Image()) Image() = ImageID(ObjectId) If ListSize(Image()) = ImagesToLoad OpenImageWindow() EndIf EndProcedure Procedure LoadingError(Type, Filename$, ObjectId) Debug Filename$ + ": loading error" EndProcedure OpenWindow(#BackgroundWindow, 0, 0, 0, 0, "", #PB_Window_Background) ButtonGadget(#Button, 20, 20, 150, 50, "Open Image-Window") DisableGadget(#Button, #True) BindGadgetEvent(#Button, @ButtonEvent()) ; Register the loading event before calling any resource load command BindEvent(#PB_Event_Loading, @Loaded()) BindEvent(#PB_Event_LoadingError, @LoadingError()) LoadImage(#PB_Any, "http://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/128/apple-watch-blue-icon.png") LoadImage(#PB_Any, "http://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/128/owl-icon.png") LoadImage(#PB_Any, "http://icons.iconarchive.com/icons/thesquid.ink/free-flat-sample/128/snowman-icon.png")
Re: Sprites in a linked list
This is always a good idea.Phil wrote:i will try to shorten my code to the root cause of this problem then i will share it.
Re: Sprites in a linked list
I found out my problem, it's not the linked list, it's the fact i close my screen/window/render en re-open it later, then the sprites become unusable it seems.Peter wrote:This is always a good idea.Phil wrote:i will try to shorten my code to the root cause of this problem then i will share it.
Code: Select all
;
Debug "use arrow keys to move"
OpenWindow(0, 0, 0, 800, 600, "")
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
AddWindowTimer(0, 1, 4000)
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(0, 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(0, x*2+xDelta*60, y*2+yDelta*60)
Next
Next
EndIf
FlipBuffers() ; continue the rendering
EndProcedure
Procedure WindowTimerEvents()
If EventWindow() = 0
UnbindEvent(#PB_Event_RenderFrame, @RenderFrame())
CloseScreen()
CloseWindow(0)
OpenWindow(0, 0, 0, 800, 600, "")
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)
BindEvent(#PB_Event_RenderFrame, @RenderFrame())
EndIf
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
AddWindowTimer(0, 1, 1000)
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())
BindEvent(#PB_Event_Timer, @WindowTimerEvents())
LoadSprite(0, "Data/Spider.png")
Re: Sprites in a linked list
Yes, the sprites are screen dependant. If you close it, you need to reload the sprites