0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Code9leapで最初に表示される「START」を消したい

Last updated at Posted at 2019-06-29

最初の「START」が要らないとき

code9leapで実行すると必ず表示されるのが、画面中央の「START」。
ここをクリックさせることでゲーム表示画面をアクティブにするねらいがあるのかもしれませんが、場合によっては要らないことも。。。

image.png

「START」は、nineleap.enchant.jsで表示している

そこで、index.htmlの中にあるnineleap.enchant.jsを読み込んでいる部分をコメントアウトすれば、解決です。

<!doctype html>
<html>
<head>
    <link rel='stylesheet' href='style.css' type='text/css'>
    <script src='/static/enchant.js-latest/enchant.js'></script>
<!--    <script src='/static/enchant.js-latest/plugins/nineleap.enchant.js'></script>-->
    <script src='/code.9leap.js'></script>
    <script src='main.js'></script>
    <title>Page title</title>
</head>
<body>
</body>
</html>

ゲーム開始からの経過時間を表示したい。

ところでなぜこんなことをすることになったかというと、開始からの経過時間を計測したい場合です。
デフォルトで表示される「START」を押されたタイミングを取得するのは複雑そうでしたので、デフォルトで表示される方は消して、オリジナルのボタンを出した方がシンプルで良いのではと思いテストしてみました。

enchant();

window.onload = function(){
    var game = new Core(320, 320);
    var timeflg = false;
    var time;
    game.fps = 15;
    game.preload("start.png");
    game.onload = function(){
        
        // 時間表示用
        var label = new Label("push start");
        label.x = 70;
        label.y = 100;
        label.font = "30px Sans-Serif";
        game.rootScene.addChild(label);
        
        // スタートボタン
        var button = new Sprite(230,50);
        button.image = game.assets["start.png"];
        button.x = 40;
        button.y = 260;
        game.rootScene.addChild(button);
        
        // ボタンが押されたらフラグをTrueにする
        button.addEventListener("touchend",function()
        {
            console.log(timeflg);
            time = 0;
            timeflg = true;
            
            game.rootScene.removeChild(button);
        });
        
        game.addEventListener('enterframe', function() {
            // Trueのときだけカウントアップ
            if(timeflg)
            {
                time++;
                label.text = Math.floor(time / game.fps);
            }
        });
        
    };
    game.start();
};

code9leapのサンプルプロジェクト(Chromeで動作させてください)。
http://code.9leap.net/codes/show/164403

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?