重写 小结一下心得
本人重写了整个项目
有了点小心得
页面跳转
director.loadScene(`s2`)
背景移动
canvas 是画布

为什么要向上图布局?
方便计算相对坐标,脚本还是只写一个
绑定上 BG 一样跑,不影响
export class ts_2_bg extends Component {
@property speed : number = 100
start() {
}
update(deltaTime: number) {
let pos1 = this.node.getPosition()
this.node.setPosition(
pos1.x,
pos1.y - deltaTime * this.speed
)
pos1 = this.node.getPosition()
if (pos1.y < -851) {
this.node.setPosition(pos1.x,852)}
}
}
精简 player
老师的代码好处 所见即所得

本人代码没那么多弯弯绕绕
新手容易绕晕,暂时只用了一种发射模式,
道理是一样的,后续更新双发
@ccclass('ts_player')
export class ts_player extends Component {
@property(Prefab) bullet1 : Prefab = null // 子弹
@property rate : number = 0.4 // 子弹发射频率
time1 : number = 0 // 过去的时间
@property(Node) zidan_weizhi : Node = null
protected onLoad(): void {
// 打开监听
input.on(
Input.EventType.TOUCH_MOVE, // 设置获取的类型
this.onmove, // 赋值给onmove函数
this
)
}
protected onDestroy(): void {
// 关闭监听
input.off(
Input.EventType.TOUCH_MOVE,
this.onmove,
this
)
}
onmove(event:EventTouch){
const p = this.node.position; // 获取坐标
let pos1 = new

最低0.47元/天 解锁文章
1039

被折叠的 条评论
为什么被折叠?



