CocosCreator中使玩家移动到点击位置
来源:互联网 发布:java框架 编辑:程序博客网 时间:2024/06/06 11:03
onLoad: function () {
var that = this
that._playerSpeed = 300
that.bg.on(cc.Node.EventType.TOUCH_START,function(event){
//获取当前点击的全局坐标
var temp = event.getLocation()
cc.log("点击全局坐标: ",temp.x,temp.y)
//获取当前点击的局部坐标
var tempPlayer = that.player.parent.convertToNodeSpaceAR(temp)
cc.log("点击局部坐标: ",tempPlayer.x,tempPlayer.y)
//获取当前的玩家的局部坐标
var po1 = that.player.getPosition()
cc.log("玩家坐标: ",po1.x,po1.y)
//对玩家的行走进行左右交换
if(po1.x < tempPlayer.x){
that.player.getChildByName("anim").scaleX = -1
}else{
that.player.getChildByName("anim").scaleX = 1
}
//计算玩家移动的时间
var playTime = cc.pDistance(tempPlayer,po1) / that._playerSpeed
//让玩家移动到点击位置
var action = cc.moveTo(playTime,tempPlayer);
cc.log("移动时间: ",playTime)
//移动前停止所有动作
that.player.stopAllActions()
//进行移动
that.player.runAction(action);
//进行移动动画
that.anim.play('playerRun')
//移动完成过后。是玩家进入站立动画状态
that.player.runAction(cc.sequence(action, cc.callFunc(function(){
that.anim.play("playerStand")
})))
})
},
var that = this
that._playerSpeed = 300
that.bg.on(cc.Node.EventType.TOUCH_START,function(event){
//获取当前点击的全局坐标
var temp = event.getLocation()
cc.log("点击全局坐标: ",temp.x,temp.y)
//获取当前点击的局部坐标
var tempPlayer = that.player.parent.convertToNodeSpaceAR(temp)
cc.log("点击局部坐标: ",tempPlayer.x,tempPlayer.y)
//获取当前的玩家的局部坐标
var po1 = that.player.getPosition()
cc.log("玩家坐标: ",po1.x,po1.y)
//对玩家的行走进行左右交换
if(po1.x < tempPlayer.x){
that.player.getChildByName("anim").scaleX = -1
}else{
that.player.getChildByName("anim").scaleX = 1
}
//计算玩家移动的时间
var playTime = cc.pDistance(tempPlayer,po1) / that._playerSpeed
//让玩家移动到点击位置
var action = cc.moveTo(playTime,tempPlayer);
cc.log("移动时间: ",playTime)
//移动前停止所有动作
that.player.stopAllActions()
//进行移动
that.player.runAction(action);
//进行移动动画
that.anim.play('playerRun')
//移动完成过后。是玩家进入站立动画状态
that.player.runAction(cc.sequence(action, cc.callFunc(function(){
that.anim.play("playerStand")
})))
})
},
1 1
- CocosCreator中使玩家移动到点击位置的代码
- CocosCreator中使玩家移动到点击位置
- Unity中物体如何移动到鼠标点击位置
- Unity移动物体到鼠标点击位置
- 鼠标点击物体移动到该位置
- Unity3D之实现点击地形使物体移动到指定位置
- 把小人移动到鼠标点击的位置
- 2D游戏中怎样移动 敌人移动到玩家面前
- ASP中应用ONMOUSEOVER鼠标点击或者移动到表格格子上时光标位置显示窗体
- 每天一个JavaScript实例-铺货鼠标点击位置并将元素移动到该位置
- (Javascript经典案例) -- 捕获鼠标点击位置并将元素移动到该位置
- 我的Unity(1)一点一滴 鼠标点击任意位置,物体移动到该位置。
- Unity 3d 如何实现点击屏幕,npc自动移动到点击位置
- 补5-22博客 获取点击坐标并将控件移动到点击位置
- 点击图片随机移动位置
- Construct制作中玩家不能移动?
- SQL Server 中如何移动tempdb到新的位置
- 让图片直线移动到鼠标点击位置,类似游戏里的人物走动!
- mysql官方下载安装教程(centos)
- Android 操作SQLite基本用法
- 自定义RatingBar的一些问题
- 我是猪,不关机
- 【职坐标】java面向对象前言——static关键字
- CocosCreator中使玩家移动到点击位置
- javascript快速入门
- baidu地图sdk使用(3)自定义定位图标
- NYOJ 115 Dijstra入门
- android将图片转换为圆形图片
- 知识点:Java变量和数组的默认值
- Hibernate学习笔记----session核心方法
- 多平台消息推送是安卓耗电原因之一?
- 人物遮挡处理