Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Get Image in For Next Loop Not Working

Author
Message
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 5th Mar 2009 01:45 Edited at: 5th Mar 2009 01:49
Hey all, I have been having a problem with the get image command. I have a image which I wish to split up into 20 tiles wide by 15 tiles tall (32x32). My problem is that it is very annoying having a huge list of each individual Get Image command:



So, obviously if I need to split this image up, the most logical route would be to put this in a for next loop. Although, when I do this I get some interesting and varying results depending on the method:



This gives me an error saying that the image does not exist when i paste the tiles, however the highest tile I paste is of image number 525.



This results in an error saying that I have an illegal image area and therefore cannot copy.

Other results I have gotten from miscellaneous experimenting is a complete white background which all the tiles overhead and under are white. Another one is that I have had it paste only 2 different tiles (the wrong ones needless to say), and none of the others.

Is there something about this command that doesn't like the For loops? Or probably just the way I have it set up? I only ask because having to type out about 300 lines of get image img,l,t,r,b would be absolutely ridiculous. Any help on this matter would be greatly appreciated. Thanks

Just tried this:


This didn't give any good results either, just more errors about image area and the image not existing.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Mar 2009 09:01 Edited at: 5th Mar 2009 09:02
Your grabbing all sorts of crazy things there, it's your code I'm afraid, but we're here to help .

It looks like you are grabbing an image that is 160 high x 192 wide - but what to do is work out how many tiles you are using X and Y, then multiply that to get the grab area. So assuming you are grabbing 10x10 tiles, you just need to change the step value to suit the image:

img=520
For y=0 to 9
For x=0 to 9
xa=x*32
ya=y*32
xb=xa+32
yb=ya+32
get image img,xa,ya,xb,yb,1
inc img,1
next x
next y

So your X and Y step goes from 0 to 9, which is multiplied by 32 to give the image location start, add 32 to X and Y to get the second set of coords to grab, then grab it, and increase the grabbed image number (IMG) each time.


Health, Ammo, and bacon and eggs!
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 5th Mar 2009 15:03 Edited at: 5th Mar 2009 15:15
Hi Van, thanks, although I still get the same error message that it cannot grab image due to the area.... It's quite frustrating.

EDIT: Got it now, forgot to set current bitmap first. Thanks Van, that helped out a lot. Cut down on the would be ridiculous amounts of code.

Oh just one more thing, I noticed that the get image can be extremely slow. Especially when grabbing an entire sheet. Now, if I were to switch areas, say leave a house and go outside, therefore switching images, and having to get all new ones, is there a faster way? Should i get all images for a few close areas first or load as needed? Thanks....
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Mar 2009 17:15
It's usually best to grab everything you need first, like have a setup routine where you load all the images and grab them. That way you can standardize the tiles and use them anywhere, a lot of tiles would be used all over your map, so it's good to be able to put tiles anywhere without having to grab them or replace images.


Health, Ammo, and bacon and eggs!
The Viking
15
Years of Service
User Offline
Joined: 21st Oct 2008
Location: Asgard
Posted: 7th Mar 2009 00:24
Ok, thanks for that... Oh, one last question, thought I would try to continue here before asking in a new post. But is there a way to set a image to translucent, so that it's similar to the ghost command in 3D. Something like having an overcast affect the way the player looks and the ground so it looks like a shadow, or light that shines through a window to brighten sprites and tiles in that area? Thanks again.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 7th Mar 2009 01:09
Yeah, since one of the last updates you can set a parameter when loading the bitmap that retains alpha transparency. Alpha transparency and PNG images are a good way to go, then you can have shadows, soft edges and lighting effects to your hearts content.

Unfortunately it's undocumented, so as a guess I'd try:

LOAD BITMAP "bitmap.png",1,1


Health, Ammo, and bacon and eggs!

Login to post a reply

Server time is: 2024-03-28 15:18:28
Your offset time is: 2024-03-28 15:18:28