在屏幕上移动形状并使其消失
Moving a shape across the screen and making it disappear
我目前使用的这个程序可以运行,但是当它进入 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 毫秒后将形状从当前位置移动到 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
希望对您有所帮助!!
--佐克
我目前使用的这个程序可以运行,但是当它进入 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 毫秒后将形状从当前位置移动到 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
希望对您有所帮助!!
--佐克