enchant.js ブラックジャック コード 解説4

//ラベルを作る関数
function createLabel(text, x, y, fontSize = “20px”, fontFamily = “monospace”) {
let label = new Label(text);//渡されたテキストでラベルを作成する
label.font = `${fontSize} ${fontFamily}`;//20px monospace;
label.moveTo(x, y);//位置を決めてる
return label;
}

// ボタン作成関数
//onClickActionで受け取るのは今のところ
//buttonActions.hit
//buttonActions.stand
//buttonActions.next
//buttonActions.cheat
function createButton(text, x, y, scene, onClickAction) {
var button = new Button(text, “light”);//ボタンを作成
button.moveTo(x, y);//ボタンの位置を決める
button.ontouchend = onClickAction;//クリック後にそれぞれのイベント発火
scene.addChild(button);//シーンにボタンを追加
return button;
}

// それぞれのボタンを使えないようにする
function disableButtons() {
hitButton.opacity = 0.5;//半透明にする
hitButton.ontouchend = null;//何も起きないようにする
standButton.opacity = 0.5;
standButton.ontouchend = null;
cheatButton.opacity = 0.5;
cheatButton.ontouchend = null;
}

//それぞれのボタンを使えるようにする
function enableButtons() {
hitButton.opacity = 1;//見えるようにする
hitButton.ontouchend = buttonActions.hit;//それぞれのイベントが起きるようにする
standButton.opacity = 1;
standButton.ontouchend = buttonActions.stand;
cheatButton.opacity = 1;
cheatButton.ontouchend = buttonActions.cheat;
}

後日解説追加予定

ブログランキング・にほんブログ村へにほんブログ村

開発ログ一覧

エロゲーム一覧