在屏幕上移动一个形状并使其消失



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

我要做的是移动火球穿过屏幕,然后移除它。但我不知道如何删除它后,它的动画

这个程序有几个问题。第一个是:

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后将形状从当前位置移动到1,115

你真正需要的是shape . 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

相关内容

  • 没有找到相关文章

最新更新