Cocos状态机与缓动系统
import { _decorator, Component, Node ,Animation,EventTouch} from 'cc';
const { ccclass, property } = _decorator;@ccclass('Player')
export class Player extends Component {//公布一个空节点到属性检查器来获得触摸层节点@property(Node)touchN:Node = null!;//定义一个变量用来记录动画组件private animation:Animation|null= null;//记录之前状态private state:string = 'none';onLoad(){//注册触摸事件this.touchN.on(Node.EventType.TOUCH_START,this.onTouchStart,this);//获取动画组件this.animation = this.node.getComponent(Animation);}//状态机changeState(state:string){//判断要切换的状态是否为之前的状态if(this.state === state){return;}//记录即将切换的状态this.state = state;//根据状态播放相应动画if(state === 'run'){if(this.animation){this.animation.play('Run');}}else if(state === 'jump'){if(this.animation){this.animation.play('Jump');}}else if(state === 'down'){if(this.animation){this.animation.play('Down');}}}onTouchStart(event:EventTouch){//切换跳跃状态this.changeState('jump');}
}
import { _decorator, Component, Prefab, instantiate } from 'cc';
const { ccclass, property } = _decorator;@ccclass('PipeLayer')
export class PipeLayer extends Component {//公布一个预制体类型到属性检查器来获取钢管预制体@property(Prefab)pipePrefab:Prefab = null!;private num: number = 0;onLoad(){}startCreatePipe() {//通过钢管预制体实例化出钢管节点let pipeN = instantiate(this.pipePrefab);//设置实例化出来的钢管节点的父节点为钢管层节点pipeN.parent = this.node;}}
import { _decorator, Component, CCInteger, Vec3, find, UITransform, tween} from 'cc';
const { ccclass, property } = _decorator;@ccclass('Pipe')
export class Pipe extends Component {//公布两个number型变量到属性检查器来随机钢管的高度@property(CCInteger)minHeight:number = 0;@property(CCInteger)maxHeight:number = 0;onLoad(){//获取Canvas节点的UITransform组件let uiTransform = <UITransform>find('Canvas')?.getComponent(UITransform);//获取游戏窗口大小let winSize = uiTransform.contentSize;//随机钢管的高度let height = Math.random()* (this.maxHeight - this.minHeight) + this.minHeight;//设置钢管的位置this.node.position = new Vec3(winSize.width + 100,height,0);//钢管移动this.move();}//缓动系统move(){//获取游戏窗口大小let uiTransform = <UITransform>find('Canvas')?.getComponent(UITransform);let winSize = uiTransform.contentSize;//缓动系统tween(this.node)//三秒钟时间钢管向左移动负的一个屏幕宽度加上200像素的距离.by(3,{position:new Vec3(-(winSize.width + 200),0,0)})//钢管移动结束后移除自己.removeSelf()//开始缓动.start();}}
export let gameInfo = {gameStart:false,
}export let playerInfo = {playerName:'none',
}
import { _decorator, Component, Node, Vec3, CCInteger, EventTouch, UITransform, Animation} from 'cc';
import {gameInfo} from './GameInfo'
const { ccclass, property } = _decorator;
import {PipeLayer} from './PipeLayer'
@ccclass('Game')
export class Game extends Component {//公布一个空节点到属性检查器用来获取玩家节点@property(Node)playerN: Node = null!;//公布一个空节点到属性检查器来获取钢管层节点@property(Node)pipeLayer:Node = null!;//公布一个number型变量到属性检查器用来定义加速度@property(CCInteger)accel: number = 0;//定义一个变量用来记录当前玩家掉落速度private speed:number = 0;start() {this.startGame();}startGame(){gameInfo.gameStart = true;//获取玩家动画组件let playerAnim = <Animation>this.playerN.getComponent(Animation);//玩家节点播放跳跃动画playerAnim.play('Jump');}update(deltaTime: number){//通过钢管层节点获得钢管层脚本let pipeLayerJs = this.pipeLayer.getComponent('PipeLayer') as PipeLayer;//开始生成钢管if(deltaTime/5 === 0)pipeLayerJs.startCreatePipe();}}
Cocos状态机与缓动系统相关推荐
- CocosCreator之缓动函数类 Easing
官方文档:使用缓动系统 · Cocos Creator 效果图地址:https://easings.net/ /** !#enThis class provide easing methods for ...
- cocos creator 3.x使用tween缓动接口和贝塞尔曲线实现简易抛物线
抛物线还是比较常用的,人物跳跃,投掷物等等,2dx和3.x接口很多都不兼容了,本文使用3.x中的缓动函数配合onUpdate钩子,计算并设置贝塞尔曲线中的坐标实现简易的抛物线运动. 代码: nodeM ...
- android自定义插值器_自定义缓动插值器,可在Android中实现有意义的动作
android自定义插值器 Interpolators are very useful to model movement for your UI elements. In this article, ...
- shader TileMap html的Canvas绘图 缓动/反弹动作 unity
图解Charles抓包工具使用教程 就是抓取返回的Data- -------------------------------------------------------shader 1 shade ...
- Dotween SetEase Ease缓动函数
例如 :cameraTrans.DOLocalMove(pos, time).SetEase(Ease.OutExpo); Ease.InQuad 不知道Quad代表什么意思 Ease.InQu ...
- JavaScript Tween算法及缓动效果
Flash做动画时会用到Tween类,利用它可以做很多动画效果,例如缓动.弹簧等等. 我这里要教大家的是怎么利用flash的Tween类的算法,来做js的Tween算法,并利用它做一些简单的缓动效果. ...
- 4.QML动画——概念、动画应用方式和动画的缓动曲线
一.动画 动画将应用于属性更改. 动画通过对属性值定义插值曲线,控制属性值从一个值到另一个值平滑过渡. Qt Quick中的所有动画均由同一计时器控制,因此动画是同步的. 这样可以提高动画的性能和视质 ...
- 用缓动函数模拟物理动画
1.缓动函数简介 <1>缓动函数的动画效果是建立在CALayer层级的关键帧动画基础之上 也就是说用普通的UIView的Animation是无法直接实现缓动函数 <2>缓动函数 ...
- WPF与缓动(一) N次缓动
WPF与缓动(一) N次缓动 ...
最新文章
- iOS开发小知识之正则表达式的简单用法
- ARTS打卡计划第二周-Share-使用java注解对方法计时
- Django 基于角色的权限控制
- 基于阿里的Node全栈之路(二)阿里负载均衡的HTTPS优化方案
- wxWidgets:wxLogChain类用法
- python0x80070005拒绝访问_PowerShell启用winrm失败:拒绝访问 0x80070005 -2147024891
- pta龟兔赛跑Java_PTA-龟兔赛跑
- express接受get数据
- PyTorch 1.0 中文文档:torch.cuda
- 计算机职业素养论文1500字,【如何提高职业素养1500字】_个人职业素养提升计划1500字范文...
- Xcode iphone模拟器运行不流畅
- SVN:冲突解决 Conflict discovered in
- r library car_医学统计与R语言:双因素重复测量方差分析(Twoway repeated measures ANOVA)...
- 小强统一认证中心-项目工程介绍
- 下拉列表—DropDownMenu的使用解析
- macos各版本汇总
- 关于QXDM的安装,解决Win7下QIK报错的问题
- Java_常瑞鹏 java_网络编程实现一个 聊天程序
- java课程设计斗地主_Java课程设计---web版斗地主
- BZOJ2844: albus就是要第一个出场(线性基)