ユーザ用ツール

サイト用ツール


soda:sprite_test

文書の過去の版を表示しています。


概要

  • Soda上で動くプログラム書いてみた。
  • 速度的にはまだ詰められる要素があるけど、とりあえずこんなもんで。
  • スプライトを並べて、順番に縮小させてみたもの。意外と見栄えがいい。

利用API/クラス

  • sprites
    現行のバージョンでは1枚しかスプライト用プレーンがないけど、これで十分ではある。
  • window
    ウィンドウのサイズ変更を行った。
  • text
    フレーム情報等を表示するのに使った。

ソースコード

  • スプライト機能を使っているので、画像ファイルが必要なことに注意してください。
  • imageフォルダを作って、その配下に「bullet32.png」というファイルを作れば読み込めます。
//==================================================
// Sprite Draw Test.
//        by MachiaWorks
//==================================================
fileInFolder = function(folderName, fileName)
if not file.exists(folderName) then
	print "Folder """ + folderName + """ not found."
	exit
      end if
      return file.child(folderName, fileName)
end function

picture = file.loadImage(fileInFolder("images", "bullet32.png"))

width_max = 800
height_max = 600
window.width=width_max
window.height=height_max//short?

w_spr=floor(800/32)-1
h_spr=floor(600/32)

for j in range(0,h_spr)
  for i in range(0,w_spr)
      spr = new Sprite
      spr.image=picture //loadimage
      spr.x=i*32
      spr.y=j*32
      spr.scale=1
      sprites.push spr //register sprites
  end for
end for

fixed_frame = 0
update_flag=0

prev_time = 0
now_time =0
frame = 0

delta = 0.0167/2
print_cnt=0
fixed_frame2=0
time_calc=0

while not key.pressed("return")
  update_flag = 0

  //time calc
  //update_flag = 1
  now_time = time

  if now_time-prev_time > delta then
      update_flag=1
      prev_time = now_time
  end if

  //update
  if update_flag == 1 then

      for j in range(0,h_spr)
          for i in range(0,w_spr)
              sprites[j*(w_spr+1)+i].scale = 1-(fixed_frame+i+j)%32*0.05 //register sprites
          end for
      end for

      fixed_frame+=1
      fixed_frame2+= 1

      //wait
      if now_time-prev_time <delta then
          wait (delta - (now_time-prev_time))
      end if
  end if

  frame=frame+1

  if time() - time_calc>1  then
      text.clear
      //print time_calc
      print "frame : "+frame
      print "draw_frame : " + fixed_frame2
      fixed_frame2=0
      frame=0
      time_calc =time
  end if
end while
soda/sprite_test.1745146502.txt.gz · 最終更新: 2025/04/20 19:55 by machiaworx