Help loading an number of images into an array.

BlitzMax Forums/BlitzMax Beginners Area/Help loading an number of images into an array.

fischer(Posted 2009) [#1]
I'm trying to load a series of button images into an array:


Why is this giving me a
Compile Error: Expecting expression but encountered ':'
Build Error: failed to compile C:/Program Files/BlitzMax/SImVillage/BArbarian Kingdoms.bmx
when I try to load an image into an array?

This is the line that craps out:
Global MktButu[0]:TImage = LoadImage(LoadBank("AppleMkt0.png"))
I defined the array earlier
as
Global MktButU[6]

If I'm totally off, can anyone suggest a good way to load a series of images into an array?
TIA

Bringing joy to the world one pixel at a time...


plash(Posted 2009) [#2]
' Creating the array to store 6 images
Global MktButU:TImage[6]

' Set the images in the array (remember when you set the position in an array it is zero-based)
MktButU[0] = LoadImage(LoadBank("AppleMkt0.png"))
'...
MktButU[5] = LoadImage(LoadBank("etc!"))


EDIT: Brucey responded to your other thread: http://www.blitzbasic.com/Community/posts.php?topic=83295#939936

Try to keep BlitzMax questions in BlitzMax forum sections ;)
Makes them easier to sift out from all the nonsense that goes on in the General Discussion area.


Arowx(Posted 2009) [#3]
Just out of interest why are you using LoadBank within LoadImage?


fischer(Posted 2009) [#4]
Ah, interesting you should ask. It was a snippet of code that I used where I loaded a 2 frame animation, and ultimately am planning to change the frame number to change the animation state of the button. I thought it would be a good way to 'clean up' my code a bit. I'm already loading around 40 individual images in my game, and I expect I'm going to need to load at least 60 more. A lot of these are buttons, and hit states.

I really appreciate the help, fellas

Thanks!


Htbaa(Posted 2009) [#5]
Wouldn't it be easier to use a spritesheet and put the animation sequences (frame numbers) inside an array?


fischer(Posted 2009) [#6]
Most likely, I trust you know better. I'm a complete noob. How would I create a spritesheet? COuld you post a code snippet?
Much appreciated.


plash(Posted 2009) [#7]
I think Htbaa means you should make an animation strip.. an image with frames/cells.. etc.

It would probably be easier to have TImage manage your image set rather than through arrays.


fischer(Posted 2009) [#8]
OH, right. I have been trying that, but I'm still not clear on the collision routines, I've been able to get my buttons registering mouse collisions, but not as animated images yet. Only when I pass different single images off.


Htbaa(Posted 2009) [#9]
Easiest way to do collision detection between 2 images, and animated images, is using:

ImagesCollide2(image1:TImage,x1,y1,frame1,rot1#,scalex1#,scaley1#,image2:TImage,x2,y2,frame2,rot2#,scalex2#,scaley2#)


This command allows you to check for collisions with any frame, rotation and scale. Just pass the frame number of the animation strip and the TImage animation strip and you're set.

Be careful with using:

ImagesCollide(image1:TImage,x1,y1,frame1,image2:TImage,x2,y2,frame2)


As in the added information it says: "ImagesCollide uses the current Rotation and Scale factors from the most previous call to SetScale and SetRotation to calculate at a pixel level if the two images collide. "

It can give you unexpected results if you didn't adjust the rotation and scale correctly. I always store a rotation value with my object that represents its rotation and use that value with ImageCollide2().