大家好,我是初学者,尝试做一个2D的坦克游戏,现在已经实现了移动,该实现开火了。
现在想把坦克子弹放在 bullet_pos 的位置,用 UITransform 转换成世界坐标之后,子弹却出现在了右上角,大约歪了半个屏幕,请问要怎么转换才对呀?
(creator 版本是3.6)
图片中的代码如下:
fire() {
let newBullet = instantiate(this.bulletPre)
const bulletPos = this.uiTransform.convertToWorldSpaceAR(Vec3.ZERO)
newBullet.setPosition(bulletPos)
newBullet.angle = this.node.angle + this.cannon.angle
newBullet.setParent(this.canvas)
}
onLoad(){
// 子弹初始位置
this.uiTransform = this.bulletPos.getComponent(UITransform)
// 开火
if (this.fireButton) {
this.fireButton.node.on(NodeEventType.TOUCH_START, () => {
this.fire()
this.firePreparing = true
})
this.fireButton.node.on(NodeEventType.TOUCH_END, () => {
this.firePreparing = false
})
this.fireButton.node.on(NodeEventType.TOUCH_CANCEL, () => {
this.firePreparing = false
})
}
}





