Plugin programming: deciding if a sprite exists

Started by Kweepa, Sun 09/10/2005 16:07:34

Previous topic - Next topic

Kweepa

I want to step through all the sprites in the game from my plugin.
This is the code I have:
Code: ags

          // global
          int s = 0;

          // in on_key_press
          bool exists = true;
          do
          {
            s++;
            if (s > 1000) s = 0;
            exists = true;
            try
            {
              BITMAP *agsBitmap = engine->GetSpriteGraphic(s);
              if (!agsBitmap || agsBitmap->w <= 0) exists = false;
            }
            catch (...)
            {
              exists = false;
            }
          }
          while (!exists);


It seems that GetSpriteGraphic can return non-NULL for nonexistent sprites, so I added the try/catch block to catch an access violation in agsBitmap->w. Unfortunately at some point GetSpriteGraphic throws an exception which AGS catches - out of sprite cache bounds.

Is there an easier way to do what I want to do? I don't want to resort to telling the plugin what the valid sprites are.

Cheers!
Still waiting for Purity of the Surf II

Pumaman

There isn't an easy way to do this, no. I'm not sure why you'd need to iterate through every sprite in the game?

Kweepa

It's part of the Ags3d editor (or it will be, hopefully) - reassigning textures on the fly.
Still waiting for Purity of the Surf II

SMF spam blocked by CleanTalk