【cocos creator】 摇杆学习笔记!

这篇博客介绍了如何在cocos creator中实现摇杆功能,涉及到数学的三角函数知识。通过两个脚本,joystick.js和player.js,分别控制摇杆效果和角色移动。摇杆UI包括player、stick、stick_bg。是作者的学习笔记,重点探讨了摇杆的实现和三角函数的应用。
摘要由CSDN通过智能技术生成

cocos creator 摇杆

手机虚拟摇杆是指用于全触摸手机的虚拟于屏幕的按键虚拟摇杆,可直接操控触摸屏上的虚拟摇杆进行游戏。
在这里插入图片描述

这个摇杆的效果需要的了解的是数学的三角函数知识。这里有分成两个脚本,第一个脚本控制摇杆的一些效果。第二个脚本是控制主角的移动

1.这是joystick.js脚本

cc.Class({
  extends: cc.Component,

  properties: {
    stick: cc.Node,
    //stick_bg的宽度
    r: 200,

  },

  onLoad() {
    //触摸事件
    this.stick.on("touchstart", this.onTouchStart, this)
    this.stick.on("touchmove", this.onTouchMove, this)
    this.stick.on("touchend", this.onTouchEnd, this)
    this.stick.on("touchcancel", this.onTouchCancel, this)
    //dir表示stick的方向
    this.dir = cc.v2(0, 0)
  },
  onDestroy() {
    this.stick.off("touchstart", this.onTouchStart, this)
    this.stick.off("touchmove", this.onTouchMove, this)
    t
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值