博客
关于我
Egret学习笔记 (Egret打飞机-4.添加主角飞机和实现飞行效果)
阅读量:415 次
发布时间:2019-03-06

本文共 761 字,大约阅读时间需要 2 分钟。

实现飞机喷气效果

在Egret开发中,想要实现飞机喷气的效果,核心在于图片的切换频率。当我们在ADDED_TO_STAGE事件中加载两张图片后,需要通过帧率来控制图片切换的速度。 Egret的默认帧率是30帧/秒,这意味着在理想环境下,界面会每秒刷新30次。为了实现喷气效果,我们可以让图片以一定的频率切换。例如,每15帧切换一次,就能让图片看起来像是有气流从飞机尾部喷出。

帧率优化

为了实现上述效果,我们可以在HeroObject类中添加一个计数器,根据帧率来切换图片。具体实现如下: ```typescript _tag: number = 0; public frame(e: egret.Event) { if (this._tag >= 30) { this._tag = 0; } if (this._tag >= 15) { this._hero.texture = this._textures[0]; } else { this._hero.texture = this._textures[1]; } this._tag += 1; } ```这个代码中,我们通过每帧递增的_tag值来控制图片切换。每15帧切换一次图片,就能实现飞机喷气的效果。

整体实现步骤

1. 创建HeroObject类继承自DisplayObjectContainer,用于管理飞机的图片和切换逻辑 2. 在ADDED_TO_STAGE事件中加载两张图片到_textures数组,并设置飞机的初始图片和尺寸 3. 在frame事件中根据_tag值切换显示的图片,实现喷气效果 4. 将HeroObject实例添加到Main场景中,确保飞机出现在预期位置

通过这种方式,我们不仅实现了飞机的喷气效果,还确保了游戏运行的流畅性。

转载地址:http://ortkz.baihongyu.com/

你可能感兴趣的文章
npm发布包--所遇到的问题
查看>>
npm发布自己的组件UI包(详细步骤,图文并茂)
查看>>
npm和package.json那些不为常人所知的小秘密
查看>>
npm和yarn清理缓存命令
查看>>
npm和yarn的使用对比
查看>>
npm如何清空缓存并重新打包?
查看>>
npm学习(十一)之package-lock.json
查看>>
npm安装 出现 npm ERR! code ETIMEDOUT npm ERR! syscall connect npm ERR! errno ETIMEDOUT npm ERR! 解决方法
查看>>
npm安装crypto-js 如何安装crypto-js, python爬虫安装加解密插件 找不到模块crypto-js python报错解决丢失crypto-js模块
查看>>
npm安装教程
查看>>
npm报错Cannot find module ‘webpack‘ Require stack
查看>>
npm报错Failed at the node-sass@4.14.1 postinstall script
查看>>
npm报错fatal: Could not read from remote repository
查看>>
npm报错File to import not found or unreadable: @/assets/styles/global.scss.
查看>>
npm报错unable to access ‘https://github.com/sohee-lee7/Squire.git/‘
查看>>
npm淘宝镜像过期npm ERR! request to https://registry.npm.taobao.org/vuex failed, reason: certificate has ex
查看>>
npm版本过高问题
查看>>
npm的“--force“和“--legacy-peer-deps“参数
查看>>
npm的安装和更新---npm工作笔记002
查看>>
npm的常用配置项---npm工作笔记004
查看>>