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

你可能感兴趣的文章
nopcommerce商城系统--文档整理
查看>>
NOPI读取Excel
查看>>
NoSQL&MongoDB
查看>>
NoSQL介绍
查看>>
NoSQL数据库概述
查看>>
Notadd —— 基于 nest.js 的微服务开发框架
查看>>
NOTE:rfc5766-turn-server
查看>>
Notepad ++ 安装与配置教程(非常详细)从零基础入门到精通,看完这一篇就够了
查看>>
Notepad++在线和离线安装JSON格式化插件
查看>>
notepad++最详情汇总
查看>>
notepad++正则表达式替换字符串详解
查看>>
notepad如何自动对齐_notepad++怎么自动排版
查看>>
Notes on Paul Irish's "Things I learned from the jQuery source" casts
查看>>
Notification 使用详解(很全
查看>>
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
查看>>
NotImplementedError: Could not run torchvision::nms
查看>>
nova基于ubs机制扩展scheduler-filter
查看>>
Now trying to drop the old temporary tablespace, the session hangs.
查看>>
nowcoder—Beauty of Trees
查看>>
np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
查看>>