Load Sprite Bank?
BlitzMax Forums/BlitzMax Beginners Area/Load Sprite Bank?
| ||
For my simple 2-D game, when a sprite needs to be a new picture, I loaded it from the hard drive. Like when the player's ship points to the right, I use this code: "PlayerShip = LoadImage("PlayerRight.png")". This method works, but I don't think it's the best way. Is there a way to load a bank of sprites at the start of a program? I searched the documentation, but haven't found anything about it so far. Thank you very much. |
| ||
There is no build-in-function to load several images at once in BMax. You can draw your image framed with different looks of playerShip in each frame and load it: Loadanimimage(...), then draw each ships view with: drawimage(img, x,y, frame), where frame then decides which look on the ship is currently displayed. This avoids at least several "Loadimages", if you don't like that. You might have a look into the codearchive whether there is a solution for you. For example there is a possibility shown to store all images one time within a bank, store the bank and furtherly load the bank at start of your app and reading the images during runtime out of the bank, which would make it not possible for your users anymore to access your images from HDD. See codearchive: Store media encrypted |
| ||
Check out Loadanimimage. If you have a strip of sprites i.e. a walking animation and each sprite in the strip is 32x32px the use loadanimimage at the begining of your code after the graphics command to load in the animstrip. The use drawimage with the frrame flag to change the frame of the images to be drawn. |
| ||
You can also load all the images at the beginning, and then change which image to draw based on direction.. pseudo code: Const LEFT = 1, RIGHT = 2, UP = 3, DOWN = 4 Select Direction Case LEFT DrawImage LImg,x,y Case RIGHT DrawImage RImg,x,y Case UP DrawImage UImg,x,y Case DOWN DrawImage DImg,x,y End Select |
| ||
OUCH! If they have to be loaded seperately, I would prefer it in an array: drawimage my_image[direction],x,y But loadanimimage is alot better. |
| ||
If the right image for a sprite is a mirror of the left, then you could also use rotation. I'm not sure if this is quicker or not though than loading them as single images or using Loadanimimage. |
| ||
if the left is a mirror of the right, you would actually use scale -1 in that axis direction, not rotation |
| ||
I didn't know that Dreamora... thanks for the tip |