私は次のコードを使用しています:
ground1.x = ground1.x - 10
ground2.x = ground2.x - 10
ground3.x = ground3.x - 10
ground4.x = ground4.x - 10
ground5.x = ground5.x - 10
ground6.x = ground6.x - 10
ground7.x = ground7.x - 10
ground8.x = ground8.x - 10
if(ground1.x < ( 0 - 75 ) ) then
ground1:removeSelf()
ground1 = ground2
ground2 = ground3
ground3 = ground4
ground4 = ground5
ground6 = ground7
ground7 = ground8
local num = math.random ( 1, 4 )
ground8 = display.newImage( group, "normalground"..num..".png", ground7.x + ground7.contentWidth/2, display.contentHeight - 52 )
動く地面をアニメーション化します。私は8つのタイル、ground1-ground8を使用しています。このコードは、「enterFrame」で呼び出されるアニメーション関数内にあります。
私がやろうとしているのは、「ground1」が左端から移動したことを検出することです。次に、タイル Ground2 を Ground1 に、Ground 3 を Ground2 に、というように再割り当てし、最後に新しいタイルを作成してそれを Ground8 に割り当てます。
バックグラウンドスクロールで同様のことを行いましたが、正常に機能しています。ただし、このコードを実行しようとすると、しばらくは機能します (最初の 4 つのタイルが正常にスクロールされます) が、タイル 5 を Ground1 に割り当ててアニメーション プロセスに戻ろうとすると、次の例外が発生します。
フィールド 'x' (nil 値) で演算を実行しようとしました
何か案は?