我需要有一个图形窗口,当用户单击按钮时,它会反复显示一条消息。我已经在互联网上查看了如何不重叠的说明。这很可能是一个快速修复,但idk。这里的Plz帮助是我的代码。我试图制作一个点击游戏,但是因为这个问题发生了。
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
GraphicsWindow.DrawText(0,0,"You have " + eggs + " eggs")
ElseIf eggs >= 1 Then
GraphicsWindow.BackgroundColor = "White"
GraphicsWindow.DrawText(0,0,"You have " + eggs + " eggs")
EndIf
EndSub
答案 0 :(得分:0)
据我所知,在Small Basic中无法实现这种确切的效果,因为在不清除整个窗口的情况下无法编辑或删除绘制到GraphicsWindow
的内容。
相反,我会使用TextBox
中的Controls
,可以在创建后进行编辑。由于用户通常可以编辑TextBox
,因此我还添加了代码以防止内容被编辑。
请参阅我在代码中的评论,了解有关其工作原理的更多信息。
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
' Create a text box to show the egg count
myTextBox = Controls.AddTextBox(0, 0)
' Ensure the user can't edit its contents by resetting the text if it changes
Controls.TextTyped = updateEggs
Sub updateEggs
' Change the text of myTextBox
Controls.SetTextBoxText(myTextBox, "You have " + eggs + " eggs")
EndSub
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
updateEggs()
ElseIf eggs >= 1 Then
GraphicsWindow.BackgroundColor = "White"
updateEggs()
EndIf
EndSub
此GIF演示了TextBox
的外观和效果,以及文字无法更改的方式:
答案 1 :(得分:0)
您所要做的就是使用Shapes.AddText。这将创建一个可以使用Shapes.SetText
修改的文本形状示例:
GraphicsWindow.Height = 420
GraphicsWindow.Width = 720
GraphicsWindow.CanResize = "1"
Text = Shapes.AddText("You have 0 eggs")
button = Controls.AddButton("Click for eggs",200,200)
Controls.SetSize(button,100,100)
eggs = 0
Controls.ButtonClicked = buttonClicked
Sub buttonClicked
lastButtonClicked = Controls.LastClickedButton
If lastButtonClicked = button Then
eggs = eggs + 1
Shapes.SetText(Text,"You have " + eggs + " eggs")
EndIf
EndSub