如何制作快速刷新的计数器?

时间:2014-06-09 12:57:36

标签: smallbasic

我试图制作一个令人耳目一新的反击......举个例子 - 让我们使用鼠标的位置(在窗口内)。

我尝试过清理并重新绘制所有内容,但是当有很多元素需要绘制时,它总是会出错。

a = 1
While(a = 1)
  Program.Delay(10)
  GraphicsWindow.Clear()
  GraphicsWindow.DrawText(10,10,Mouse.MouseX)
  GraphicsWindow.DrawText(10,20,Mouse.MouseY)
EndWhile  

哪个有效...除非它因为刷新太快而闪烁......如果我要增加延迟,它将无法正常工作,尤其是在做秒表之类的事情时。问题是它也无法支持大量命令...喜欢:

a = 1
While(a = 1)
  Program.Delay(10)
  GraphicsWindow.Clear()
  GraphicsWindow.DrawText(10,10,Mouse.MouseX)
  GraphicsWindow.DrawText(10,20,Mouse.MouseY)
  GraphicsWindow.DrawText(100,100,"Text")
  GraphicsWindow.BrushColor = "#FF0000"
  GraphicsWindow.DrawText(100,200,"Text")
  GraphicsWindow.BrushColor = "#00FF00"
  GraphicsWindow.DrawText(100,300,"Text")
  GraphicsWindow.BrushColor = "#0000FF"
  GraphicsWindow.DrawText(100,400,"Text")
  GraphicsWindow.BrushColor = "#000FF0"
  GraphicsWindow.DrawText(200,100,"Text")
  GraphicsWindow.BrushColor = "#FF0000"
  GraphicsWindow.DrawText(200,200,"Text")
  GraphicsWindow.BrushColor = "#0FF000"
  GraphicsWindow.DrawText(200,300,"Text")
  GraphicsWindow.BrushColor = "Black"
EndWhile

这只是一个大闪光的混乱...并且删除GraphicsWindow.clear()也不是一个选项,因为它会覆盖一团糟......

a = 1
While(a = 1)
  Program.Delay(10)
  GraphicsWindow.DrawText(10,10,Mouse.MouseX)
  GraphicsWindow.DrawText(10,20,Mouse.MouseY)
EndWhile  

或类似的东西: http://i.stack.imgur.com/4sfSS.png

<小时/> 所以,我的问题:
有没有办法让一个可以顺利刷新的计数器而不闪烁,可以在后台绘制很多额外的东西;在窗口的其他地方?像下面的东西,但也移动。
http://i.stack.imgur.com/aZQ5T.png

很抱歉链接乱七八糟:发布图片的声誉不够......

2 个答案:

答案 0 :(得分:1)

这不是一个很好的方法。

做得更简单,没有任何扩展,试试这个:

GraphicsWindow.Show()
Text = Shapes.AddText("")
Shapes.Move(Text,100,100)

While 1 = 1
Program.Delay(5)
Shapes.SetText(Text,Clock.Second)
EndWhile

您正在添加文本形状,然后只需将文本设置为变量即可。

答案 1 :(得分:0)

您可以通过重写刚刚清除的元素来减少闪烁效果。 例如,&#34;删除&#34;通过绘制一个矩形(比GraphicsWindow.Clear()更快)然后立即使用DrawText来创建文本。

但这种刷新方式总会产生闪光。 更好的选择是使用Fremy的FC扩展,它具有添加&#34; changable&#34; GW的文本元素(称为Label)。 Fremy的扩展为SB提供了大量额外功能,它使语言可用于创建实际程序。它类似于JavaScript的JQuery。我强烈建议您使用它,只需下载* .dll库即可。有关SB Wiki thread的更多信息。

语法:

FCControls.AddLabel(Width [px], Height [px], Text)

示例:

mylabel = FCControls.AddLabel(100, 30, "loading...")
FCControls.Move(mylabel,10,10)

While "true"
...
FCControls.SetText(mylabel,value)
EndWhile

这使您可以刷新文本而不会闪烁。

额外提示:您可以使用While "true"创建无限循环。