2016-11-20 40 views
0

在iPhone上將畫布連接到文檔時出現問題。運行時:cordova編譯然後:cordova啓動瀏覽器畫布被添加並渲染罰款。使用xcode和ios模擬器,應用程序將啓動,但看起來畫布從未呈現。我在這裏做錯了什麼?畫布將不會呈現在與科爾多瓦和pixi.js的iPhone上

onDeviceReady: function() { 
    this.receivedEvent('deviceready'); 

    var Container = PIXI.Container, 
     autoDetectRenderer = PIXI.autoDetectRenderer, 
     loader = PIXI.loader, 
     resources = PIXI.loader.resources, 
     Sprite = PIXI.Sprite, 
     Rectangle = PIXI.Rectangle, 
     TextureCache = PIXI.TextureCache, 
     Graphics = PIXI.Graphics, 
     Text = PIXI.Text, 
     ParticleContainer = PIXI.ParticleContainer, 
     stage, 
     renderer; 

    stage = new Container(); 

    renderer = new autoDetectRenderer(window.innerWidth, window.innerHeight); 

    document.body.appendChild(renderer.view); 


}, 

回答

1

在該代碼示例中,您永遠不會實際渲染容器。檢查PIXI的例子這裏:https://pixijs.github.io/examples/#/basics/basic.js

所以你還需要調用: renderer.render(stage);

而你很可能需要requestAnimationFrame(functionToCall);當你有移動部件時,請打電話到實際運行遊戲。

1

與其他答案一樣,您需要使用本機方法​​遞歸調用renderer.render(stage)。此外,Cordova只是一個在Web View中運行的網頁,這個例子將在任何Web瀏覽器中運行。

onDeviceReady: function() { 
    this.receivedEvent('deviceready'); 
    var Container = PIXI.Container, 
    autoDetectRenderer = PIXI.autoDetectRenderer, 
    loader = PIXI.loader, 
    resources = PIXI.loader.resources, 
    Sprite = PIXI.Sprite, 
    Rectangle = PIXI.Rectangle, 
    TextureCache = PIXI.TextureCache, 
    Graphics = PIXI.Graphics, 
    Text = PIXI.Text, 
    ParticleContainer = PIXI.ParticleContainer, 
    stage, 
    renderer; 
    stage = new Container(); 
    renderer = new autoDetectRenderer(window.innerWidth, window.innerHeight); 
    document.body.appendChild(renderer.view);   
    // requestAnimationFrame will make gameLoop recursive 
    function gameLoop() { 
     // Loop this function 60 times per second 
     requestAnimationFrame(gameLoop); 
     //HERE: <-- the logic of your game or animation 
     renderer.render(stage); 
    } 
    gameLoop(); 

},

有關更多解釋有關​​閱讀下面的鏈接https://www.paulirish.com/2011/requestanimationframe-for-smart-animating/