Cocos Creator2D游戏开发(5)-飞机大战(3)-手指操作玩家飞机移动
创始人
2024-11-27 16:04:25
0次
  1. 添加玩家飞机
    1.创建player_node节点
    2.将资源中Player图片拖入player_node节点
    3.将Player的Position属性值调整为(0,-300) Content Size属性调整为(100 100)
    4.点击运行,飞机在屏幕上了
    在这里插入图片描述
    2 用手指拖着飞机跑流程
    ① 要监听手指按下
    ②判断手指是否在飞机上
    ③移动飞机
    ④监听手指离开
    在这里插入图片描述
    创建一个脚本Player.ts , 场景节点选player_node节点, 将Player.ts拖入右边属性检查器,保存;
    Player.ts脚本
import { _decorator, Component, EventTouch, Input, input, UITransform} from 'cc'; const { ccclass, property } = _decorator;  @ccclass('Player') export class Player extends Component {      private isPress; //是否按下     start() {         this.isPress = false;     }      onLoad() {         input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);  //注册按下事件         input.on(Input.EventType.TOUCH_MOVE, this.onTouchMove, this);  // 注册移动事件         input.on(Input.EventType.TOUCH_END, this.onToucheEnd, this); // 注册离开事件     }      onToucheEnd(event: EventTouch) {         this.isPress = false;     }       onTouchMove(event: EventTouch) {         if (!this.isPress) {             return;         }         const player = this.node.getChildByName("Player"); // 获取指定的组件         if (player === null) {             return;         }         const uiPos = event.getUILocation(); //获取世界坐标         player.setWorldPosition( uiPos.x,uiPos.y,0); // 设置指定坐标     }      onTouchStart(event: EventTouch) {         const player = this.node.getChildByName("Player");         if (player === null) {             return;         }          const transform = player.getComponent(UITransform);         const newRect = transform.getBoundingBoxToWorld(); //获取player组件框框         if(newRect.contains(event.getUILocation())){             this.isPress= true;         }      }      update(deltaTime: number) {      } }    

相关内容

热门资讯

微扑克辅助器!德州平台有没有挂... 您好:德州平台有没有挂这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
AApoker透视挂!wepo... 很多人使用云端 AI 时,都担心wepoker透视挂是真的吗、内部资料上传带来隐私风险。这款本地运行...
WePoKer透视!wepok... WePoKer透视!wepoker如何拿到好牌,分享透视多功能软件APP模板;近期一款 AI 黑科技...
红龙扑克透视挂!德扑之星规律,... 红龙扑克透视挂!德扑之星规律,解迷透视挂多功能插件APP法门是一款可以让一直输的玩家,快速成为一个“...
aapoker透视!WePoK... 您好,WePoKer有没有透视软件挂这款游戏可以开挂的,确实是有挂的,需要了解加微【48527505...
红龙扑克开挂!微扑克的辅助工具... 很多人使用云端 AI 时,都担心微扑克的辅助工具有哪些、内部资料上传带来隐私风险。这款本地运行的 A...
aapoker辅助!wepok... 您好:wepoker私人局怎么设置抽水这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会...
aapoker辅助挂!wepo... aapoker辅助挂!wepoker透视挂安全吗,普及辅助挂多功能方法APP策略AI 智能体黑科技再...
红龙PoKer辅助挂!wepo... 您好:wepokerplus透视挂真的假的这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌...
德扑之星辅助挂!德州ai辅助有... 德扑之星辅助挂!德州ai辅助有用吗,详细辅助挂多功能下载APP指南书是一款可以让一直输的玩家,快速成...