Arrays of animated images, is it possible?
Monkey Forums/Monkey Programming/Arrays of animated images, is it possible?
| ||
I am working on a project that has several on screen buttons that can be pressed at any time. I have set up an array that I am using to store the current status of the button (if it is pressed or not) so they can interact in other parts of the program. my problem is I have 10 buttons to draw and the frame of the animation to draw (either pressed or not) is stored in another variable. What I basically want to do is have an array of images with 4 frames of animation on each image and then draw the correct image with a command something like DrawImage buttonimages[a], but_pos_x[a], but_pos_y[a] - y_pos, 0, 1, 1, button_status[a] where a is a loop to cover each button, but_pos_x and y is an array for each buttons draw position, button_status is an array holding the status of each button (up or down), and buttonimages[a] is the array of images but they are not single frame, they are multi frame and this is the code that doesnt work. Is there any way of doing this without having different names for each button image Thanks Gary |
| ||
I don't use frames myself but I don't see anything wrong with the above, assuming button_status[ a ] is the frame you want to draw. I suspect the error is somewhee else. |
| ||
Hi Gerry I am setting up the array with Global buttonimages:Image[] and trying to load the images with buttonimages[0] = LoadImage("start.png", but_size_x[0], but_size_y[0], 4) But this gives me an monkey run time error, array index out of range. Do I need to dim the image array somewhere? Gary |
| ||
Gary, I think you are supposed to do something like [monkeycode] Global buttonimages:Image[X] [/monkeycode] where X is the array size. Or use later in the code: [monkeycode] buttonimages = buttonimages.Resize(X) [/monkeycode] |
| ||
Yes! Arrays must always be dimensioned before you put stuff in them. You need something like: buttonImages = New Image[ nButtons ] |
| ||
Cheers Gerry, that's solved the problem, thanks |