Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Junkface on Fri 13/09/2013 09:29:33

Title: Dynamic sprites
Post by: Junkface on Fri 13/09/2013 09:29:33
Hi,

I'm making a game where I want to use dynamic sprites to change the appearance of objects a lot. I was hoping to do this with one function to create a different dynamic sprite for all the objects and other functions to then manipulate the dynamic sprite associated with whatever individual object is being worked with later, i.e. something like this (with [SceneryCurrent] representing the ID of the object being worked with):

Code (ags) Select

scale[SceneryCurrent] = DynamicSprite.CreateFromExistingSprite(object[SceneryCurrent].Graphic);
object[SceneryCurrent].Graphic=scale[SceneryCurrent].Graphic;


Code (ags) Select

scale[SceneryCurrent].Resize(FloatToInt(SpriteSizeX[SceneryCurrent]), FloatToInt(SpriteSizeY[SceneryCurrent]));


scale0, scale1, scale2, etc are already defined as dynamic sprites in the global variables section but when I try to compile I get the error "Undefined token 'scale' ". Is there some means of working with dynamic sprites in the way I'm attempting or will I need to resort to something like:

Code (ags) Select

if(SceneryCurrent==1){
  scale1.Resize(FloatToInt(SpriteSizeX[SceneryCurrent]), FloatToInt(SpriteSizeY[SceneryCurrent]));
}

if(SceneryCurrent==2){
  scale2.Resize(FloatToInt(SpriteSizeX[SceneryCurrent]), FloatToInt(SpriteSizeY[SceneryCurrent]));
}


I hope that's at least somewhat clear and would appreciate any advice anyone can give.

Thanks.
Title: Re: Dynamic sprites
Post by: Khris on Fri 13/09/2013 11:53:27
In order to use scale[some_value], you have to define an array of DynamicSprites, not individual ones called scale0, scale1, etc.

Put this in GlobalScript.asc, near the top:
Code (ags) Select
DynamicSprite *scale[40];
export scale;


Then add this line to GlobalScript.ash:
Code (ags) Select
import DynamicSprite *scale[40];

(And delete scale0, scale1, etc.)
Title: Re: Dynamic sprites
Post by: Junkface on Fri 13/09/2013 15:00:56
Ah, for some reason it hadn't occurred to me that I should treat dynamic sprites like the other variables - I feel quite silly  now. Thanks for the help.