Javascript 我如何才能正确地订购tilemap,使其显示在具有Phaser的最底层?
我一直在使用Phaser开发一个小游戏,并且大部分都能正常工作,但是总体来说,各个部分都不能正常工作。出于某种奇怪的原因,主tilemap(意味着作为基础层)被设置在其他所有内容之上 我通过移除地图仔细检查了这一点,并且看到了屏幕上生成的小行星阴影。即使将小行星群的深度设置为200或更多,地图仍然显示在顶部,使用“group.sort”似乎没有效果。我怎样才能解决这个问题Javascript 我如何才能正确地订购tilemap,使其显示在具有Phaser的最底层?,javascript,phaser-framework,Javascript,Phaser Framework,我一直在使用Phaser开发一个小游戏,并且大部分都能正常工作,但是总体来说,各个部分都不能正常工作。出于某种奇怪的原因,主tilemap(意味着作为基础层)被设置在其他所有内容之上 我通过移除地图仔细检查了这一点,并且看到了屏幕上生成的小行星阴影。即使将小行星群的深度设置为200或更多,地图仍然显示在顶部,使用“group.sort”似乎没有效果。我怎样才能解决这个问题 GameObject.Engine = function() {}; GameObject.Engine.prototyp
GameObject.Engine = function() {};
GameObject.Engine.prototype = {
init : function()
{
this.map;
this.cursors;
this.mapLayer = System.add.group();
this.mapLayer.z = 0;
this.asteroidShadowGroup = System.add.group();
this.asteroidShadowGroup.z = 200;
this.mapSizeWidth = 1280;
this.mapSizeHeight = 960;
this.bufferZone = 60;
System.world.setBounds(0, 0, this.mapSizeWidth, this.mapSizeHeight);
this.initPhysics();
},
initPhysics :function()
{
System.physics.startSystem(Phaser.Physics.ARCADE);
this.asteroidShadowGroup.enableBody = true;
this.asteroidShadowGroup.physicsBodyType = Phaser.Physics.ARCADE;
},
create : function()
{
this.map = System.add.tilemap('World');
this.map.addTilesetImage('Tiles', 'Background');
this.map.createLayer('BaseWorld');
this.cursors = System.input.keyboard.createCursorKeys();
this.buildAsteroids();
},
update: function() {
this.asteroidShadowGroup.forEachExists(this.checkBoundaries, this);
if (this.cursors.up.isDown)
{
System.camera.y -= 4;
}
else if (this.cursors.down.isDown)
{
System.camera.y += 4;
}
if (this.cursors.left.isDown)
{
System.camera.x -= 4;
}
else if (this.cursors.right.isDown)
{
System.camera.x += 4;
}
},
checkBoundaries: function (sprite) {
if (sprite.x < -this.bufferZone) {
sprite.x = this.mapSizeWidth + this.bufferZone;
} else if (sprite.x > this.mapSizeWidth + this.bufferZone) {
sprite.x = -this.bufferZone;
}
if (sprite.y < -this.bufferZone) {
sprite.y = this.mapSizeHeight + this.bufferZone;
} else if (sprite.y > this.mapSizeHeight + this.bufferZone) {
sprite.y = -this.bufferZone;
}
},
buildAsteroids: function () {
for (var i=0; i < 8; i++ ) {
var x;
var y;
x = System.rnd.integerInRange(0, this.mapSizeWidth);
y = System.rnd.integerInRange(0, this.mapSizeHeight);
this.createAsteroid(x, y);
}
},
createAsteroid: function (x, y) {
var asteroid = this.asteroidShadowGroup.create(x, y, 'asteroids', System.rnd.integerInRange(0, 12));
asteroid.anchor.set(0.5, 0.5);
asteroid.angularVelocity = System.rnd.integerInRange(0, 360);
var randomAngle = System.math.degToRad(System.rnd.angle());
var randomVelocity = System.rnd.integerInRange(10, 40);
System.physics.arcade.velocityFromRotation(randomAngle, randomVelocity, asteroid.body.velocity);
}
}
GameObject.Engine=function(){};
GameObject.Engine.prototype={
init:function()
{
这张地图;
这是游标;
this.mapLayer=System.add.group();
这个.mapLayer.z=0;
this.group=System.add.group();
这个.z组=200;
this.mapSizeWidth=1280;
this.mapSizeHeight=960;
这个缓冲区=60;
System.world.setBounds(0,0,this.mapSizeWidth,this.mapsizehHeight);
这个。initPhysics();
},
初始物理:函数()
{
系统。物理。启动系统(相位器。物理。拱廊);
this.shadowgroup.enableBody=true;
this.shadowgroup.physicsBodyType=Phaser.Physics.ARCADE;
},
创建:函数()
{
this.map=System.add.tilemap('World');
this.map.addTilesetImage('Tiles','Background');
this.map.createLayer('BaseWorld');
this.cursors=System.input.keyboard.CreateCursorWorkeys();
这个。buildasteros();
},
更新:函数(){
this.shadowgroup.forEachExists(this.checkbounders,this);
if(this.cursors.up.isDown)
{
系统摄像机y-=4;
}
else if(this.cursors.down.isDown)
{
系统摄像机y+=4;
}
if(this.cursors.left.isDown)
{
系统.camera.x-=4;
}
else if(this.cursors.right.isDown)
{
System.camera.x+=4;
}
},
检查边界:函数(精灵){
if(sprite.x<-此.bufferZone){
sprite.x=this.mapSizeWidth+this.bufferZone;
}else if(sprite.x>this.mapSizeWidth+this.bufferZone){
sprite.x=-this.bufferZone;
}
if(sprite.y<-此缓冲区){
sprite.y=this.mapSizeHeight+this.bufferZone;
}else if(sprite.y>this.mapSizeHeight+this.bufferZone){
sprite.y=-this.bufferZone;
}
},
构建小行星:函数(){
对于(变量i=0;i<8;i++){
var x;
变量y;
x=System.rnd.integerInRange(0,this.mapSizeWidth);
y=System.rnd.integerInRange(0,this.mapSizeHeight);
这个。创建小行星(x,y);
}
},
创建小行星:函数(x,y){
var asteroid=this.asteroidShadowGroup.create(x,y,'asteroids',System.rnd.integeringrange(0,12));
小行星。锚。设置(0.5,0.5);
小行星角速度=系统rnd积分范围(0360);
var randomAngle=System.math.degToRad(System.rnd.angle());
var randomVelocity=系统rnd整数范围(10,40);
系统。物理。拱廊。旋转速度(随机角,随机速度,小行星。天体。速度);
}
}
在create()
方法中创建this.map
后,您可以创建并初始化您的组
一般来说,如果你想在不同的“z”层中添加组,那么将它们添加到游戏中的顺序很重要。
例如,如果您有:
this.groupA = this.game.add.group();
this.groupB = this.game.add.group();
this.groupC = this.game.add.group();
然后渲染顺序将始终为:
- groupA背景
- B组中老年人
- C组前景
可能有一些方法,比如
bringtop()
,您可以在其中操纵订单,但您必须在文档中搜索 哎呀!这就是问题所在。我没有意识到先初始化组会自动将其压到底。