额~~~
大神~我又来了~琢磨了一上午,还是没琢磨明白

您受累帮忙看看应该改哪里啊~~
cc.Class({
extends: cc.Component,
onCollisionEnter: function (other, self) {
//如果碰到的是障碍物
if (other.tag == 2 && self.tag == 1) {
cc.director.loadScene(‘Over’);//加载game over的场景
this.getComponent(cc.Animation).stop();//停止播放动画
}
},
properties: {
BG: {
default: null,
type: cc.Node
},
// Player跳跃高度
jumpHeight: 0,
// Player跳跃持续时间
jumpDuration: 0,
//Player状态
state: 'Run',
},
//Player跑
run: function () {
this.getComponent(cc.Animation).play('Cat_Run');//播放Player跑步动画
this.state = 'Run';//设置Player的状态为跑步
},
//Player跳跃
jump: function () {
if (this.state == 'Run') {//如果Player的状态是跑步的话
this.state = 'Jump';//设置Player的状态为跳跃
this.getComponent(cc.Animation).stop();//停止播放跑步的动画
this.getComponent(cc.Animation).play('Cat_Jump');//播放Player跳跃动画
// 开始执行动作 顺序执行 用跳跃的方式移动到指定的距离 固定的高度更改为可以蓄力跳跃,但未实现
this.node.runAction(cc.sequence(cc.jumpBy(this.jumpDuration, cc.p(0, 0), this.BG.getComponent('Game').onLoad().this.is_gather_strength = true, 1),//跳跃持续时间和跳跃的次数
cc.callFunc(function () {
this.run();//Player继续跑步
}, this)));
}
},
start() {
var catCollider = cc.director.getCollisionManager();//获取碰撞检测系统
catCollider.enabled = true;//开启碰撞检测系统
// catCollider.enabledDebugDraw = true;//显示碰撞组件的碰撞检测范围
}
});
你可以把那些蓄力的方法直接写到你现在的代码里,可以不用分开2个js文件的
可是那样的话会不会只有点在Player身上才能跳跃啊,点背景图片就无法跳跃了吧~
大神,按照您的意思,现在将两篇代码合为一体,如下:
cc.Class({
extends: cc.Component,
onCollisionEnter: function (other, self) {
//如果碰到的是障碍物
if (other.tag == 2 && self.tag == 1) {
cc.director.loadScene(‘Over’);//加载game over的场景
this.getComponent(cc.Animation).stop();//停止播放动画
}
},
properties: {
// Player跳跃高度
jumpheight: 0,
// Player跳跃持续时间
jumpDuration: 0,
//Player状态
state: 'Run',
is_gather_strength: false
},
//Player跑
run: function () {
this.getComponent(cc.Animation).play('Cat_Run');//播放Player跑步动画
this.state = 'Run';//设置Player的状态为跑步
},
//Player跳跃
jump: function () {
if (this.state == 'Run') {//如果Player的状态是跑步的话
this.state = 'Jump';//设置Player的状态为跳跃
this.getComponent(cc.Animation).stop();//停止播放跑步的动画
this.getComponent(cc.Animation).play('Cat_Jump');//播放Player跳跃动画
// 开始执行动作 顺序执行 用跳跃的方式移动到指定的距离
this.node.runAction(cc.sequence(cc.jumpBy(this.jumpDuration, cc.p(0, 0), this.is_gather_strength = true, 1),//跳跃持续时间和跳跃的次数
cc.callFunc(function () {
this.run();//Player继续跑步
}, this)));
}
},
start() {
var catCollider = cc.director.getCollisionManager();//获取碰撞检测系统
catCollider.enabled = true;//开启碰撞检测系统
// catCollider.enabledDebugDraw = true;//显示碰撞组件的碰撞检测范围
},
onLoad: function () {
this.node.on('touchstart', function (event) {//当触摸事件发生的时候
this.jumpheight = 50;//设置跳跃高度为0
this.is_gather_strength = true;//设置可以蓄力跳跃
this.jump();//让Cat跳跃
}, this);
this.node.on('touchend', function (event) {//当触摸事件结束的时候
this.is_gather_strength = false;//设置不可以蓄力跳跃
this.getComponent('Cat_Run').jump();//让Cat跳跃
console.log('121231231231231');//CSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
if (this.jumpheight > 300) {//如果高度大于1000
this.jumpheight = 300;//让跳跃高度等于1000
}
}, this);
},
update(dt) {
if (this.is_gather_strength) {//如果开启蓄力跳跃
this.jumpheight += dt * 50;//开始蓄力
}
}
});
但是改了之后猫跳不起来了不知道为什么…
预览窗口您看一下:http://localhost:7456/
你jumpBy里面怎么传this.is_gather_strength = true这个参数
您昨天不是说之前的参数:this.jumpHeght,是固定跳跃高度么~我就改了一下~不知道怎么改,就挨个测试了一下~发现不起作用~~~
![]()
(-。-) 真的是小白~做完这个项目我要申请调回Unity小组…
大神~应该怎么写啊~~我就差这一个蓄力跳跃了,其他的关卡什么的都搭建好了,请大神助我一臂之力


