Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/402.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 相位器3创建圆形区域_Javascript_Typescript_Phaser Framework - Fatal编程技术网

Javascript 相位器3创建圆形区域

Javascript 相位器3创建圆形区域,javascript,typescript,phaser-framework,Javascript,Typescript,Phaser Framework,有一个特定的类“怪物”。他有一个所谓的农业区。当玩家进入时,它被激活。但问题是我做不到,我不知道如何让它恢复过来。这一领域有专家可以告诉你如何做对吗 TS上的类别代码: import Creature from "./Creature"; export default class Monster extends Creature { private readonly speed: number; private agroZone!: Phaser.GameObjects.Zon

有一个特定的类“怪物”。他有一个所谓的农业区。当玩家进入时,它被激活。但问题是我做不到,我不知道如何让它恢复过来。这一领域有专家可以告诉你如何做对吗

TS上的类别代码:

import Creature from "./Creature";

export default class Monster extends Creature {
    private readonly speed: number;
    private agroZone!: Phaser.GameObjects.Zone;
    private target!: Phaser.Physics.Arcade.Sprite

    constructor(scene: Phaser.Scene, x: number, y: number, texture: string, 
frames?: string | number) {
        super(scene, x, y, texture, frames);

        this.hp.max = 10;
        this.hp.current = 10;
        this.hpBarConfig = {
            x: 250,
            y: 10,
            color: 0x15fa03,
            fixed:true
        };

        this.updateHpBar();

        this.speed = 50;

        this.scene.events.on('update', this.updateScene);
    }

    private updateScene = () => {
      this.checkAgroZone(this.target);
    };

    public initAgroZone = (target: Phaser.Physics.Arcade.Sprite) =>{
        this.target = target;
        this.agroZone = this.scene.add.zone(this.body.x, this.body.y, 200, 200);
        this.agroZone.setOrigin(0.5, 0.5);
        this.scene.physics.world.enable(this.agroZone, 0);
        this.agroZone.body.moves = false;
        this.scene.physics.add.overlap(target, this.agroZone);

        this.agroZone.on("enterzone", () => {console.log("!!!!!!!!!!!");});
    };

    private checkAgroZone = (target) => {
        if(target){
            const touching = this.agroZone.body.touching;
            const wasTouching = this.agroZone.body.wasTouching;

            if (touching.none && !wasTouching.none) {
                this.agroZone.emit('leavezone');
            }
            else if (!touching.none && wasTouching.none) {
                this.agroZone.emit('enterzone');
            }

            this.agroZone.body.debugBodyColor = 
this.agroZone.body.touching.none ? 0x00ffff : 0xffff00;
        }
    };

    chaseTarget(obj: Phaser.Physics.Arcade.Sprite){
        this.scene.physics.moveToObject(this, obj, this.speed);
    }
}

如果你想画一个圆圈,这里是怎么做的

var配置={
宽度:800,
身高:600,
类型:Phaser.AUTO,
加载器:{
baseURL:'https://raw.githubusercontent.com/nazimboudeffa/assets/master/',
交叉源:“匿名”
},
父级:'相位器示例',
物理学:{
默认值:“arcade”
},
场景:{
预加载:预加载,
创建:创建,
更新:更新
}
};
var game=new Phaser.game(配置);
var播放器;
变量游标;
函数预加载()
{
this.load.image('dude','sprites/phaser dude.png')
}
函数创建()
{
var graphics=this.add.graphics({fillStyle:{color:0xff0000}});
var循环=新的相量器几何循环(50,50,50);
图形。填充圆形(圆形);
这个。物理。添加。现有(图形);
player=this.physics.add.sprite(300100,'dude');
player.setCollizeWorldBounds(true);
cursors=this.input.keyboard.createCursorWorkeys();
这个.physics.add.overlap(播放器、图形、inZone);
}
区域()中的函数{
console.log(“圈中玩家”)
}
函数更新()
{
if(游标。左。isDown)
{
player.setVelocityX(-160);
}
else if(cursors.right.isDown)
{
player.setVelocityX(160);
}
else if(游标。向下。isDown)
{
player.setVelocityY(160);
} 
else if(cursors.up.isDown)
{
player.setVelocityY(-160);
}
}
在相量器3中,区域不是圆,您可以尝试
setCircleDropZone
方法

public initAgroZone = (target: Phaser.Physics.Arcade.Sprite) =>{
        this.target = target;
        this.agroZone = this.scene.add.zone(this.body.x, this.body.y, 200, 200);
        this.agroZone.setOrigin(0.5, 0.5);
        // make it a circle
        this.agroZone.setCircleDropZone(100); // radius = 100
        //etc.
或者,我认为您可以使用一个,然后处理重叠而不是碰撞

mysprite = this.physics.add.image(400, 300, 'myimage')
        .setBounce(1, 1)
        .setCollideWorldBounds(true)
        .setCircle(46);

this.physics.add.overlap(mysprite, mygroup);

还有,玩家的方形入口区域,但我需要一个圆圈。如果在游戏arcade:{debug:true}中启用arcade,您将看到