【发布时间】:2011-07-16 22:01:31
【问题描述】:
我有一组固定的 9 个等距对象。当他们通过屏幕右边缘时,它们会绕到屏幕左侧。
当 object0.x 碰到屏幕的右边缘(720 或 1280)时,它需要绕到 object9 的左侧,它可能在屏幕左侧,并保持与 object9 的距离,对于其他精灵来说也是如此。离开屏幕,他们需要包裹到与前一个对象之间保持距离的相反方向。当向相反方向移动时,当然也需要如此。
目前,事情正在结束,并且正在偏离位置。
这是我当前的代码:(getstartpos() 感谢petar-ivanov)
function getstartpos(objectWidth as integer, startPosition as integer, objectNumber as integer, space as integer)
return startPosition + objectNumber * (objectWidth + space)
end function
sub screenupdate()
m.p0x=m.p0x+ int(m.inc)
if m.p0x > 720
m.p0x = -getstartpos(120,m.p9x,9,20)
?m.p0x
endif
m.p0.MoveTo(m.p0x, m.p0y)
m.p1x = m.p1x + int(m.inc)
if m.p1x > 720
m.p1x = -getstartpos(120,m.p0x,0,20)
?m.p1x
endif
m.p1.MoveTo(m.p1x, m.p1y)
m.p2x = m.p2x + int(m.inc)
if m.p2x > 720
m.p2x = -getstartpos(120,m.p1x,1,20)
?m.p2x
endif
m.p2.MoveTo(m.p2x, m.p2y)
...
m.p9x = m.p9x + int(m.inc)
if m.p9x > 720
m.p9x = -getstartpos(120,m.p8x,8,20)
?m.p9x
endif
m.p9.MoveTo(m.p9x, m.p9y)
end sub
【问题讨论】: