Just starting out? Need help? Post your questions and find answers here.
Phil
 
Posts: 2
Joined: Thu Oct 10, 2019 7:49 pm

Sprites in a linked list

by Phil Thu Oct 10, 2019 7:52 pm

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.
User avatar
Peter
 
Posts: 625
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Sprites in a linked list

by Peter Thu Oct 10, 2019 9:35 pm

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")
Phil
 
Posts: 2
Joined: Thu Oct 10, 2019 7:49 pm

Re: Sprites in a linked list

by Phil Sat Oct 12, 2019 3:53 pm

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")


Tnx for your reply, i will try to shorten my code to the root cause of this problem then i will share it.
User avatar
Peter
 
Posts: 625
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: Sprites in a linked list

by Peter Sat Oct 12, 2019 4:09 pm

Phil wrote:i will try to shorten my code to the root cause of this problem then i will share it.

This is always a good idea. ;)
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 3 guests