当前位置: 首页 > news >正文

UE5 C++ 定时器 案例练习

一.这里参照 官方案例

Quick Start Guide to Variables Timers and Events in Unreal Engine CPP | 虚幻引擎 5.6 文档 | Epic Developer Community

二.

UPrimitiveComponent 是涉及渲染的组件,三角面的渲染几何等等。渲染线程它不能用U开头的东西,它会在这里把数据转换为F开头的结构体,把数据传递给渲染现场。

 * PrimitiveComponents are SceneComponents that contain or generate some sort of geometry, generally to be rendered or used as collision data.。

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "CountdownActor.generated.h"UCLASS()
class THIRDLEARN_API ACountdownActor : public AActor
{GENERATED_BODY()public:	// Sets default values for this actor's propertiesACountdownActor();class UTextRenderComponent* CountdownText;
protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;void UpdateTimeDisplay();void AdvanceTimer();void CountdownHasFinished();public:	// Called every framevirtual void Tick(float DeltaTime) override;
protected:int32 CountdonwTime = 3;FTimerHandle CountTimer;};

UpdateTimeDisplay()更新,在BeginPlay一开始的时候就更新一次,并设置好定时器。

定时器,AdvanceTimer 减少计时,更新显示的位置。并判断是否要消除计时器,再最后清楚的时候,更新文本。

// Fill out your copyright notice in the Description page of Project Settings.#include "CountdownActor.h"
#include "Components/TextRenderComponent.h"// Sets default values
ACountdownActor::ACountdownActor()
{// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = false;CountdownText = CreateDefaultSubobject<UTextRenderComponent>("CountdownTime");CountdownText->SetHorizontalAlignment(EHTA_Center);CountdownText->SetWorldSize(150);RootComponent = CountdownText;CountdonwTime = 3;
}// Called when the game starts or when spawned
void ACountdownActor::BeginPlay()
{Super::BeginPlay();UpdateTimeDisplay();GetWorldTimerManager().SetTimer(CountTimer, this, &ACountdownActor::AdvanceTimer, 1.0f, true);
}// Called every frame
void ACountdownActor::Tick(float DeltaTime)
{Super::Tick(DeltaTime);}void ACountdownActor::UpdateTimeDisplay()
{CountdownText->SetText(FText::FromString(FString::FromInt(FMath::Max(CountdonwTime, 0))));
}void ACountdownActor::AdvanceTimer()
{--CountdonwTime;UpdateTimeDisplay();if (CountdonwTime < 0){GetWorldTimerManager().ClearTimer(CountTimer);CountdownHasFinished();}
}void ACountdownActor::CountdownHasFinished()
{CountdownText->SetText(FText::FromString(TEXT("GO")));
}// Called every frame
void ACountdownActor::Tick(float DeltaTime)
{Super::Tick(DeltaTime);}void ACountdownActor::UpdateTimeDisplay()
{CountdownText->SetText(FText::FromString(FString::FromInt(FMath::Max(CountdonwTime,0))));
}void ACountdownActor::AdvanceTimer()
{ --CountdonwTime;
}void ACountdownActor::CountdownHasFinished()
{CountdownText->SetText(FText::FromString(TEXT("GO")));
}

http://www.dtcms.com/a/601071.html

相关文章:

  • 6 个成熟的 JS 开源视频编辑项目
  • 网站建设管理维护责任书格式怎样在网站做链接
  • Flutter---Stream
  • 佛山企业网站建设机构南明区住房和城乡建设局网站上
  • 仓颉三方库开发实战:Simple HTTP Server 实现详解
  • 做360网站官网还是百度济南有做五合一网站公司
  • 详细解读视频生成模型Wan2.1代码
  • Cortex-M3-STM32F1 开发:(二十二)HAL 库开发 ➤ STM32 中断逻辑优先级计算
  • THC63LVD1027D一款10位双链路LVDS信号中继器芯片,支持WUXGA分辨率视频数据传输THC63LVD1027支持30位数据通道方案
  • 考研规划手册
  • MongoDB中 client_connection和database和collection之间的关系
  • 建筑网站建设赏析外贸公司用什么建网站
  • [智能体设计模式] 第4章:反思(Reflection)
  • 系统架构设计师与考研408在IT基础设施能力考核上的全面对比研究
  • 饮用水品牌营销型网站手机网站主页
  • 亿网中国网站管理系统绍兴网站网站建设
  • 基于web宿舍管理系统的设计与实现
  • 利用idea创建springboot多模块项目
  • C++仿muduo库高并发服务器项目:Poller模块
  • QT C++ QWebEngine与Web JS之间通信
  • 华为防火墙web配置SSL-在外人员访问内网资源
  • 本地部署事务管理软件 JIRA 并实现外网访问(Windows 版本)
  • 18、Linux常用命令-磁盘分区相关命令
  • nvm与node.js的安装指南
  • python+django/flask+vue的书城图书阅读器系统,亮点含目录章节pycharm
  • 外贸cms什么意思seo海外推广
  • C++网络开发---CURL与CURLcode数据类型
  • 【Python数据分析】数据分析与可视化
  • MyBatis概述
  • Hadoop集群搭建(下):centos 7为例(已将将安装所需压缩包统一放在了/opt/software目录下)