2017-08-15 65 views
1

我是phaser的新手,我似乎无法让对象创建可见,不管是什么。Phaser没有渲染在组中创建的对象

这里是JS代码:

var game = new Phaser.Game(448, 448, Phaser.AUTO, '', { preload: preload, 
create: create, update: update }); 



function preload() { 
    game.load.image('tabuleiro','assets/tabuleiro.png') 
    game.load.spritesheet('devil','assets/devil.png',32,32); 
    var capetinhas; 
} 

function create(){ 

capetinhas = game.add.group(); 

game.add.sprite(window.width,0,'tabuleiro'); //loading the background 


game.add.sprite(128,128,'devil'); // this works 


capetinhas.create(32,32,'devil'); // this doesnt  

} 

function update(){ 

} 

当我把capetinhas.countLiving()它打印1控制台,这意味着在创建对象但不呈现在。

在此先感谢。

回答

0

尝试将var capetinhas;移动到您的预加载器函数之外,因此它具有全局范围。这看起来像是一个示波器错误 - capetinhaspreload()内定义,因此create()无法访问该变量。

0

试试这个我相信我得到它正确没有选中,但我改变了几个东西,只是比较你的。

//this will all go in one state 
var game = new Phaser.Game(448, 448, Phaser.AUTO, '', { 
    preload: preload, 
    create: create, 
    update: update 
}); 

var main={ 

    preload:function() { 
     game.load.image('tabuleiro','assets/tabuleiro.png') 
     game.load.spritesheet('devil','assets/devil.png',32,32); 

    }, 

    create:function(){ 
     this.capetinhas = game.add.group(); 
     game.add.sprite(window.width,0,'tabuleiro'); //loading the background 
     game.add.sprite(128,128,'devil'); // this works 
     this.capetinhas.create(32,32,'devil'); // this doesnt  
    }, 

    update:function(){ 
    }, 
}; 

var capetinhas; 

我在移动,所以我不能检查功能,但尝试,如果它不工作然后删除创建组部分作出之间的一个新功能创建和更新称之为防爆

evil: function(){ 
    // and in here do your group calls while using the “this.” So you can comunícate outside of the function 
}