如何解决容器位于GROUP内内的精灵不可见
我需要在屏幕上弹很多网球。每个球的中心都有一个标签文本。由于可能有很多球,所以我使用bitMap文本在球上添加标签。
到目前为止,我一直遵循的方法如下:
// Created a GROUP that will hold multiple balls
class Balls extends Phaser.Physics.Arcade.Group {
constructor(scene) {
super(scene.physics.world,scene);
// Keep adding'Ball' to the group here
scene.time.addEvent({
delay: 2000,loop: true,callback: () => {
const ball = new Ball(scene);
this.add(ball);
},});
}
// do some other stuff
}
// Created a CONTAINER that will hold BALL SPRITE with BITMAP TEXT
class Ball extends Phaser.GameObjects.Container {
constructor(scene) {
super(scene,0);
const ball = scene.physics.add.sprite(0,'myBall');
const label = scene.add.bitmapText(0,'fontName','label text');
this.add(ball);
this.add(label);
// Enabling physics on container
scene.physics.world.enable(this);
// Moving/Bouncing balls around the screen
this.body.setVelocity(50,50).setBounce(1).setCollideWorldBounds(true);
}
// do some other stuff
}
现在的问题是,球在屏幕上不可见,但是它们存在并且在屏幕上弹跳良好(转动debug: true
后可以看到容器周围的绿色轮廓)。
我所要做的就是在屏幕上的中心附近打一些网球,标签文本在中间(需要经常更新)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。