Dynamic sprites

Started by Junkface, Fri 13/09/2013 09:29:33

Previous topic - Next topic

Junkface

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

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


Code: ags

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

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.

Khris

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
DynamicSprite *scale[40];
export scale;


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


(And delete scale0, scale1, etc.)

Junkface

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.

SMF spam blocked by CleanTalk