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

你可能感兴趣的文章
notepad如何自动对齐_notepad++怎么自动排版
查看>>
Notification 使用详解(很全
查看>>
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
查看>>
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>
np.power的使用
查看>>
NPM 2FA双重认证的设置方法
查看>>
npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
查看>>
npm build报错Cannot find module ‘webpack‘解决方法
查看>>
npm ERR! ERESOLVE could not resolve报错
查看>>
npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
查看>>
npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
查看>>
npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
查看>>
npm install CERT_HAS_EXPIRED解决方法
查看>>
npm install digital envelope routines::unsupported解决方法
查看>>
npm install 卡着不动的解决方法
查看>>
npm install 报错 EEXIST File exists 的解决方法
查看>>
npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
查看>>
npm install 报错 fatal: unable to connect to github.com 的解决方法
查看>>