基本的なスクリプト例


基礎

直線移動


obj.ox = obj.ox + obj.time*25



円移動


l = 100                  --半径
r = 360*obj.time/2
obj.ox = obj.ox + math.sin(r*math.pi/180)*l
obj.oy = obj.oy - math.cos(r*math.pi/180)*l
obj.rz = obj.rz + r



複数のオブジェクトを描画


n=5                     --個数
for i=0,n-1 do
  x = 80*i
  obj.draw(x,0)
end



円形に並べる


l=120                  --半径
n=10                   --個数
for i=0,n-1 do
  r  = 360*i/n
  x  =  math.sin(r*math.pi/180)*l
  y  = -math.cos(r*math.pi/180)*l
  rz = 360*i/n
  obj.draw(x,y,0,1,1,0,0,rz)
end



Z軸に沿って円形に並べる


l=120                  --半径
n=10                   --個数
for i = 0,n-1 do
  r  =  360*i/n
  x  =  math.sin(r*math.pi/180)*l
  z  = -math.cos(r*math.pi/180)*l
  ry = -360*i/n
  obj.draw(x,0,z,1,1,0,ry,0)
end



XY軸方向に並べる


nx = 5                --X軸個数
ny = 3                --Y軸個数
dx = 1.2              --X軸間隔
dy = 1.2              --Y軸間隔
for j=0,ny-1 do
  y=obj.h*dy*j
  for i=0,nx-1 do
    x=obj.w*dx*i
    obj.draw(x,y)
  end
end



ランダムに位置を変化


w = obj.screen_w/2
h = obj.screen_h/2
t = math.floor(obj.time/0.5)           --0.5秒ごとに変化
obj.ox = obj.ox + obj.rand(-w,w,0,t)
obj.oy = obj.oy + obj.rand(-h,h,1,t)



ランダムな位置に描画


n = 20  --個数
w = obj.screen_w/2
h = obj.screen_h/2
for i=0,n-1 do
  x = obj.rand(-w,w,i,0)
  y = obj.rand(-h,h,i,1)
  obj.draw(x,y)
end



ときどき拡大


s = obj.rand(0,100)
if( s>80 ) then
  obj.zoom = obj.zoom*2
end




基礎の応用

登場系のスクリプト

登場系のスクリプトで多く使われる例

t=5                        --登場時間
r = (t-obj.time)/t         --登場時間で1→0に変化
if( r>0 ) then
  obj.oy = obj.oy -200*r
end



なめらか登場


t=5                       --登場時間
r = (t-obj.time)/t        --登場時間で1→0に変化
if( r>0 ) then
  if( r>1 ) then          --rの最大値を1に制限
    r = 1
  end
  r = r*r                 --なめらかに移動
  obj.oy = obj.oy -200*r
end



順番にフェードして登場


obj.effect()                      --フィルタ効果を遡って適用できるように
n=5                               --個数
ta=5                              --登場時間
tb=1                              --登場間隔
for i = 0,n-1 do
  r = (ta-obj.time+i*tb)/ta       --間隔をずらして1→0に変化
  r = math.min(1,math.max(r,0))   --rを0~1の範囲に限定(関数を使用する方法)
  x = 100*i
  obj.draw(x,0,0,1,1-r)
end



obj.index

※テキストオブジェクトで使用し、「文字毎に個別オブジェクト」をチェックする必要あり

obj.oy = obj.oy + 10*obj.index



テキストオブジェクト内でのカウントダウン

【残り時間を表示】
残り時間 <?mes(math.floor(obj.totaltime-obj.time))?> 秒
【任意の数値でカウントダウン】
9999秒から17倍の速さでカウントダウン
<?a=9999 b=17
mes(string.format("%04d",a-obj.time*b))?>

【任意の数値で増加】
5000秒から17倍の速さで増加
<?a=5000 b=17
mes(string.format("%04d",a+obj.time*b))?>

【現在時刻】
(lua.txtより)
<?mes(string.format("%02d:%02d.%02d",obj.time/60,obj.time%60,(obj.time*100)%100))?>
【時間表記でのカウントダウン】
10分(600秒)から17倍の速さでカウントダウン
<?a=600 b=17 t=a-obj.time*b
mes(string.format("%02d:%02d.%02d",t/60,t%60,(t*100)%100))?>


  • 最終更新:2011-12-17 19:37:46

このWIKIを編集するにはパスワード入力が必要です

認証パスワード