我到目前为止这个程序有效,但是当它进入for循环时会冻结。我已经用另一个程序完成了这样的事情,但是它的形状并不喜欢它。
GraphicsWindow.Height = 400
GraphicsWindow.Width = 600
GraphicsWindow.Title = "FairyTail"
GraphicsWindow.CanResize = "False"
animation()
Controls.ButtonClicked = action
Sub animation
GraphicsWindow.BrushColor = "Black"
Firstmove = Controls.AddButton("fireball", 300, 100)
Controls.Move(Firstmove, 0, 200)
endsub
Sub action
If Controls.GetButtonCaption(Firstmove) = "fireball" Then
GraphicsWindow.BrushColor = "Red"
fireball = Shapes.AddEllipse(20, 20)
Shapes.Move(fireball, 135, 115)
For i = 135 To 465
if i <> 465 then
Shapes.animate(fireball, i, 115, 1000)
i = i + 1
Program.Delay(100)
Else
Shapes.Remove(fireball)
endif
endfor
endif
endsub
我试图做的是将火球移过屏幕然后将其移除。但我不知道如何在它动画后删除它。
答案 0 :(得分:1)
此程序存在一些问题。第一个是:
For i = 135 To 465
if i <> 465 then
Shapes.animate(fireball, i, 115, 1000)
i = i + 1
Program.Delay(100)
Else
Shapes.Remove(fireball)
endif
endfor
如果你已经在&#34; i&#34;之后关闭了For语句。 = 465,你真的不需要If语句。
第二个问题(以及它未运行的原因)是:
Shapes.animate(fireball, i, 115, 1000)
此命令的作用是,它是否在设定的时间内将形状移动到设定的x和y坐标。因此,这意味着它将在1000 MS之后将形状从其葡萄干位置移动到i,115。
你真正需要的是Shapes.Move。
此外,通常一个好主意是让所有循环在子程序之外执行。这是因为如果你单击按钮两次,它将尝试调用子程序,而子程序仍在运行(因为它在其中循环)这将导致问题。以下是我制作本计划的方式:
GraphicsWindow.Height = 400
GraphicsWindow.Width = 600
GraphicsWindow.Title = "FairyTail"
GraphicsWindow.CanResize = "False"
animation()
Controls.ButtonClicked = action
While 1 = 1
Program.Delay(10)
If CanMoveFireball Then
i = i + 1 '<--- Increase the position and move it to that position
Shapes.Move(fireball,i,115)
EndIf
If i > 465 Then '<--- If the fireball is past 465 then remove it and say its OK to add another
Shapes.Remove(fireball)
CanMoveFireball = "False"
EndIf
EndWhile
Sub animation
GraphicsWindow.BrushColor = "Black"
Firstmove = Controls.AddButton("fireball", 300, 100)
Controls.Move(Firstmove, 0, 200)
endsub
Sub action
If Controls.LastClickedButton = Firstmove Then
If CanMoveFireball <> "True" Then '<--- Make sure you don't add another fireball while the first one is moving
GraphicsWindow.BrushColor = "Red"
fireball = Shapes.AddEllipse(20, 20)
Shapes.Move(fireball, 135, 115)
i = 135
CanMoveFireball = "True" '<--- Tell it it's OK to move Fireball
EndIf
Endif
Endsub
我希望这会有所帮助!!
- Zock