|
Post by held12345 on Feb 23, 2023 6:39:48 GMT -5
hello good day.
how to make the transparent sprite for liberty basic please? what simple painting program do you use for this?
Thanks. greeting
Attachments:smiley224.bmp (4.64 KB)
|
|
|
Post by Rod on Feb 23, 2023 10:37:03 GMT -5
This is the simplest routine we all use. There are other sprite creation programs but perhaps more complex than you need.
'small utility to add masks to the 'top of sprite images for use in LB3
nomainwin bmpheight=0 'bitmap height bmpwidth=0 'bitmap width
bitmap$="" 'bitmap file name savefile$="" 'save file name hBitmap=0 'handle for loaded bitmap hWindow=0 'window handle
menu #1, "&File", "&Open Sprite",[openSprite],_ "&Save As...",[saveAs],|,"E&xit",[quit]
open "Add Masks to Sprites" for graphics_fs_nsb as #1 print #1, "trapclose [quit]" print #1, "down;place 20 40" print #1, "|Open the desired sprite image." print #1, "|A mask will be added to the sprite " print #1, "|as you watch."
print #1, "|This might take time for large images." print #1, "|Images larger than the window " print #1, "|will be cut off." print #1, "|If it is satisfactory, choose " print #1, "|'Save As...' from the File menu." hWindow=hwnd(#1)
[loop] input aVar$
[quit] close #1:end
[openSprite] if hBitmap<>0 then unloadbmp ("bm") print #1, "cls" end if
filedialog "Open Sprite","*.bmp",bitmap$ if bitmap$="" then
notice "No bitmap chosen!" goto [loop] end if
print #1, "cls" loadbmp "bm" , bitmap$ hBitmap=hbmp("bm")
print #1, "down;drawbmp bm 0 0"
bmpheight=HeightBitmap(bitmap$) bmpwidth=WidthBitmap(bitmap$)
print #1, "drawbmp bm 0 ";bmpheight
call MakeMask bmpwidth, bmpheight, hWindow goto [loop]
[saveAs] print #1, "getbmp SpriteMask 0 0 ";bmpwidth;" ";2*bmpheight
filedialog "Save As... ","*.bmp",savefile$
if savefile$="" then notice "No filename specified!" goto [loop] end if
bmpsave "SpriteMask",savefile$ notice "Sprite and mask saved as ";savefile$ goto [loop]
'************FUNCTIONS****************** function WidthBitmap(name$) open name$ for input as #pic pic$=input$(#pic,29) close #pic WidthBitmap = asc(mid$(pic$,19,1)) + _ (asc(mid$(pic$,20,1)) * 256) end function
function HeightBitmap(name$)
open name$ for input as #pic pic$=input$(#pic,29) close #pic HeightBitmap = asc(mid$(pic$,23,1)) + _ (asc(mid$(pic$,24,1)) * 256) end function
sub MakeMask wide, high, hWnd
cursor hourglass white=(255*256*256)+(255*256)+255 black=0
open "user32" for dll as #user Open "gdi32"for DLL as #gdi
CallDll #user, "GetDC",_ hWnd as long,_ hDC as long
for i = 0 to wide-1 for j = 0 to high-1
CallDll #gdi, "GetPixel",_ hDC as long,_ i as long,_ j as long,_ pColor as long
if pColor=black then newColor=white else newColor=black end if
CallDll #gdi, "SetPixel",_ hDC as long,_ i as long, _ j as long, _ newColor as long, _ r as long
next j next i
CallDll #user, "ReleaseDC",_ hWnd as long,_ hDC as long,_ r as long
close #user close #gdi cursor normal end sub
This code will rotate small square images and create masked images. Bit messy on the diagonals.
nomainwin WindowWidth=800 WindowHeight=600 UpperLeftX=(DisplayWidth-WindowWidth)/2 UpperLeftY=(DisplayHeight-WindowHeight)/2 menu #1, "&File", "&Open Sprite",[openSprite],_ "&Save As...",[saveAs],|,"E&xit",[quit] open "Rotate and Mask Sprite" for graphics_nsb as #1 #1 "down ; trapclose [quit]"
hWindow=hwnd(#1) CallDll #user32, "GetDC",_ hWindow as ulong,_ hDC as ulong wait
[quit] CallDll #user32, "ReleaseDC",_ hWindow as ulong,_ hDC as ulong,_ r as long close #1 end
[openSprite] if hBitmap<>0 then unloadbmp ("bm") #1 "cls" end if
filedialog "Open Sprite","*.bmp",bitmap$ if bitmap$="" then wait loadbmp "bm" , bitmap$ hBitmap=hbmp("bm") bmpheight=HeightBitmap(bitmap$) bmpwidth=WidthBitmap(bitmap$) midx=int(bmpwidth/2) midy=int(bmpheight/2)+bmpheight radi=int(bmpwidth/2) #1 "fill black" #1 "drawbmp bm 0 ";bmpheight for angle= 30 to 330 step 30 newx=newx+bmpwidth call rotate angle,newx,midx,midy,radi, hWindow, hDC next call MakeMask bmpwidth, bmpheight, hWindow, hDC wait
[saveAs] #1 "getbmp SpriteMask 0 0 ";bmpwidth;" ";2*bmpheight filedialog "Save As... ","*.bmp",savefile$ if savefile$="" then wait newx=0 for a=0 to 330 step 30 #1 "getbmp SpriteMask ";newx;" 0 ";bmpwidth;" ";2*bmpheight bmpsave "SpriteMask",left$(savefile$,len(savefile$)-4)+str$(a)+".bmp" newx=newx+bmpwidth next wait
'************FUNCTIONS****************** function WidthBitmap(name$) open name$ for input as #pic pic$=input$(#pic,29) close #pic WidthBitmap = asc(mid$(pic$,19,1)) + _ (asc(mid$(pic$,20,1)) * 256) end function
function HeightBitmap(name$)
open name$ for input as #pic pic$=input$(#pic,29) close #pic HeightBitmap = asc(mid$(pic$,23,1)) + _ (asc(mid$(pic$,24,1)) * 256) end function
sub rotate angle, newx, midx, midy, radi, hWindow, hDC for d = 0 to radi for n= 1 to 360 step .5 scan x=int(midx-(d*sin(n/57.29577951))) y=int(midy-(d*cos(n/57.29577951))) CallDll #gdi32, "GetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long a=n+angle mod 360 x=int(midx-(d*sin(a/57.29577951))) y=int(midy-(d*cos(a/57.29577951))) x=x+newx CallDll #gdi32, "SetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long,_ r as long next n next d end sub
sub MakeMask wide, high, hWnd,hDC white=(255*256*256)+(255*256)+255 black=0 for x = 0 to 12*wide-1 for y = high to 2*high-1 CallDll #gdi32, "GetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long if pColor=black then newColor=white else newColor=black end if j=y-high CallDll #gdi32, "SetPixel",_ hDC as ulong,_ x as long, _ j as long, _ newColor as long, _ r as long next y next x end sub
|
|
|
Post by held12345 on Feb 23, 2023 12:34:01 GMT -5
Hi, Thank You. the sprite with the mask works wonderfully with the program.
can you please change your rotate program so that a sprite is rotated from 0-180 degrees with 20 degrees each and the sprite is saved as a bmp? spr1.bmp , spr2.bmp ....
Thanks. greeting
|
|
|
Post by Rod on Feb 23, 2023 13:32:43 GMT -5
nomainwin WindowWidth=800 WindowHeight=600 UpperLeftX=(DisplayWidth-WindowWidth)/2 UpperLeftY=(DisplayHeight-WindowHeight)/2 menu #1, "&File", "&Open Sprite",[openSprite],_ "&Save As...",[saveAs],|,"E&xit",[quit] open "Rotate and Mask Sprite" for graphics_nsb as #1 #1 "down ; trapclose [quit]"
hWindow=hwnd(#1) CallDll #user32, "GetDC",_ hWindow as ulong,_ hDC as ulong wait
[quit] CallDll #user32, "ReleaseDC",_ hWindow as ulong,_ hDC as ulong,_ r as long close #1 end
[openSprite] if hBitmap<>0 then unloadbmp ("bm") #1 "cls" end if
filedialog "Open Sprite","*.bmp",bitmap$ if bitmap$="" then wait loadbmp "bm" , bitmap$ hBitmap=hbmp("bm") bmpheight=HeightBitmap(bitmap$) bmpwidth=WidthBitmap(bitmap$) midx=int(bmpwidth/2) midy=int(bmpheight/2)+bmpheight radi=int(bmpwidth/2) #1 "fill black" #1 "drawbmp bm 0 ";bmpheight for angle= 0 to 180 step 20 newx=newx+bmpwidth call rotate angle,newx,midx,midy,radi, hWindow, hDC next call MakeMask bmpwidth, bmpheight, hWindow, hDC wait
[saveAs] #1 "getbmp SpriteMask 0 0 ";bmpwidth;" ";2*bmpheight filedialog "Save As... ","*.bmp",savefile$ if savefile$="" then wait newx=0 for a=1 to 10 #1 "getbmp SpriteMask ";newx;" 0 ";bmpwidth;" ";2*bmpheight bmpsave "SpriteMask",left$(savefile$,len(savefile$)-4)+str$(a)+".bmp" newx=newx+bmpwidth next wait
'************FUNCTIONS****************** function WidthBitmap(name$) open name$ for input as #pic pic$=input$(#pic,29) close #pic WidthBitmap = asc(mid$(pic$,19,1)) + _ (asc(mid$(pic$,20,1)) * 256) end function
function HeightBitmap(name$)
open name$ for input as #pic pic$=input$(#pic,29) close #pic HeightBitmap = asc(mid$(pic$,23,1)) + _ (asc(mid$(pic$,24,1)) * 256) end function
sub rotate angle, newx, midx, midy, radi, hWindow, hDC for d = 0 to radi for n= 1 to 360 step .5 scan x=int(midx-(d*sin(n/57.29577951))) y=int(midy-(d*cos(n/57.29577951))) CallDll #gdi32, "GetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long a=n+angle mod 360 x=int(midx-(d*sin(a/57.29577951))) y=int(midy-(d*cos(a/57.29577951))) x=x+newx CallDll #gdi32, "SetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long,_ r as long next n next d end sub
sub MakeMask wide, high, hWnd,hDC white=(255*256*256)+(255*256)+255 black=0 for x = 0 to 12*wide-1 for y = high to 2*high-1 CallDll #gdi32, "GetPixel",_ hDC as ulong,_ x as long,_ y as long,_ pColor as long if pColor=black then newColor=white else newColor=black end if j=y-high CallDll #gdi32, "SetPixel",_ hDC as ulong,_ x as long, _ j as long, _ newColor as long, _ r as long next y next x end sub
|
|
|
Post by held12345 on Feb 24, 2023 8:30:18 GMT -5
hello, thanks for the demo.
what is the .bas for an image format? what is it played with?
Thanks. greeting
|
|
|
Post by tsh73 on Feb 24, 2023 9:09:21 GMT -5
That's just typoo in a program in [saveAs] branch
bmpsave "SpriteMask",left$(savefile$,len(savefile$)-4)+str$(a)+".bas" should be
bmpsave "SpriteMask",left$(savefile$,len(savefile$)-4)+str$(a)+".bmp"
Saved are just normal BMP files, you can rename then from *BAS to *.BMP
|
|
|
Post by held12345 on Feb 24, 2023 10:57:13 GMT -5
Hi, Thank You.
your .bas react to the sprites, are better.
|
|
|
Post by held12345 on Feb 24, 2023 15:26:37 GMT -5
how are your 10 graphics-bas-programs used for the sprite? How do you play with it?
Thanks.
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Feb 24, 2023 15:29:18 GMT -5
how are your 10 graphics-bas-programs used for the sprite? How do you play with it? Thanks. Hi there. What do you mean?
|
|
|
Post by held12345 on Feb 24, 2023 15:33:21 GMT -5
I cannot evaluate the .bas with the graphic in it. how do you play with the 10 programs in the sprites? what kind of graphic format is that?
|
|
|
Post by tsh73 on Feb 24, 2023 16:08:17 GMT -5
It is NOT *.BAS files It is BMP files saved as *.BAS due to error in a program so either 1) rename them to BMP yourself or 2) change program
and run it again - you'll get 10 BMP instead.
|
|
|
Post by Rod on Feb 25, 2023 5:16:00 GMT -5
Yes sorry, old tired eyes. Should have been .bmp not .bas I have edited the programs above.
|
|
|
Post by held12345 on Feb 25, 2023 7:48:46 GMT -5
hello , thanks for info.
greeting
|
|
|
Post by held12345 on Feb 25, 2023 8:07:39 GMT -5
Hi good afternoon.
does my bmp of me 64x64 without a mask have a mask after the rotation with your program?
Thanks.
|
|
|
Post by Rod on Feb 25, 2023 9:07:01 GMT -5
yes, open the new .bmp with any graphic or paint program and you will see it is double the height with the mask at the top of the image. Although the .bmp is double the height when drawn as a sprite you only see the bottom 64x64 portion.
|
|