Hi all, new here, and relatively new to programming. I've been working for about a week on a 2D RPG engine, and even AI (of various sorts) can't see to help me on certain issues.
The first issue is that I can't figure out how to take a screenshot of one particular area of the screen. When I use _ScreenImage it just takes a shot of the last window that was open OTHER than the game I'm working on. GET seems useless for whatever reason, and _NewImage only starts from 0, 0, which is useless to me. And I don't even understand _CopyImage.
I'm working in a 32-bit window.
The purpose of this is for the second issue, and for all I know isn't needed at all. I made code to animate the opening of a text box by splitting it into thirds. It appears from top to bottom over a certain period of frames. But the problem is that the only way I've been able to make those images disappear is by making them all disappear at the same time. However I simply want the animation to reverse itself so the box appears to be closing.
I must've worked seven hours today to try and make this happen, to no avail. And Claude, ChatGPT, and Gemini were all of no help. I'm desperate here!
Since you've started a project, please post the code. It is much easier to get help on what your are working on than what you are talking about. Also, please don't try to learn programming from these stupid so called AI apps. They are being hyped up to insure a some sort of a future when they actually may be useful. I was around to see search engines go from trash to treasure, but thankfully, back then, we didn't have to contend with all the bonehead hype we see today.
Now the project you are undertaking may be a bit too advanced for starters. Usually folks cut their teeth by building up their coding ability with easier concepts; however some folks catch on pretty fast, provided they can just get past some hurdles. That's what posting the code, even if it doesn't work, helps with, recognizing and getting past those hurdles.
Welcome to the biggest and bestest BASIC forum on the internet. That's right, channeling Trump again.
10-28-2024, 07:46 AM (This post was last modified: 10-28-2024, 07:56 AM by bplus.)
Quote:The first issue is that I can't figure out how to take a screenshot of one particular area of the screen
This is combo of maybe _Newimage, for sure _Putimage and _SaveImage.
_putimage gets a section of screen and can put it into a _newimage work area and _saveimage can convert that image to file for storage and retrieval anytime anywhere.
You might just be needing to learn to use _PutImage: https://qb64phoenix.com/forum/showthread.php?tid=1119
"Text boxes"
I know "text boxes" as controls in GUI that users use to fill with strings for processing info in the app.
This is not describing them:
Quote:The purpose of this is for the second issue, and for all I know isn't needed at all. I made code to animate the opening of a text box by splitting it into thirds. It appears from top to bottom over a certain period of frames. But the problem is that the only way I've been able to make those images disappear is by making them all disappear at the same time. However I simply want the animation to reverse itself so the box appears to be closing.
Could you be talking about View Print or Window commands used for controling areas of screen usually for text?
Pete says post code and usually that is great advice for newbies but trying to describe things with right words won't be helped much by code.
It seems like you are going for some visual effect with text? You can use _NewImage and _PutImage to create all sorts of effects with text like swirl it around with RotoZoom!
10-28-2024, 05:43 PM (This post was last modified: 10-28-2024, 06:02 PM by Vespin.)
There's a lot of code in the overall program. Here's just the relevant stuff (this won't run if you try to run it). And yes, I know it's probably very inefficient, but I figured it out, so I'm proud of it. Note, most of these subs are in different files. The following makes the textbox disappear all at once instead of "roll" open as it does when it opens. And note that I reveal the letters by shrinking a black box over them.
Code: (Select All)
Dim henryB2 As Integer ' Determines if Henry text box 2 is triggered
Dim henryDone As Integer ' Makes it so Henry won't start over when trying to close text box
Dim henryWait As Integer ' A timer for talking to Henry again
Dim boxDone As Integer ' Determines when it's time to roll-up the box
Dim Shared textbox1 As Integer: textbox1 = _LoadImage("images/text_box1.png") ' top third of the box
Dim Shared textbox2 As Integer: textbox2 = _LoadImage("images/text_box2.png")
Dim Shared textbox3 As Integer: textbox3 = _LoadImage("images/text_box3.png")
Do
' Henry Interaction
' All if this code needs to be present for a text box to appear; just modify variables for different sources
If _KeyDown(32) And Not keyPressed And cPlayX = 19 And cPlayY = 3 And henryDone = 0 And henryB2 = 0 Then henryT = 1 ' These are all tiles where Henry can be triggered with spacebar
If _KeyDown(32) And Not keyPressed And cPlayX = 19 And cPlayY = 5 And henryDone = 0 And henryB2 = 0 Then henryT = 1 ' keyPressed tests for a tap; if not keyPressed, then not held down
If _KeyDown(32) And Not keyPressed And cPlayX = 18 And cPlayY = 4 And henryDone = 0 And henryB2 = 0 Then henryT = 1
If _KeyDown(32) And Not keyPressed And cPlayX = 20 And cPlayY = 4 And henryDone = 0 And henryB2 = 0 Then henryT = 1
' henryB2 needs to be tested here because doing so is one part of getting rid of a certain bug, see below
If henryT = 1 Then
interact = 1 ' Player reads as interacting so they won't move
boxOpen ' Box unfolding animation
If boxdraw >= 3 Then ' The box needs to be unfolded before any text appears
drawText "ABCDEFGHIJKLMNOPQRSTUVWXYZ", textDnX, textDnY ' Activate the function that draws the text with the custom font; text is drawn at screen x, y
drawText "abcdefghijklmnopqrstuvwxyz", textDnX, textDnY + lineSpaceB
drawText "0123456789", textDnX, textDnY + lineSpaceC
drawText "!?,:;/%'&.-~()[]@#*^}", textDnX, textDnY + lineSpaceD
lineReveal4 ' Four lines need to be revealed, so this sub is used
End If
End If
If _KeyDown(32) And Not keyPressed And revealD >= blackBox Then ' revealD refers to the final line of the last text box, in this case the 4th, or D
revealReset
henryT = 0 ' Keeps the text box from being opened away from Henry; needs to be here and not below, because a strange bug makes it so the second text box can be repeated after waiting a bit
henryB2 = 1 ' makes possible to trigger Henry's second text box
End If
If henryB2 = 1 Then
boxAppear ' Box appearing to remain in place, unchanged, for the next text
DrawText "Second box!", textDnX, textDnY
Line (textDnX + revealA, textDnY)-(textDnX + blackBox + 1, textDnY + letterHeight), _RGB(0, 0, 0), BF
lineReveal1
End If
If _KeyDown(32) And Not keyPressed And henryB2 = 1 And revealA >= blackBox Then
revealReset ' Resets the letters being revealed
revealResetB ' Allows the player to move again, and resets the box roll-down
henryB2 = 0 ' Resets B2 and causes the second text box to disappear
henryDone = 1 ' As long as this is 1, Henry can't be talked to
henryWait = 1 ' Resets the waiting period
boxDone = 1 ' Trigger the box to unroll upwards
End If
If henryDone = 1 Then henryWait = henryWait + 1 ' The player must wait before being able to trigger Henry again
If henryWait = 40 Then henryDone = 0 ' The waiting period
$If lineReveal1_bi = UNDEFINED Then
$Let lineReveal1_bi = 1
Sub lineReveal1
Line (textDnX + revealA, textDnY)-(textDnX + blackBox + 1, textDnY + letterHeight), _RGB(0, 0, 0), BF ' These are black boxes that cover the text
textRevealDnA ' These subs reveal the text of each line from left to right
$If drawText_bi = UNDEFINED Then
$Let drawText_bi = 1
Sub drawText (text As String, x As Integer, y As Integer)
Dim i As Integer
Dim positionX As Integer
Dim letter As String
positionX = x
For i = 1 To Len(text)
letter = Mid$(text, i, 1) ' Get each letter, convert to uppercase
Select Case letter
Case "a"
_PutImage (positionX, y), lowerA
Case "b"
_PutImage (positionX, y), lowerB
Case "c"
_PutImage (positionX, y), lowerC
Case "d"
_PutImage (positionX, y), lowerD
Case "e"
_PutImage (positionX, y), lowerE
Case "f"
_PutImage (positionX, y), lowerF
Case "g"
_PutImage (positionX, y), lowerG
Case "h"
_PutImage (positionX, y), lowerH
Case "i"
_PutImage (positionX, y), lowerI
Case "j"
_PutImage (positionX, y), lowerJ
Case "k"
_PutImage (positionX, y), lowerK
Case "l"
_PutImage (positionX, y), lowerL
Case "m"
_PutImage (positionX, y), lowerM
Case "n"
_PutImage (positionX, y), lowerN
Case "o"
_PutImage (positionX, y), lowerO
Case "p"
_PutImage (positionX, y), lowerP
Case "q"
_PutImage (positionX, y), lowerQ
Case "r"
_PutImage (positionX, y), lowerR
Case "s"
_PutImage (positionX, y), lowerS
Case "t"
_PutImage (positionX, y), lowerT
Case "u"
_PutImage (positionX, y), lowerU
Case "v"
_PutImage (positionX, y), lowerV
Case "w"
_PutImage (positionX, y), lowerW
Case "x"
_PutImage (positionX, y), lowerX
Case "y"
_PutImage (positionX, y), lowerY
Case "z"
_PutImage (positionX, y), lowerZ
Case "A"
_PutImage (positionX, y), upperA
Case "B"
_PutImage (positionX, y), upperB
Case "C"
_PutImage (positionX, y), upperC
Case "D"
_PutImage (positionX, y), upperD
Case "E"
_PutImage (positionX, y), upperE
Case "F"
_PutImage (positionX, y), upperF
Case "G"
_PutImage (positionX, y), upperG
Case "H"
_PutImage (positionX, y), upperH
Case "I"
_PutImage (positionX, y), upperI
Case "J"
_PutImage (positionX, y), upperJ
Case "K"
_PutImage (positionX, y), upperK
Case "L"
_PutImage (positionX, y), upperL
Case "M"
_PutImage (positionX, y), upperM
Case "N"
_PutImage (positionX, y), upperN
Case "O"
_PutImage (positionX, y), upperO
Case "P"
_PutImage (positionX, y), upperP
Case "Q"
_PutImage (positionX, y), upperQ
Case "R"
_PutImage (positionX, y), upperR
Case "S"
_PutImage (positionX, y), upperS
Case "T"
_PutImage (positionX, y), upperT
Case "U"
_PutImage (positionX, y), upperU
Case "V"
_PutImage (positionX, y), upperV
Case "W"
_PutImage (positionX, y), upperW
Case "X"
_PutImage (positionX, y), upperX
Case "Y"
_PutImage (positionX, y), upperY
Case "Z"
_PutImage (positionX, y), upperZ
Case "0"
_PutImage (positionX, y), nZero
Case "1"
_PutImage (positionX, y), nOne
Case "2"
_PutImage (positionX, y), nTwo
Case "3"
_PutImage (positionX, y), nThree
Case "4"
_PutImage (positionX, y), nFour
Case "5"
_PutImage (positionX, y), nFive
Case "6"
_PutImage (positionX, y), nSix
Case "7"
_PutImage (positionX, y), nSeven
Case "8"
_PutImage (positionX, y), nEight
Case "9"
_PutImage (positionX, y), nNine
Case "!"
_PutImage (positionX, y), exclamation
Case "?"
_PutImage (positionX, y), question
Case "."
_PutImage (positionX, y), period
Case "'"
_PutImage (positionX, y), sQuote
Case "-"
_PutImage (positionX, y), dash
Case "("
_PutImage (positionX, y), lParanthesis
Case ")"
_PutImage (positionX, y), rParanthesis
Case "["
_PutImage (positionX, y), lBracket
Case "]"
_PutImage (positionX, y), rBracket
Case "~"
_PutImage (positionX, y), tilda
Case ":"
_PutImage (positionX, y), colon
Case ";"
_PutImage (positionX, y), semicolon
Case ","
_PutImage (positionX, y), comma
Case "/"
_PutImage (positionX, y), slash
Case "%"
_PutImage (positionX, y), percent
Case "@"
_PutImage (positionX, y), atSign
Case "#"
_PutImage (positionX, y), hash
Case "&"
_PutImage (positionX, y), dQuote
Case "*"
_PutImage (positionX, y), star
Case "^"
_PutImage (positionX, y), heart
Case "}"
_PutImage (positionX, y), note
Case " "
End Select
positionX = positionX + letterWidth + letterSpace
Next i
The code above, when in place with the rest of the code, works perfectly... I just can't figure out how to modify it to "roll" the box up when the conversation is over. It rolls down fine when it starts.
_Title "Roll Open and Close an Image" ' b+ 2024-10-29
Const SW = 1200, SH = 700
Screen _NewImage(SW, SH, 32): _ScreenMove 0, 0
i = _LoadImage("vespin.PNG")
Do
BoxRollDown 10, 10, _Width - 20, _Height - 20, i, 1
_PrintString (500, _Height - 40), "Press any to roll up."
Sleep
Cls
BoxRollDown 10, 10, _Width - 20, _Height - 20, i, 0
_PrintString (500, _Height - 40), "Press any to roll down."
Sleep
Cls
Loop
Sub BoxRollDown (x, y, w, h, i, DownTF)
' not likely the box w, h is same scale as image w, h
' so what fits what?
saveAD = _AutoDisplay
iw = _Width(i)
ih = _Height(i)
wR = w / iw
hR = h / ih
If wR < hR Then ' use w scale to accommodate smallest change
scale = w / iw
xo = 0: yo = (h - ih * scale) / 2
Else ' use h to accomadate smallest change
scale = h / ih
xo = (w - iw * scale) / 2: yo = 0
End If
' mult scale to fit box
Line (x, y)-Step(w, h), , B ' draw box
Line (x + xo, y + yo)-Step(iw * scale, ih * scale), &HFFFFFF00, B ' fit image inside
If DownTF Then
For yy = 0 To ih
_PutImage (x + xo, y + yo)-Step(iw * scale, yy * scale), i, 0, (0, 0)-(iw, yy)
_Display
_Limit 120
Next
Else
For yy = ih To 0 Step -1
Line (x + xo, y + yo)-Step(iw * scale, ih * scale), &HFF000000, BF
Line (x + xo, y + yo)-Step(iw * scale, ih * scale), &HFFFFFF00, B ' fit image inside
_PutImage (x + xo, y + yo)-Step(iw * scale, yy * scale), i, 0, (0, 0)-(iw, yy)
_Display
_Limit 120
Next
End If
If saveAD Then _AutoDisplay
End Sub
Animation in zip is way better!
Should work for any image, here is New PieSlice screen shot rolling down. This image had less width than height for box it was to be fit into.
the most simplistic thing to do would be to copy the section of screen that the text box will go over. this also assumes your text box is an image itself,
Code: (Select All)
tempimagelayer = _NEWIMAGE( textboxXsize , textboxYsize, 32) 'temp area to store screen hidden by text box
_PUTIMAGE (0,0), _DISPLAY ,tempimagelayer, (ScreenPosX ,ScreenPosY)-step(textboxXsize -1, textboxYsize -1) 'move the section of screen to back it up
FOR Y%=0 TO textboxYsize-1 'Scroll out text box (this is from top down, for bottom up use "textboxYsize -1 TO 0 STEP -1"
_PUTIMAGE (ScreenPosX,ScreenPosY + Y%), TEXTBOXLayer, _DISPLAY, (0,y%)-STEP(TextboxXsize-1,0) 'place textbox line by line onto screen
_LIMIT 30 'change value to speed up or slow down how fast the textbox is shown
NEXT Y%
'do textbox stuff
FOR Y%=0 TO textboxYsize-1 'remove text box with scroll (this is from top down, for bottom up use "textboxYsize -1 TO 0 STEP -1"
_PUTIMAGE (ScreenPosX,ScreenPosY + Y%), tempimagelayer, _DISPLAY, (0,y%)-STEP(TextboxXsize-1,0) 'remove textbox from screen line by line.
_LIMIT 30 'change value to speed up or slow down how fast the textbox is removed
NEXT Y%
This code makes a lot of assumptions of how you are storing and using your text box and how fast you want it to scroll in and out and makes no attempt in controlling screen flickering.
You could also us a DO:LOOP as well if you don't like FOR\NEXT.
You can change how much of the text box is shown\removed with STEP, and how fast\slow with _LIMIT or even _DELAY.
I see B+ just made you some code too. Beat me to it.
When I was working on my version reversing the down effect, I too wondered, "Why isn't this working?"
Oh! because I had to blank out the image area! BEFORE each redraw of the shrinking image! Otherwise the image is redrawing over the full image, doesn't look like anything is happening! LOL
@bplus - is there an exe file in the zip file? I have never had any problems downloading zipped files with an exe file.
That can only be due to the host server. Chrome is on the default security settings, third-party cookies are blocked... all completely normal settings that don't otherwise cause any problems. And the Windows-Defender also.