jump函数,放在touched里,上面的jumpBy里面的高度,改为this.jumpheight
大神~~是这样写么?跳不了了呢~检查了好几遍,逻辑上应该没有问题啊…
cc.Class({
extends: cc.Component,
onCollisionEnter: function (other, self) {
//如果碰到的是障碍物
if (other.tag == 2 && self.tag == 1) {
cc.director.loadScene(‘Over’);//加载game over的场景
this.getComponent(cc.Animation).stop();//停止播放动画
}
},
properties: {
// Player跳跃高度
jumpheight: 0,
// Player跳跃持续时间
jumpDuration: 0,
//Player状态
state: ‘Run’,
//初始蓄力跳跃为关闭状态
is_gather_strength: false
},
//Player跑
run: function () {
this.getComponent(cc.Animation).play(‘Cat_Run’);//播放Player跑步动画
this.state = ‘Run’;//设置Player的状态为跑步
},
start() {
var catCollider = cc.director.getCollisionManager();//获取碰撞检测系统
catCollider.enabled = true;//开启碰撞检测系统
},
onLoad: function () {
this.node.on('touchstart', function (event) {//当触摸事件发生的时候
this.jumpheight = 50;//设置跳跃高度为0
this.is_gather_strength = true;//设置可以蓄力跳跃
}, this);
this.node.on('touchend', function (event) {//当触摸事件结束的时候
this.is_gather_strength = false;//设置不可以蓄力跳跃
this.state = 'Jump';//设置Player的状态为跳跃
this.getComponent(cc.Animation).stop('Cat_Run');//停止播放跑步的动画
this.getComponent(cc.Animation).play('Cat_Jump');//播放Player跳跃动画
// 开始执行动作 顺序执行 用跳跃的方式移动到指定的距离
this.node.runAction(cc.sequence(cc.jumpBy(this.jumpDuration, cc.p(0, 0), this.jumpheight, 1),//跳跃持续时间和跳跃的次数
cc.callFunc(function () {
this.run();//Player继续跑步
}, this)));
}, this);
},
update(dt) {
if (this.is_gather_strength) {//如果开启蓄力跳跃
this.jumpheight += dt * 500;//开始蓄力
}
}
});
附工程预览:http://localhost:7456/
看到52楼@HelloWorld,感动中国十大人物,能这样子手把手教别人写代码…
其实你@暴躁的小章鱼最大的问题就是自己找问题,解决问题的能力,上述你问第问题其实都很简单,稍稍调试就出来了;还是说句不好听的,调回Unity小组,不解决你现在的问题,你觉得你能逃脱稍由于问题就在unity论坛一直请教别人的情况?
好吧,我是菜鸟,以上都是笑话…
多嘴一句:附工程预览:http://localhost:7456/,这是本地地址,别人是访问不了的
看来感动中国10大人物是跑不了了…
好的,那我自己解决吧
辛苦了大神!感谢您的耐心指导!
有问题就问吧,我也会帮你解决。不过提醒一句,写代码先看看文档,这样对你有很大的帮助
谢谢你哈,我再看看文档试一试~
真的感动中国!
很耐心的看完了帖子,好感动
,个人建议啊:楼主你可以花费1个小时左右时间把官方案例看一下(就那个摘星星就可以),单看文档知识点确实很枯燥,通过案例项目碰到不懂得再看文档也学的快,然后看完自己再敲一遍,再去上手搞你这个跑酷游戏会容易很多