2016-06-24 9 views
0

私はdivでキャンバスに行く空のページを持っています。私はゲームを反応的にしようとしましたが、要素を調べると、キャンバスのサイズが変更されていないことがわかります。キャンバスは反応しません。 PhaserのCSSを使ってキャンバスのサイズを変更したいと思っています。私が純粋なJavaScriptでこれを行うと、私はキャンバスでマウスの位置を拡大する必要があります。だから、どのように反応させるのですか?私はそれを実行しようとしましたPhaserを使用してキャンバスを反応させる方法は?

var game; 

function create() { 

    // Scaling options 
    game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; 

    // Have the game centered horizontally 
    game.scale.pageAlignHorizontally = true; 

    // And vertically 
    game.scale.pageAlignVertically = true; 

    // Screen size will be set automatically 
    game.scale.setScreenSize(true); 

} 

window.onload = function() { 

    // Create game canvas and run some blocks 
    game = new Phaser.Game(1280, 720, Phaser.AUTO, 'frame', { create: create }); 

} 
+0

あなたはフルスクリーンを正しく取得したいですか? 1280年、720年 – RensvWalstijn

答えて

0

あなたがここにキャンバスの幅と高さを変更したい場合は、私はそれを行う方法です。 これは、フェーザー溶液だと思います。試してみてください。私はPhaserを使ったことがありません。

あなたのページ:

var bSize = { 
    bWidth: window.innerWidth || 
    root.clientWidth || 
    body.clientWidth, 
    bHeight: window.innerHeight || 
    root.clientHeight || 
    body.clientHeight, 
}; 

var game; 

var canvas = document.getElementById("canvas"); 

function create() { 

    // Scaling options 
    game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; 

    // Have the game centered horizontally 
    game.scale.pageAlignHorizontally = true; 

    // And vertically 
    game.scale.pageAlignVertically = true; 

    // Screen size will be set automatically 
    game.scale.setScreenSize(true); 
} 

window.onload = function() { 

    // Create game canvas and run some blocks 
    game = new Phaser.Game(
     bSize.bWidth, //is the width of your canvas i guess 
     bSize.bHeight, //is the height of your canvas i guess 
     Phaser.AUTO, 
     'frame', { create: create }); 

    canvas.style.position = "fixed"; 
    canvas.style.left = 0; 
    canvas.style.top = 0; 
} 

私はそれはあなたを助け願っています!

関連する問題