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

你可能感兴趣的文章
nnU-Net 终极指南
查看>>
No 'Access-Control-Allow-Origin' header is present on the requested resource.
查看>>
NO 157 去掉禅道访问地址中的zentao
查看>>
no available service ‘default‘ found, please make sure registry config corre seata
查看>>
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
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 qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>