注意:現在のスプライト機能は非常に重いので、使える場所が限られます。
// スプライトテスト2
// V2.00以降専用
// グラフィックモードに設定
width(0)
int wgx,wgy
getWidth(wgx,wgy):// グラフィックモードで画面幅を取得
//locate(0,2):print "Graphic Width:";wgx;"*";wgy
//
sp_init():// ここでスプライト画面は非表示になる
width(32)
vpage(B_SPAGE+B_TPAGE,YES):// display sprite screen
vpriority(TPAGE,SPAGE,GPAGE0,GPAGE1,GPAGE2,GPAGE3)
cls()
tborder(1,CTHCYAN)
//
// タッチした位置からにスプライトパターンを表示する
//
str exit$,mes$
if isLocalizeJapan() then {
exit$="中断"
mes$="画面にタッチ&ドラッグしてください"
} else {
exit$="exit"
mes$="Please touch & drag"
}
setFunctionKey(0, exit$ ,'!')
setFunctionKey(1,"SPst" ,'S')
setFunctionKey(2,"BGst" ,'B')
setFunctionKey(3,"Dprw" ,'p')
setFunctionKey(4,"disp" ,'d')
setFunctionKey(5,"OFF" ,'F')
setFunctionKey(6,"ON" ,'O')
setFunctionKey(7,"BGget",'G')
setFunctionKeyBackgroundImage("funcBack.png")
displayFunctionKeyAll(YES,YES):// v2.0
//
setTouchArea(0,0,0,0,0,YES):// これがないと任意のタッチ座標を得られない
//
// パターンは512個定義できるが、表示=プレーンは256個まで
sp_halt(YES):// しばらくスプライトの表示を中止
int pwx=16,pwy=16
int tsp=0,esp=0
esp=sp_image("IMG1.JPG",110,260,pwx,pwy,tsp,tsp,wgx/3,wgy/3,SPRITE_PRW_BG0SPBG1,YES):// pwx,pwyは補正される
locate(12,0):print "SP:";tsp;"〜";esp-1
//---------------------
// 関数テスト
//dim int ptn(255)
//sp_pat(tsp,ptn)
//int fp
//fp=fopen("pat.dat","w")
//fwrite(ptn,255,fp)
//fclose(fp)
//---------------------
//
// sprite pattern (X68 type)
dim char ca(255) = { // 網目
0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
, 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1
, 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0
}
int pb1=3:// パレットブロック番号
int pb2=2:// パレットブロック番号
sp_color(0,&h00000000,pb1):// 透明
sp_color(0,&h00000000,pb2):// 透明
sp_color(1,&h000080ff,pb1)
sp_color(1,&h800000ff,pb2)
sp_def(esp,ca)
sp_clr(esp+1)
//
int pg0=0:// BGテキストページ番号
int pg1=1:// BGテキストページ番号
int x,y
bg_fill(pg0,esp,pb1,SPRITE_FLIP_NONE):// 一旦全体を埋める
// wg?/16 : 画面幅のスプライト単位の数
// 中央を抜く
int bwx=wgx/16,bwy=wgy/16
for y=bwy/4 to bwy*3/4
for x=bwx/4 to bwx*3/4
bg_put(pg0,x,y,esp+1,pb1)
next
next
bg_set(1,pg0,YES)
//
bg_fill(pg1,esp+1,pb1,SPRITE_FLIP_NONE):// 一旦全体をクリアする
// 中央に描画
for y=bwy*4/10 to bwy*5/10
for x=0 to bwx
bg_put(pg1,x,y,esp,pb2)
next
next
bg_set(0,pg1,YES)
//
//mapSprite(wgx/3,wgy/3,tsp,pwx,pwy)
sp_halt(NO):// スプライトの表示を再開
//
dim float tpoint(2)
int touchCnt
str cs
int dt=0,t
int ts=time():/* 開始時間
locate(0,1):print mes$
//
int i
int x0=-1,y0=-1
int fDisableBG0SPBG1=NO
prfDisableBG0SPBG1(fDisableBG0SPBG1)
int fdisp=YES
sp_disp(fdisp)
repeat
// キー入力待ちしながら時計を回す
while (not kbhit())
t=time()
if t-ts>dt then { :/* 秒が変った
dt=dt+1
// locate(20,0):print dt;
// beep2(0)
// locate(20,1)
}
touchCnt=getTouchPoint(tpoint)
if (touchCnt>0) then {
x=tpoint(0):// float → int
y=tpoint(1)
if x<>x0 or y<>y0 then {
locate(0,0):print x;",";y
mapSprite(x,y,tsp,pwx,pwy)
//
x0=x
y0=y
}
// 同じ座標の時は再表示しないようにしないとちらつく
}
endwhile
// キー操作判定
cs=inkey$()
switch cs
case "S":// Sprite stat
for i=0 to 5
locate(0,2+i)
print "i=";i;":";sp_stat(tsp,i)
next
break
case "B":// BG stat
for i=0 to 3
locate(16,2+i)
print "i=";i;":";bg_stat(0,i)
next
break
case "p":// Disable BG0SPBG1
if fDisableBG0SPBG1 then fDisableBG0SPBG1=NO else fDisableBG0SPBG1=YES
prfDisableBG0SPBG1(fDisableBG0SPBG1)
break
case "d":// sp_disp
if fdisp then fdisp=NO else fdisp=YES
sp_disp(fdisp)
break
case "F":// sp_off
sp_off(tsp,esp-1):// このプログラム中ではプレーン番号とパターン番号を合わせてあるから
break
case "O":// sp_on
sp_on(tsp,esp-1,SPRITE_PRW_BG0SPBG1):// このプログラム中ではプレーン番号とパターン番号を合わせてあるから
break
case "G":// bg_get
getBG(pg0,bwx,bwy)
getBG(pg1,bwx,bwy)
break
endswitch
until cs="!"
print "Sprite version=";versionXBiOSSprite$()
//
end
func mapSprite(gx;int,gy;int,tsp;int,pwx;int,pwy;int)
int wx,wy
sp_halt(YES):// 以下一括変更するので終了まで表示停止
for wy=0 to pwy-1
for wx=0 to pwx-1
// sp_image()では全てiOS型で定義されるのでパレットは無効
sp_setting(tsp,gx+wx*16,gy+wy*16)
tsp=tsp+1
next
next
sp_halt(NO):// 表示再開
endfunc
func prfDisableBG0SPBG1(fDisableBG0SPBG1;int)
dim str strfDisableBG0SPBG1(1)={"-","D"}
sp_disableBG0SPBG1(fDisableBG0SPBG1)
locate(31,0):print strfDisableBG0SPBG1(-fDisableBG0SPBG1)
endfunc
func getBG(pg;int,x;int,y;int)
int pb,flip,ptn
ptn=bg_get(pg,x,y,pb,flip)
locate(0,10+pg*2) :print "pg=";pg;":x=";x;"/y=";y
locate(0,10+pg*2+1):print "pb=";pb;"/flip=";flip;"/ptn=";ptn
endfunc
画像ファイル入りZipファイル :
XBsprite.zip
0 件のコメント:
コメントを投稿