SOLVED: Custom Save-Load GUI with multiple screenshots, ¿what I'm doing wrong?

Started by ArsCreativa, Tue 13/11/2018 20:01:26

Previous topic - Next topic

ArsCreativa

Hi, I have a little problem trying to do a custom save & load GUI.
The GUI has five slots, shown at the same time on screen. I want to show a screenshot of the saved game if the slot is used, or a generic empty box if it isn't.
So I have this code to populate the buttons used to store the screenshots, every time the GUI appears on screen, but I'm doing something wrong, because no image is shown in any button.
Any idea? Thanks!

Code: ags

function SaveGame()
{
  for (int i = 1; i < 6; i++)
  {
    buttonSprite = DynamicSprite.CreateFromSaveGame(i, 214, 120); // Reads the screenshot of the current savegame slot loop (1-5)
    if (buttonSprite == null)
    {
      buttonSprite = DynamicSprite.CreateFromExistingSprite(507); // If savegame doesn't exists, the image is a default empty box
    }
    // Assign the image to the current loop button
    if (i == 1)
    {
      BScreenshot1.NormalGraphic = buttonSprite.Graphic;
    }
    else if (i == 2)
    {
      BScreenshot2.NormalGraphic = buttonSprite.Graphic;
    }
    else if (i == 3)
    {
      BScreenshot3.NormalGraphic = buttonSprite.Graphic;
    }
    else if (i == 4)
    {
      BScreenshot4.NormalGraphic = buttonSprite.Graphic;
    }
    else if (i == 5)
    {
      BScreenshot5.NormalGraphic = buttonSprite.Graphic;
    }
    
    if (buttonSprite != null)
    {
      buttonSprite.Delete(); // Clears the dinamic sprite
    }
  } 
}


Crimson Wizard

This is a common misunderstanding: when you assign BScreenshot1.NormalGraphic = buttonSprite.Graphic; this does not copy sprite to the button, but makes button remember dynamic sprite's ID. You must keep the sprites so long as your buttons have to display them, and only delete sprites later when the GUI is no longer shown.
Of course, since you have 5 buttons, you need 5 dynamic sprite pointers (as separate variables, or stored in array), otherwise all buttons will be showing last created sprite.

Khris

Yes, you need something like this:

Code: ags
DynamicSprite *buttonSprite[5];

function SaveGame()
{
  for (int i = 0; i < 5; i++)
  {
    buttonSprite[i] = DynamicSprite.CreateFromSaveGame(i + 1, 214, 120); // Reads the screenshot of the current savegame slot loop (1-5)
    if (buttonSprite[i] == null) buttonSprite[i] = DynamicSprite.CreateFromExistingSprite(507); // If savegame doesn't exists, the image is a default empty box
    GUIControl *gc = gSavegames.Controls[i]; // assuming the buttons are controls 0 to 4
    Button *b = gc.AsButton;
    b.NormalGraphic = buttonSprite[i].Graphic;
  } 
}


SMF spam blocked by CleanTalk