<羊了个羊>目录1
羊了个羊关于运动动画
矩形移动
通过缓动动画移动
import { _decorator, Component, Node, tween, Vec3 } from 'cc';
const { ccclass, property } = _decorator;
@ccclass('ts_start')
export class ts_start extends Component {
start() {
}
update(deltaTime: number) {
const pos1 = this.node.getPosition()
if (pos1.x == 300 && pos1.y == 300){
this.node.scale = new Vec3(1 , 1) // 翻转一下
this.on_anim(new Vec3(300 , -300))
}
else if (pos1.x == 300 && pos1.y == -300){this.on_anim(new Vec3(-300 , -300))}
else if (pos1.x == -300 && pos1.y == -300){this.on_anim(new Vec3(-300 , 300))}
else if (pos1.x == -300 && pos1.y == 300){
this.node.scale = new Vec3(-1 , 1) // 翻转一下
this.on_anim(new Vec3(300 , 300))
}
else {return}
}
on_anim(pos:Vec3){
tween(this.node)
.to(2 , {position:pos})
.start()
}
}
但是好像cocos 在进行缓动时到达pos坐标有细微差异
导致判断失效,动画无法循环播放
但理论上是可以循环播放的
圆形移动
在<见缝插针_点击跳转>小游戏里,针脚本中
理论上建立一个节点,使其旋转
羊绑定在这个节点上,羊保持它的角度
const rw = this.node.getWorldRotation()
this.node.setWorldRotation(rw)
应该就能实现圆形移动,懒得验证了
小技巧_翻转
this.node.scale = new Vec3(-1 , 1) // 翻转一下

因为矩形移动有BUG,我就又改为圆形移动
start() {
this.on_aud_vol()
this.node.getWorldRotation(this.yang_rot) // 获取羊的世界坐标系下角度
//console.log(this.yang_rot)
}
on_move_yuan(){ // 羊圆形移动
this.fu_no.angle += 1
if (this.fu_no.angle == 360){this.fu_no.angle = 0}
this.node.setWorldRotation(this.yang_rot) // 保持角度
const p = this.node.getWorldPosition() // 获取羊的世界坐标
console.log(p.y)
if (p.y < 645) {this.node.scale = new Vec3(-1 , 1)}
else {this.node.scale = new Vec3(1 , 1)}
}
update(deltaTime: number) {
//this.on_move_fang()
this.on_move_yuan()
}
多点移动
老师方法

不要瞎魔改,我直接写一个死循环判定,cocos直接卡死
小技巧_绑定数组
老师代码,AI回答,都是用下面代码实现组件数组绑定
但我的 cocos 无法实现,我的版本是 3.8.5
@property([Node]) no : Node[] = [];
BUG
我的 cocos 出了点问题,调试运行的时候,
按钮按不到,滑动组件也按不到
改为浏览器调试运行,按键 和 滑动组件 都无异常
但背景音乐只有在滑动组件点击后才会出来
实验了N次后
并不是点击滑动组件才有声音
是点击 触屏 内任意地方都会出声音
我用的浏览器是夸克,所以不知道是不是浏览器的问题
用模拟器也OK
暂时就这样(应该是cocos 的问题)
1162

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



