Simple Maze, created with Tiled
所以,最初的计划是通过Tilemaps创建一个迷宫,如果玩家(从左上角开始)触摸到右下角的东西,下一关应该被加载。到目前为止,我所做的是创建墙之间的碰撞(黑色),现在我真的不知道如何开始“碰撞”的东西在右下角。
到目前为止,这是我的代码
var labGame = labGame || {};
labGame.Game = function() {};
var map;
var layer;
var player;
var controls = {};
var playerSpeed = 350;
var jumpTimer = 0;
labGame.Game.prototype = {
create: function() {
map = this.add.tilemap("map", 64, 64);
map.addTilesetImage("tileset");
layer = map.createLayer(0);
layer.resizeWorld();
map.setCollisionBetween(2, 2);
player = this.add.sprite(64, 384, "player");
player.anchor.setTo(0,5, 0,5);
this.physics.arcade.enable(player);
this.camera.follow(player);
player.body.collideWorldBounds = true;
controls = {
right: this.input.keyboard.addKey(Phaser.Keyboard.D),
left: this.input.keyboard.addKey(Phaser.Keyboard.A),
up: this.input.keyboard.addKey(Phaser.Keyboard.W),
down: this.input.keyboard.addKey(Phaser.Keyboard.S),
}
},
update: function() {
player.body.velocity.x = 0;
player.body.velocity.y = 0;
this.physics.arcade.collide(player, layer);
if(controls.right.isDown) {
player.body.velocity.x += playerSpeed;
}
if(controls.left.isDown) {
player.body.velocity.x -= playerSpeed;
}
if(controls.up.isDown) {
player.body.velocity.y -= playerSpeed;
}
if(controls.down.isDown) {
player.body.velocity.y += playerSpeed;
}
}
};
(在phaser论坛中有人写道,Boot.js等东西后来更容易“处理”,所以我开始使用它)
发布于 2017-01-02 06:40:39
可以使用平铺对象层。
在平铺中,在显示图层的面板下,单击新建图层按钮,但选择新建对象图层。
然后确保图层被选中,并将右下角的瓦片放在地图上。现在,所有的墙都将在平铺层上,对象层上将有一个平铺层。
在代码中,您将添加如下内容:
//Create Exit
//Add the exit tile to a group
exit = this.add.group();
this.map.createFromObjects('Objects', 28, 'door', 0, true, false, exit);
//Apply properties to the exit
exit.forEach(function(exit) {
exit.body.allowGravity = false;
exit.body.immovable = true;
},this);组参数为:createFromObjects( this.map.createFromObjects,gid,key,frame,exists,autoCull,CustomClass,adjustY)
您可以在documentation here.中查看有关这方面的更多信息
现在对象已插入,只需在更新中调用碰撞函数即可。所以就像这样:
update: function() {
this.physics.arcade.overlap(player,exit, this.endLevel)
}
endLevel: function(player,exit) {
//Code for moving to next Level
}https://stackoverflow.com/questions/41401718
复制相似问题