问题描述
我需要在屏幕上弹很多网球。每个球的中心都有一个标签文本。由于可能有很多球,所以我使用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 (将#修改为@)