javascript - CONTAINER(位于 GROUP 内)内的 Sprite 不可见
问题描述
我需要在屏幕上弹跳很多网球。每个球的中心都有一个标签文本。由于可能有很多球,我使用位图文本在球上添加标签。
到目前为止,我为实现这一目标所遵循的方法如下:
// 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, 0);
const ball = scene.physics.add.sprite(0, 0, 'myBall');
const label = scene.add.bitmapText(0, 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
)。
我需要做的就是在屏幕上弹一些网球,在它的中心有一个标签文本(需要经常更新它)。
解决方案
推荐阅读
- javascript - ag-grid 列文本截断问题
- firebase - 将我自己的域与 Firebase 动态链接一起使用
- node.js - 将 BLOB 发送到 nodejs API 会导致服务器上的正文为空
- javascript - 如何缩小 JavaScript 缓冲区?
- amazon-web-services - eks 选项在 AWS CLI 中不可用。如何安装它?
- java - Windows 计算机视觉 API - 二进制图像的图像格式无效 - Java
- ios - iPhone X 横向模式下的视图看起来不正确
- javascript - 为什么 Promise 在 sequelize 中返回
- python - 如何从包含数字和名称的值列表中仅检索名称?
- c# - 在使用 WebClient 下载文件期间出现错误访问被拒绝?