『A-Frame』の勉強続けています
手探り状態ですが分かってきたこともいろいろあって 忘れないうちにメモっときます
シーン内にBoxを作成する
const scene = document.querySelector("a-scene"); let box = document.createElement("a-box"); box.setAttribute("id", "box"); box.setAttribute("position", "0 0 0"); box.setAttribute("scale", "1 1 1"); box.setAttribute("color", "red"); scene.appendChild(box);
シーン内のBoxを削除する
const scene = document.querySelector("a-scene"); let box = document.getElementById("box"); scene.removeChild(box);
クリック(タップ)した時
AFRAME.registerComponent("この処理の名前", { init: function () { this.el.addEventListener("click", function (evt) { //処理 }); }, });
時間の取得
let time = new Date().getTime();
音を鳴らす
var sound= new Audio("ロードした音源のURL" ); sound.play();
タイマー処理
var functionName = function () { //処理 }; setInterval(functionName, 100); //0.1秒ごとに繰り返す clearInterval(functionName); //処理を中止する
これくらい分かってくると簡単なゲームが作れます
Android Studioで初めて作ったゲーム「1から25まで順番にタップする」をA-Frameを使ってWebVRでプレイできるようにしてみました
スマホでQRコードを読み込んで
カメラの設定を許可またはONにすると
こんな感じで遊べます
勉強したことが形になると嬉しくなります
もう少し頑張ってみよ!