|
Post by Enzo on Mar 2, 2021 22:51:56 GMT
Any documents information of fileinfo$ function?
I'd like to open all items in folder and resave named at "A";numbervariable;".bmp" for faster loading.
|
|
|
Post by Rod on Mar 3, 2021 8:15:40 GMT
Before we get to file$ command can you post an example of a bmp that needs recoloured and resized. Are the background colours varied or do all the bmps have the same color? The problem here is if the image contains the background color. So if you have a black background and black within the image that’s harder to mask.
Also is this build a one off. I mean are you planning to distribute completed working bmp sprites or are you planning to build the sprites on the users platform? Normally you would distribute working sprites.
And explain more about resizing, all to the same size? Varied sizes?
|
|
|
Post by Enzo on Mar 3, 2021 18:44:37 GMT
Sorry, refer to the black pixels being converted to values of 1 stops any overlapping with mask and black, right now I parse each image 3 times.
|
|
|
Post by Enzo on Mar 4, 2021 0:44:01 GMT
Backtracking now, making a mapfile and turn into bmp image, for splitting up for some type of star tracking in game to a mini map display.
|
|
|
Post by Rod on Mar 4, 2021 15:23:31 GMT
I was trying to improve the masking code. The code works but comes with so many caveats that it is pretty much useless. The thing about sprites is that the original image MUST have a unique background. This code changes the main surrounding background to black and then replaces black in the central image with near black then creates the mask.
It will not work for sprites that have isolated background areas. So it only works for images completely surrounded by the background color and it will not handle see through areas within the central image. It was an exercise in understanding that sprites really do require a unique background color.
So for what it is worth
[spritemask] global mapw,maph,offset,pointer,bytes,padding,Red,Green,Blue file$="sprite.bmp" 'now open the bmp file for binary read/write access open file$ for binary as #bmp
'analyse the file header bytes seek #bmp,10 'picture data offset, where the color data starts 4 bytes of data offset=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,18 'width 4 bytes of data mapw=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,22 'height 4 bytes of data maph=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256+asc(input$(#bmp,1))*65536+asc(input$(#bmp,1))*16777216 seek #bmp,28 'bits per pixel, ie color depth 2 bytes of data bits=asc(input$(#bmp,1))+asc(input$(#bmp,1))*256
'work out start of picture data and how to move through file pointer=offset
'work out how many bytes in the bits per pixel 24=3 bgr 32=4 abgr bytes=bits/8
'work out padding each raster line must be a 4byte multiple mult=bits/8*mapw/4 padding = 4*(1-(mult-int(mult))) mod 4
WindowWidth=400 WindowHeight=400 UpperLeftX=10 UpperLeftY=10 open "Spritemask" for graphics as #1 #1 "trapclose [quit]" loadbmp "s",file$ #1 "down ; color black ; fill white ; drawbmp s 0 0"
'Now flood the outside area with magenta 'big caveat is that there are no isolated 'background areas inside the image. 'big caveat is that background is found 'at 1,1 target=getpixel(1,1) replace=255+255*256*256 #1 "color 255 0 255" nul=floodfill(1,1,target,replace)
'now replace any black in the central image 'with near black then, replace any magenta with black 'big caveat sprite can have no see through parts
for y=0 to maph-1 for x=0 to mapw-1 pixel=getpixel(x,y)
if pixel=0 then #1 "color 1 0 0" #1 "set ";x;" ";y+maph #1 "color 0 0 0" #1 "set ";x;" ";y else if pixel=replace then #1 "color 0 0 0" #1 "set ";x;" ";y+maph #1 "color 255 255 255" #1 "set ";x;" ";y else #1 "color ";Red;" ";Green;" ";Blue #1 "set ";x;" ";y+maph #1 "color 0 0 0" #1 "set ";x;" ";y end if
end if next next #1 "getbmp ms 0 0 ";mapw;" ";maph+maph bmpsave "ms","mask"+file$
[quit] close #bmp close #1 end
function setpixel(x,y,r,g,b) if x>=mapw or y>=maph or x<0 or y<0 then exit function 'raster lines are stored bottom up so we invert y y=(maph-1)-y pointer=offset+x*bytes+y*(mapw*bytes+padding) 'set pixel color seek #bmp, pointer #bmp chr$(b);chr$(g);chr$(r); end function
function getpixel(x,y) if x>=mapw or y>=maph or x<0 or y<0 then exit function 'raster lines are stored bottom up so we invert y y=(maph-1)-y pointer=offset+x*bytes+y*(mapw*bytes+padding) 'get pixel color stored as BGR Liberty needs RGB seek #bmp, pointer Blue=asc(input$(#bmp,1)) Green=asc(input$(#bmp,1)) Red=asc(input$(#bmp,1)) getpixel=Red+256*Green+256*256*Blue [done] end function
function floodfill(x,y,target,replace) if x>=mapw or y>=maph or x<0 or y<0 then exit function 'recursive flood fill function see rosetta code if target = replace then exit function if getpixel(x,y) <> target then exit function else #1 "set ";x;" ";y nul=setpixel(x,y,255,0,255) end if nul=floodfill(x,y+1,target,replace) nul=floodfill(x,y-1,target,replace) nul=floodfill(x-1,y,target,replace) nul=floodfill(x+1,y,target,replace) end function
|
|
|
Post by Enzo on Mar 4, 2021 19:07:33 GMT
Yes I was mistaken with the background fill at first, now I am applying fill with paint program I could parse each image three times in program, one loop to Change black pixels to values of 1, modify white pixels to true black; and then lastly the mask.
Right now im working on adding items to game at least from map to inventory, also running into some lag at 256mb gfx ram, might need to unload loading menu bmps to free ram?
Trying to find anything wrong with these functions, besides;
Function pickup(player.x, player.y, selecteditem, deleteid, pos)' single item per square pickup deleteid = 3 selected = obj.x(player.x) func = deleteitem(selected, selecteditem, deleteid, pos, player.x, player.y) 'delete item deleteid = null renew=serverexchange(serverdata) 'server exchange data null = null 'prevent from double pickup null = null
func = newitem(newitem) 'create new item in inventory End function
Function deleteitem(selected, selecteditem, deleteid, pos, player.x, player.y) ' TileX = left$(str$(pos,1)) ' TileY = right$(str$((pos,2)) if deleteid = 3 then '3 = map. obj.y(player.y)=null 'reset area array server exchange here obj.x(player.x)=null notice "3" renew=serverexchange(serverdata) end if
if deleteid = 1 then '1 = inventory if selected = inventory(pos) then 'debugged inventory(pos)=null end if end if End Function
Function newitem(selected)'multi-use selected variable also for new quest items and trade not included currently for inventoryslot = 1 to 8 if inventory(inventoryslot) > null then 'check if slot is free if not null = null else it is a free slot null = null else 'if inventory(8) > null then 'notice "item lost full" 'else inventory(inventoryslot) = selected 'inputs selected data here for new item on next draw inventoryslot = 10' exit for ' end if end if 'make sure draw sprites command renews graphics next inventoryslot End Function
; if inventory is fill, no handler for null item pickup, but that is fine for right now.
|
|
|
Post by Enzo on Mar 4, 2021 19:51:04 GMT
newitem=selecteditem
After last if then; else
Also manually inputing obj.y() obj.x() both to 0 item still appears on map, to hide a sprite, use a !hide command or move the xy values to offscreen?
|
|
|
Post by Enzo on Mar 4, 2021 19:56:44 GMT
I suppose a ram buffer of unloading bmps as items are picked up, if needed a prefetch for loading as well.
|
|
|
Post by Enzo on Mar 5, 2021 0:48:50 GMT
|
|
|
Post by Enzo on Mar 7, 2021 6:17:17 GMT
Massive error when trying to fix unload bmp 1.bmp, I renamed both in program completely (checked with find ctrl F) and in directory and it crashed my VMware
Stopped my linux ubuntu from booting.
Lost verison with picking items up and sailing, unless I can retrieve. Hmm,
Be aware, I was just about to change vmwares to fresh to stop the memory page file from effecting running justbasic program from previous runs but I was seconds away from preventing.
Shame
|
|
|
Post by Rod on Mar 7, 2021 9:24:15 GMT
There should be a .bak file. Look at Preferences
|
|
|
Post by Enzo on Mar 7, 2021 9:40:26 GMT
Thats another thing I don't think my .ini file has been saving I've changed setting several times but it keeps resetting, IDE has never created bak folder in complied Directory, I was able to remove harddrive from computer and use sata coord to retieve lastest verison, I will post, but please be wary of running. O.o This WILL have new filename/association to code. I remember last time I tried to use 1.bmp as a file name for JB and was let known that those (1-9.bmp) are semi-reserved by IDE? Here it is, ufile.io/dp5fscwiI had to create a dump area in map at 100x 100y which will be hidden/moved and hidden from player view, this is a catch-all for items picked up and otherwise used, I tried to use command remove sprite or also sprite visible it did NOT work even tried calling spriteimage first thinking it would 'call' the sprite to have internal functions remove and visible to work, no avail
|
|
|
Post by Rod on Mar 7, 2021 10:00:53 GMT
Had not heard of that, seems to be drawbmp that hangs up, the other lines work.
#1 "getbmp 1 0 0 800 800" bmpsave "1","1.bmp" loadbmp "1","1.bmp" #1 "drawbmp 1 0 0"
So seems to be to do with the "name" we give the bmp rather than the filename. I have always preceded the "name" with a letter adopting the variable naming convention. S1-S9
|
|
|
Post by Enzo on Mar 7, 2021 10:10:16 GMT
Rod I forgot, after it was 100% changed last error message before crash had 1.bmp still in memory but IDE was closed before last run, and like I said filenames were new format. I've ran into and been warned JB acts funny when bmps are not unloaded properly.
|
|
|
Post by Enzo on Mar 8, 2021 4:28:14 GMT
How do you prevent these hidden files from loading unwanted data that isn't even called out in program.
|
|