博客
关于我
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/

你可能感兴趣的文章
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>
NO.23 ZenTaoPHP目录结构
查看>>
NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
查看>>
NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
查看>>
Node JS: < 一> 初识Node JS
查看>>
Node-RED中使用JSON数据建立web网站
查看>>
Node-RED中使用json节点解析JSON数据
查看>>
Node-RED中使用node-random节点来实现随机数在折线图中显示
查看>>
Node-RED中使用node-red-browser-utils节点实现选择Windows操作系统中的文件并实现图片预览
查看>>
Node-RED中使用node-red-node-ui-iframe节点实现内嵌iframe访问其他网站的效果
查看>>
Node-RED中使用Notification元件显示警告讯息框(温度过高提示)
查看>>
Node-RED中实现HTML表单提交和获取提交的内容
查看>>
Node.js 8 中的 util.promisify的详解
查看>>