0

我到目前为止的这个程序可以工作,但是当它进入 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

我想要做的是在屏幕上移动火球然后将其移除。但我不知道如何在它动画后将其删除。

4

1 回答 1

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 

如果在“i”= 465 之后已经有一个 For 语句结束,那么您实际上并不需要 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

我希望这有帮助!!

——佐克

于 2015-09-03T18:35:14.760 回答