0
我正在嘗試用移相器製作遊戲。我用一個objectlayer創建了一個tilemap。然而,當我試圖將對象從對象層添加到組「檢查器」時,重疊不起作用。 這裏是我的代碼:createFromObjects()在phaser中不工作?
function preload()
{
game.load.spritesheet("bird","assets/flappybird.png",92,64,3);
game.load.tilemap('map', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON);
game.load.image('tiles', 'assets/obstacle.png');
game.load.image('checktiles', 'assets/empty.png');
game.stage.backgroundColor = '#c9c9c9';
}
function create()
{
game.physics.startSystem(Phaser.Physics.ARCADE);
map = game.add.tilemap('map');
//OBSTACLES
map.addTilesetImage('obstacle', 'tiles');
layer = map.createLayer('Tilelaag 1');
layer.resizeWorld();
map.setCollisionBetween(1, 12);
//CHECKERS
checkers = game.add.group();
checkers.enableBody=true;
map.createFromObjects('Object Checkers', 5, 'checktiles', 0, true, false, checkers);
//PLAYER
player=game.add.sprite(92,game.world.heigth-300,"bird");
player.scale.setTo(0.5,0.5);
game.physics.arcade.enable(player);
player.body.gravity.y=300;
player.animations.add("fly",[0,1,2],10,true);
player.body.collideWorldBounds = true;
player.body.velocity.x=150;
//CURSORS
cursors=game.input.keyboard.createCursorKeys();
spacebar=game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
//CAMERA
game.camera.follow(player);
}
function update()
{
var hit=game.physics.arcade.collide(layer,player);
game.physics.arcade.overlap(player, checkers,Addpoint,null,this);
player.animations.play("fly");
if(spacebar.isDown)
{
player.body.velocity.y = -150;
}
if(hit)
{
game.state.restart();
}
}
function Addpoint()
{
console.log("Called");
}