|
Post by valleyboy on Jun 24, 2023 11:24:06 GMT -5
I'm sure I worked this out in the past but I'm suffering from a senior citizen moment. Couple of questions:
1. How do you stop drawn sprites from disappearing if you move the part of the window they are located, off screen and and back on again? I've tried the flush command but that doesn't seem to have any effect.
2. I have a graphics window that I don't want the use to move. Is there a stylebit option to make this so?
|
|
|
Post by Rod on Jun 24, 2023 14:09:29 GMT -5
To draw sprites first create the background and load that with “background”, then you create the sprite as a masked image, “add sprite” then “drawsprite” after positioning the sprite. Flush has nothing to do with sprites. Sprite displays are usually displayed in a regular cycle which is why they pop back into view.
But for better answers show us how you have coded your sprite display.
|
|
|
Post by tsh73 on Jun 24, 2023 14:36:50 GMT -5
You can't nail the window to fixed place, but if you use window_popup, it will have no titlebar and borders, so user have no means to move it by mouse.
|
|
|
Post by valleyboy on Jun 24, 2023 15:23:35 GMT -5
Appreciate your responses. As for code, this example code shows my problem. If you run the program then move the part of the window off the screen and back again, the sprite disappears. I was hoping there was a way to nail it to the page somehow but maybe I am asking too much of sprites. My second question was related because if I can stop the user from moving the window off the screen, I can prevent the problem before it becomes one.
Hope this gives a little more context.
nomainwin
'this is the sprite bitmap loadbmp "smiley1", "smiley.bmp"
WindowHeight = 300:WindowWidth = 400
'sprites can only appear in a graphics window or graphicbox open "sprite test" for graphics_nf_nsb as #wg
'trap the close event so the code can issue 'the proper CLOSE and END commands #wg "trapclose [quit]"
'add a sprite #wg "addsprite smiley smiley1"
'give a location to sprite: #wg "spritexy smiley 30 40"
'cause images to show #wg "drawsprites"
'wait for user input wait
[quit] unloadbmp "smiley1" close #wg:end
|
|
|
Post by valleyboy on Jun 24, 2023 15:27:02 GMT -5
I need a graphic window for sprites so popup is not an option sadly. I also need transparency because I have a background image, so standard jpeg or bmp images are not fit for purpose. Any other ideas? Keen to experiment because this requirement is core to what I'm building.
|
|
|
Post by tsh73 on Jun 24, 2023 15:36:40 GMT -5
>>graphics window or graphicbox So you just put graphicbox of the size of popup window
EDIT but it will not help against "sprite disappear" it will disappear then you obscure window or minimize/restore it
So just make a timer, drawsprites on timer.
nomainwin
'this is the sprite bitmap ' loadbmp "smiley1", "smiley.bmp" loadbmp "smiley1", "sprites\smiley.bmp"
WindowHeight = 300:WindowWidth = 400
'sprites can only appear in a graphics window or graphicbox open "sprite test" for graphics_nf_nsb as #wg
'trap the close event so the code can issue 'the proper CLOSE and END commands #wg "trapclose [quit]"
'add a sprite #wg "addsprite smiley smiley1"
'give a location to sprite: #wg "spritexy smiley 30 40"
'cause images to show #wg "drawsprites"
timer 150, [tick] 'call timer every 150 ms
'wait for user input wait
[tick] #wg "drawsprites" 'redraw srites every tick wait
[quit] unloadbmp "smiley1" close #wg:end
|
|
|
Post by valleyboy on Jun 24, 2023 17:55:30 GMT -5
The timer idea is worth a look. I will need to re-jig my code a little. Thank you for taking the time to respond
|
|
|
Post by valleyboy on Jun 24, 2023 18:10:39 GMT -5
One final question ... Do you know if there are any plans for LB to support .png files natively or otherwise and/or z layering? If it did, then you wouldn't have to resort to using sprites for static images.
|
|
|
Post by valleyboy on Jun 24, 2023 18:12:47 GMT -5
Hang on a minute ... just discovered API TransparentBlt function. This could be the start of a wonderful relationship
|
|
|
Post by Walt Decker on Jun 25, 2023 18:39:23 GMT -5
This might be of interest to you.
PS: You can nail a form to a specific place and even have it move with another form. All it takes is a little API magic and some imagination.
|
|
|
Post by valleyboy on Jun 26, 2023 18:22:56 GMT -5
Thanks Walt. 'All it takes is a little API magic ...', care to enlighten the not so well enlightened among us please? BTW I found a way around my original question re:AWOL sprites. It might be a classed as a swear word but if I test my code in RT Russell's LB Booster, the sprites remain solidly attached to the canvas, no matter where it goes. Not sure why but that codebase must have a way of being able to redraw sprites without the need for any user coded instructions. Thoughts?
|
|
|
Post by Rod on Jun 27, 2023 3:02:22 GMT -5
The API involved with the blitter is not onerous. However even with the blitter code there is an expectation that sprite drawing will cycle. It would be unusual to have static sprite drawing. Even though it cycles the sprites can remain static. There is no overhead in this cycling, the code uses no more memory and is instantly available for change.
Sprites have a lot of graphic functionality, if you dont need that perhaps just a few predrawn screens being drawn and flushed is what you need. Depends on the project really.
nomainwin
' open the dll file used for TransparentBlt open "msimg32.dll" for dll as #m
WindowWidth = 600 WindowHeight = 600 UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 graphicbox #1.g, 50,80,500,300 open "Blitter" for graphics_nf_nsb as #1 print #1, "trapclose [quit]"
'set up our bitmaps, open device contexts and store our bitmaps in them 'first draw a rotatable starfield print #1.g, "down; fill black ; color white" for x = 1 to 50 print #1.g, "place ";int(rnd(0)*225);" ";int(rnd(0)*300) print #1.g, "size ";int(rnd(0)*4) print #1.g, "circle ";int(rnd(0)*3) next x print #1.g, "getbmp bmp 0 0 225 300" print #1.g, "drawbmp bmp 225 0"
'now draw a simple circle as the spaceship print #1.g, "place 475 40 ; size 1 ;circle 20" 'now get the bmp print #1.g, "getbmp bmp 0 0 500 300"
'sDC is our screen buffer, (DC handle to the graphicsbox) sDC=GetDC(hwnd(#1.g))
'mDC is a copy of the screen in memory mDC=CreateCompatibleDC(sDC)
' select our bmp graphic resource into the memory dc hBitmap=hbmp("bmp") oldBmp=SelectObject(mDC,hBitmap)
'starting point for spaceship s=0 x=100 y=100 'it isn't moving delatX=0 deltaY=0
' set up a repeating loop to draw our graphics timer 57, [timedloop] wait
[timedloop] 'scroll the background s=s+1 if s=225 then s=0 'move the spaceship x=x+deltaX if x>500 then x=-40 if x<-40 then x=500 y=y+deltaY if y>300 then y=-40 if y<-40 then y=300 'draw the background with StretchBlt then the spaceship with TransparentBlt 'note fast keyboard reading call StretchBlt,sDC,0,0,500,300,mDC,s,0,225,300 call TransparentBlt,sDC,x,y,40,40,mDC,455,20,40,40,0
' read the keyboard
'escape/quit CallDLL #user32, "GetAsyncKeyState",_VK_ESCAPE AS long,k1 AS long if k1<0 then Goto [quit]
'left CallDLL #user32, "GetAsyncKeyState",_VK_LEFT AS long,k1 AS long CallDLL #user32, "GetAsyncKeyState",4 AS long,k2 AS long if k1<0 or k2<0 then deltaX=-10
'right CallDLL #user32, "GetAsyncKeyState",_VK_RIGHT AS long,k1 AS long CallDLL #user32, "GetAsyncKeyState",6 AS long,k2 AS long if k1<0 or k2<0 then deltaX=10
'up CallDLL #user32, "GetAsyncKeyState",_VK_UP AS long,k1 AS long CallDLL #user32, "GetAsyncKeyState",8 AS long,k2 AS long if k1<0 or k2<0 then deltaY=-10
'down CallDLL #user32, "GetAsyncKeyState",_VK_DOWN AS long,k1 AS long CallDLL #user32, "GetAsyncKeyState",2 AS long,k2 AS long if k1<0 or k2<0 then deltaY=10
wait
wait
[quit] timer 0
unloadbmp "bmp" call ReleaseDC hwnd(#1), gDC call DeleteDC mDC close #1 close #m
end
'=============================Window and DC functions================================= Function GetDC(hWnd) CallDLL #user32, "GetDC",_ hWnd As ulong,_ 'window or control handle GetDC As ulong 'returns device context End Function
Sub ReleaseDC hWnd, hDC CallDLL#user32,"ReleaseDC",_ hWnd As ulong,_ 'window or control handle hDC As ulong,_ 'handle of DC to delete result As Long End Sub
Function CreateCompatibleDC(hDC) CallDLL #gdi32,"CreateCompatibleDC",_ hDC As ulong,_ 'window DC CreateCompatibleDC As ulong 'memory DC End Function
Sub DeleteDC hDC CallDLL #gdi32, "DeleteDC",_ hDC As ulong,_ 'memory DC to delete r As Boolean End Sub
Sub StretchBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2 CallDLL #gdi32, "SetStretchBltMode",_ hDCdest As ulong,_ 'device context _COLORONCOLOR As Long,_ 'color reduction mode RESULT As Long CallDLL #gdi32, "StretchBlt",_ hDCdest As ulong,_ 'destination x As Long,_ 'destination x pos y As Long,_ 'destination y pos w As Long,_ 'destination width desired h As Long,_ 'destination height desired hDCsrc As ulong,_ 'source x2 As Long,_ 'x location to start from source y2 As Long,_ 'y location to start from source w2 As Long,_ 'width desired from source h2 As Long,_ 'height desired from source _SRCCOPY As long,_ 'dwRasterOperation RESULT As Boolean End Sub
Sub TransparentBlt hDCdest,x,y,w,h,hDCsrc,x2,y2,w2,h2,crTransparent calldll #m, "TransparentBlt",_ hDCdest As uLong,_ 'destination x As Long,_ 'destination x pos y As Long,_ 'destination y pos w As Long,_ 'destination width desired h As Long,_ 'destination height desired hDCsrc As uLong,_ 'source x2 As Long,_ 'x location to start from source y2 As Long,_ 'y location to start from source w2 As Long,_ 'width desired from source h2 As Long,_ 'height desired from source crTransparent as ulong,_ 'color to make transparent 0=Black result as boolean end sub
Function SelectObject(hDC,hObject) CallDLL #gdi32,"SelectObject",_ hDC As ulong,_ 'memory device context hObject As long,_ 'handle of object SelectObject As long 'returns previously selected object End Function
|
|
|
Post by Rod on Jun 27, 2023 3:18:30 GMT -5
As Anatoly suggests window popup is a viable way to fix your screen and stop wayward mouse clicks. Not everyone likes full screen but again depends on what the project is. Your screen shot links don't work so still a bit in the dark about what the drawing needs really are. 'open a big window and graphicbox WindowWidth = DisplayWidth WindowHeight = DisplayHeight graphicbox #w.g, 0, 0, WindowWidth, WindowHeight open "Big Window" for window_popup as #w #w "trapclose [quit]" #w.g "down ; fill black" #w.g "when characterInput [quit]" #w.g "setfocus" #w.g "color red ; place 0 0 ; box ";WindowWidth-2;" ";WindowHeight-2 'Border pixels #w.g "place 400 400 ;\Press any key" wait
[quit] close #w end
This is a full screen blitter sprite demo. It uses blitter based sprites, it enlarges a fixed sized animation to the users full screen parameters. gamebin.webs.com/FSDance.zip
|
|
|
Post by Walt Decker on Jun 27, 2023 11:40:01 GMT -5
Look at THISAs far as keeping the image stable, I have not seen the referenced app?/code? However, I think it is using some type of double buffering either via LB's GETBMP/DRAWBMP instructions or API functions. Personally, I would use API functions since LB's instructions fail when a portion of the image is obscured.
|
|