Resize Spritesheet?
Blitz3D Forums/Blitz3D Programming/Resize Spritesheet?
| ||
Hi everybody! :) Can someone tell me how I can make it so I can get the total amount of frames in ANY image, and use that to save EACH sprite 1 by 1? and also to resize them to half of whatever they are, so that they are 1 tile, and not 2 tiles for 1 sprite. code: ; Resize Spritesheet ; Set Graphics Mode Graphics 800,600,0,2 Global maxframes=0 Global startinc=336 Global endinc=maxframes ; Randomize the random seed SeedRnd MilliSecs() ; Load an image to tile (your location might vary) gfx=LoadImage("042-King01.bmp") MaskImage gfx,255,255,255 Global bits = 0 ;size If bits < 8 Then bits = 8 If bits > 32 Then bits = 32 Global width=ImageWidth(gfx) Global height=ImageHeight(gfx) ; Size it randomly from original width/height to imagewidth-bits, imageheight-bits of frame both x and y ResizeImage gfx,width-bits,height-bits ; Wait for ESC to hit While Not KeyHit(1) Cls startinc = startinc+1 If startinc > endinc Then startinc = endinc DrawImage gfx,0,0 Text GraphicsWidth()/2,GraphicsHeight()/2,"bits:"+bits,1,1 Text GraphicsWidth()/2,GraphicsHeight()/2-20,"startinc:"+startinc,1,1 saveit=1 If saveit Text GraphicsWidth()/2,GraphicsHeight()/2-40, "saving",1,1 texton=1 EndIf If texton For x = 0 To maxframes SaveImage gfx,startinc+".bmp",x If FileType(startinc+".bmp")=1 saved=1 EndIf Next EndIf If saved Text GraphicsWidth()/2,GraphicsHeight()/2-60, "saved",1,1 Else Text GraphicsWidth()/2,GraphicsHeight()/2-60, "wasnt saved",1,1 EndIf Flip Wend ANY help is GREATLY appreciated! :) DS PS there are 16 frames in the king image. |
| ||
Can someone tell me how I can make it so I can get the total amount of frames in ANY image, and use that to save EACH sprite 1 by 1? serious answer: human eyes a computer cannot tell you what is in the image it can only display it by reading the bytes and putting them in the corresponding pixel coords eg loading it in paint or whatever and there may be numerous directions which count as different anim strips secondly if this is a catch all program then you have way too many variables between artists and sprite sheets, nowadays you can have numerouse sprite sheets for each type of move or character, but in the old days you could have one .dat file that used to be a dpaint or similar st/amiga paint file and that could have sprites that were 8*8, 16*16 and 32*32 and if you read the sprites that were 32*32 in as 8*8 you can imagine the results thirdly do you mean you want to take a sprite sheet apart and save it out as single images? if yes thats a bit of a waste of drive clusters if you ask me |
| ||
yes. i want to find the max # of frames dependant on w/e size the picture is. i want to then save each frame as a sprite |
| ||
knowing the horizontal and vertical of the jpg etc is only one part of it sure you can divide a blank 1280*1024 image easily but if you are working on someones sprite sheet then you yourself need to know the boundaries of the sprites in question ive seen bmp's with numerous sprite sizes, handy for reducing file lengths but problematic for what you want eg a walking character a jeep with no wheels and wheel sprites bullets and powerup boxes all different sizes, but the coder knows where the walking frames are. if you were to just load that same image in with loadanimimage it would totally cut up the jeep you would have to run multiple passes on the file to access the jeep and then the wheel sprites and pair them up |
| ||
o no. its spritesheets that contain 1 character or item only in different positions mate. :) I'm looking to split the horizontal and vertical parts of the image into 1 tile sprites instead of 2. here, i'll upload the image so u can see. the reason being that its 2 tiles is that each sprite is bigger than 32x32. which is not right for some engines. thanks! DS |
| ||
Here is the pic:![]() |
| ||
The only way of doing this, is to scan the entire image and checked for a full solid line of background colour vertically and horizontal, then find out, based on these dimensions, the closest number that will divide into the dimensions. Apart from doing it that way, it's impossible to do, without knowing the sprites dimensions. |
| ||
well, i do happen to know the size of the sprites. its isometric 3d rpgmaker vx size :P |
| ||
Can someone tell me how I can make it so I can get the total amount of frames in ANY image gave me the impression you were looking at any and all sprite sheets not just the king one listed in the code and as i said "eyes" 16 frames there ;) or 4 frames for 4 directions |
| ||
then why in my code does it not let me use ANYTHING in maxframes but "0" ? :S o wait. dumb question. i didnt load it with loadanimimage did i? :D |
| ||
tbh i didnt even look at the code, i just saw the king sprite file part of me was thinking "is he trying to reinvent loadanimimage?" |
| ||
LOL! XD So what am i doing wrong, can u AT LEAST show me what line i messed up and a possible way to fix it? |
| ||
new code: still wont work.. ; Resize Spritesheet ; Set Graphics Mode Graphics 800,600,0,2 Global maxframes=16 Global startinc=336 Global endinc=maxframes ; Randomize the random seed SeedRnd MilliSecs() ; Load an image to tile (your location might vary) gfx=LoadAnimImage("042-King01.bmp",40,40,1,maxframes) MaskImage gfx,255,255,255 Global bits = 32 ;size If bits < 8 Then bits = 8 If bits > 32 Then bits = 32 Global width=ImageWidth(gfx) Global height=ImageHeight(gfx) ; Size it randomly from original width/height to imagewidth-bits, imageheight-bits of frame both x and y ResizeImage gfx,width-bits,height-bits ; Wait for ESC to hit While Not KeyHit(1) Cls startinc = startinc+1 If startinc > endinc Then startinc = endinc DrawImage gfx,0,0 Text GraphicsWidth()/2,GraphicsHeight()/2,"bits:"+bits,1,1 Text GraphicsWidth()/2,GraphicsHeight()/2-20,"startinc:"+startinc,1,1 saveit=1 If saveit Text GraphicsWidth()/2,GraphicsHeight()/2-40, "saving",1,1 texton=1 EndIf If texton For x = 0 To maxframes SaveImage gfx,startinc+".bmp",x If FileType(startinc+".bmp")=1 saved=1 EndIf Next EndIf If saved Text GraphicsWidth()/2,GraphicsHeight()/2-60, "saved",1,1 Else Text GraphicsWidth()/2,GraphicsHeight()/2-60, "wasnt saved",1,1 EndIf Flip Wend |
| ||
can someone tell me what im doing wrong here? u can keep the spritesheet if u want |
| ||
Your asking 3 questions at the beginning of your post. What's not working. |
| ||
i cant get it to load any frames from the loadanimimage. |
| ||
well i dusted off my blitz folder and C+P your code and resaved the png as a bmp as i cant remember if vanilla blitz supports png (edit the dust was layered thick ;) ) fixied the loadanimimage info you have gfx=LoadAnimImage("042-King01.bmp",40,40,1,maxframes) whereas the image is clearly 32*48 per sprite or gfx=LoadAnimImage("042-King01.bmp",32,48,0,maxframes) (edit ive changed mine to read 0 as the start frame 1 is the 2nd) if the code worked and you did get 16 frames out you would have cut the image all wrong, too much of the next and not enough of the legs. that and its asking for the image to be 160 pixels wide not 128 next i got a mav at the resize portion of the code. now im not going to look too closely at this code RTM as im unsure since your first post as to what you truely want this code to do. your first post read like you wanted to load in any bmp sprite sheet, infact you did say "ANY image" hence my reply. i know you want to resize in blitz the king image, if this is a one off i would have just used paint program of choice and just resized. now after re reading this line I'm looking to split the horizontal and vertical parts of the image into 1 tile sprites instead of 2. do you mean you want to split the legs from the body and have them as individual elements? seeing as there are only 16 images and 4 frames per direction it seems moot again another part reads like you would prefer the image to be 1*16 and not 4*4 as it is, again that is totally asthetic and easily done in paint. |
| ||
no, i want to split the 16 different king's graphic into 16 different ppl :) u know: X = King pic here |X|X|X|X| |X|X|X|X| |X|X|X|X| |X|X|X|X| thanks! DS |
| ||
im hacking away with mspaint (i do have others but paint is quicker for me to do what i want tbh) and will slap up some visual examples of what im on about edit: should have refreshed before posting no, i want to split the 16 different king's graphic into 16 different ppl :) u know: X = King pic here |X|X|X|X| |X|X|X|X| |X|X|X|X| |X|X|X|X| thanks! ok now im lost you want to display 16 different sprites in the same area as is occupied by the sprite sheet? (X=king is confusing when you then have all of em as X's) or you have 16 sprite sheets and you want to join them all together in one sprite sheet? if it is the latter, then you could do that in code (i did a mock up in paint its not hard just bothersome) infact that might be this code/thread thats bothersome ;) so you have king*16 queen*16 bla*16 bla*16 etc this if it is what i think you mean it keeps files down to a minimum, which is always a good thing f-in flicker resized everything but here is one image ![]() is it me or have they duplicated the 1st and 3rd frames of each movement? if so thats a waste of a frame there. its not a zoetrope (sp) so you can easily omit those and just use idle and walking looped cant help thinking ive seen the king in one of those final fantasy rom rip sites or something, but iir there are dozzens of similarly laid out sprite sheets that if it were legal to use would be better served in one file |
| ||
yes! EXACTLY! i need to create EXACTLY what is above because the program im using called xtremeworlds requires each sprite be an individual sprite. so can u take a look at my code and tell me what im doing wrong? |
| ||
erm well doing that image took me less than a minute in mspaint ;) the pink outline was originally to show what it would look like if you used the 40*40 cutter but it came in handy lining things up and only slightly over wrote some pixels ill have a gander when i get back from work, but if its only for the odd sprite and not a shed load then why code when you can manually do it |
| ||
Look at the readPixel and WritePixel comands. Use them to read the image pixels and write them onto a texture. |
| ||
well, gingertea. its not for just that spritesheet. its for all spritesheets LIKE that. |
| ||
So, each frame has a fixed width/height, but you need to know how much frames there are inside the imagestrip? I think that should be imagewidth / framewidth * imageheight / frameheight. So first, load the image width LoadImage, to find out it's width/height, calculate the framecount and then use LoadAnimImage. So something along the lines of this: |