我有一个 CircleMorph
,我想扩大它的直径,可能是为了用它创建一个小动画。
b := CircleMorph new.
b color: Color transparent.
b borderWidth: 2.
b extent:100 @ 100.
b openInWorld.
如果我使用循环或 step
方法来执行此操作会好吗?如果您推荐 step
方法,那么我该怎么做?
最佳答案
您可以创建一个 CircleMorph
的子类,称为 GrowingCircleMorph
。
然后执行step
:
step
self extent: (self extent) + 1.
(self extent) > (200@200) ifTrue: [ self stopStepping ]
现在,如果您在世界中打开新的 GrowingCircleMorph 实例,它将开始增长到 201@201。
要更改速度,请实现 stepTime
并返回所需的步骤之间的时间(以毫秒为单位)。
更新:如果你想让中心保持不变,改变你的圆变形的边界,而不是范围:
step
self bounds: ((self bounds) expandBy: 1).
(self extent) > (200@200) ifTrue: [ self stopStepping ]
https://stackoverflow.com/questions/12184484/