ARPG----C++学习记录01日志和调试

多人射击有点难,发现这个更加基础,先学习这个

显示日志

可以在代码中插入这样一行来打印日志,蓝图里的printstring会在屏幕和日志里都显示。可以使用%f,d等来获取后边的输入值。对于打映字符串变量,传入需要*

cpp 复制代码
UE_LOG(LogTemp,Warning,TEXT("time:%f"), DeltaTime);
if (GEngine)
{	
	FString Name = GetName();
	FString Message = FString::Printf(TEXT("name:%s"), *Name);
	//显示位置,时间,颜色,文本
	GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red,Message);
}

Draw a debug sphere

可以将画球的代码封装成宏,放到一个新的头文件里那么在别的代码里也能直接调用,同时引入头文件

Draw a debug Line

cpp 复制代码
if (World)
{	//获取向前的单位向量
	FVector Forward = GetActorForwardVector();
	//地图,起始点,终止点,颜色,时间
	DrawDebugLine(World,Location,Location+Forward*100.f,FColor::Red,false,60.f);
}

Draw a debug point

cpp 复制代码
if (World)
{
	DrawDebugPoint(World, Location + Forward * 100.f,15.f,FColor::Blue,true);
}

将它们都定义成宏来调用

cpp 复制代码
#define DRAW_SPHERE(Location) if(GetWorld()) DrawDebugSphere(GetWorld(), Location,25.f,24,FColor::Red,false,30.f);
#define DRAW_LINE(StartLocation,EndLocation) if(GetWorld()) DrawDebugLine(GetWorld(),StartLocation,EndLocation,FColor::Red,true,-1.f,0,1.f);
#define DRAW_POINT(Location) if(GetWorld()) DrawDebugPoint(GetWorld(),Location,15.f,FColor::Blue,true);
#define DRAW_VECTOR(StartLocation,EndLocation) if(GetWorld())\
	{\
		DrawDebugLine(GetWorld(),StartLocation,EndLocation,FColor::Red,true,-1.f,0,1.f);\
		DrawDebugPoint(GetWorld(), EndLocation, 15.f, FColor::Blue, true);}
cpp 复制代码
void Aitem::BeginPlay()
{
	Super::BeginPlay();

	UE_LOG(LogTemp,Warning,TEXT("BeginPLay"));
	if (GEngine)
	{
		//显示位置,时间,颜色,文本
		GEngine->AddOnScreenDebugMessage(-1,5,FColor::Red,TEXT("hello"));
	}

	//得到所在世界
	UWorld* World = GetWorld();
	//获取组件的位置
	FVector Location = GetActorLocation();
	//获取向前的单位向量
	FVector Forward = GetActorForwardVector();
	
	DRAW_SPHERE(Location);
	/*DRAW_LINE(Location,Location+Forward*100.f);
	DRAW_POINT(Location + Forward * 100.f);*/
	DRAW_VECTOR(Location, Location + Forward * 100.f);
}
相关推荐
Daydream.V31 分钟前
网页学习——HTML
学习
张永清-老清40 分钟前
每周读书与学习->JMeter性能测试脚本编写实战(四)-利用JMeter对MySQL数据库查询进行性能测试
学习·jmeter·性能调优·jmeter性能测试·性能分析·每周读书与学习
InterestOriented1 小时前
中老年线上学习发展:兴趣岛“内容+服务+空间”融合赋能下的体验升级
人工智能·学习
宇钶宇夕1 小时前
CoDeSys入门实战一起学习(二十八):(ST)三台电机顺起逆停程序详解
运维·学习·自动化·软件工程
£漫步 云端彡1 小时前
Golang学习历程【第十篇 方法(method)与接收者】
开发语言·学习·golang
im_AMBER1 小时前
Leetcode 111 两数相加
javascript·笔记·学习·算法·leetcode
四谎真好看2 小时前
JavaWeb学习笔记(Day12)
笔记·学习·学习笔记·javaweb
阿蒙Amon2 小时前
TypeScript学习-第11章:配置文件(tsconfig.json)
学习·typescript·json
babe小鑫2 小时前
中专学历转内容运营分析的学习路径
学习·产品运营·内容运营
●VON2 小时前
React Native for OpenHarmony:贪吃蛇游戏的开发与跨平台适配实践
学习·react native·react.js·游戏·openharmony