111
This commit is contained in:
parent
1032578ed1
commit
363b4b9b1e
|
|
@ -5,15 +5,15 @@
|
|||
"includePath": [
|
||||
"${workspaceFolder}/source/**",
|
||||
"${workspaceFolder}/source_game/**",
|
||||
"D:/devkitPro/devkitA64/aarch64-none-elf/include",
|
||||
"D:/devkitPro/libnx/include",
|
||||
"D:/devkitPro/portlibs/switch/include",
|
||||
"D:/devkitPro/portlibs/switch/include/SDL2"
|
||||
"L:/Switch/devkitPro/devkitA64/aarch64-none-elf/include",
|
||||
"L:/Switch/devkitPro/libnx/include",
|
||||
"L:/Switch/devkitPro/portlibs/switch/include",
|
||||
"L:/Switch/devkitPro/portlibs/switch/include/SDL2"
|
||||
],
|
||||
"defines": [
|
||||
"__SWITCH__"
|
||||
],
|
||||
"compilerPath": "D:/devkitPro/devkitA64/bin/aarch64-none-elf-gcc",
|
||||
"compilerPath": "L:/Switch/devkitPro/devkitA64/bin/aarch64-none-elf-gcc",
|
||||
"cStandard": "c17",
|
||||
"cppStandard": "c++17",
|
||||
"intelliSenseMode": "gcc-arm",
|
||||
|
|
|
|||
2
Makefile
2
Makefile
|
|
@ -67,7 +67,7 @@ ASFLAGS := -g $(ARCH)
|
|||
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
|
||||
|
||||
LIBS := `curl-config --libs` `$(PREFIX)pkg-config --libs sdl2 SDL2_mixer SDL2_image SDL2_ttf` \
|
||||
-lnx -lsquirrel_static -lsqstdlib_static -lstdc++ -lm
|
||||
-lnx -lsquirrel_static -lsqstdlib_static -lstdc++ -lm -lglad -lEGL -lglapi -ldrm_nouveau -lEGL -lGLESv2
|
||||
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ void Asset_Script::Init()
|
|||
InitBin();
|
||||
// 读取LoadString
|
||||
InitLoadString();
|
||||
|
||||
InitFlag = true;
|
||||
}
|
||||
|
||||
void Asset_Script::Clear()
|
||||
|
|
@ -20,7 +18,6 @@ void Asset_Script::Clear()
|
|||
LoadStringM.clear();
|
||||
_Data.clear();
|
||||
_Data.shrink_to_fit();
|
||||
InitFlag = false;
|
||||
}
|
||||
|
||||
void Asset_Script::InitHeader()
|
||||
|
|
|
|||
|
|
@ -55,6 +55,4 @@ public:
|
|||
|
||||
std::string GetFileContent(std::string path); // 获取文件内容
|
||||
std::vector<BYTE> GetFileContentByte(std::string path); // 获取文件内容
|
||||
|
||||
bool InitFlag = false;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include <switch.h>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <GLES3/gl3.h> // 假设使用 OpenGL ES 3.0,根据需求替换为 GLES2/gl2.h
|
||||
|
||||
// some switch buttons
|
||||
#define JOY_A 0
|
||||
|
|
|
|||
|
|
@ -49,11 +49,48 @@ void Actor::Clear()
|
|||
{
|
||||
}
|
||||
|
||||
void Actor::OnAdded(Scene *scene)
|
||||
{
|
||||
this->Parent = scene;
|
||||
}
|
||||
|
||||
void Actor::ReorderActors()
|
||||
{
|
||||
if (Parent)
|
||||
{
|
||||
RefPtr<Actor> me = this;
|
||||
Parent->m_Actors.Remove(me);
|
||||
RefPtr<Actor> sibling = Parent->m_Actors.GetLast();
|
||||
if (sibling && sibling->GetRenderZOrder() > RenderZOrder)
|
||||
{
|
||||
sibling = sibling->GetPrev();
|
||||
while (sibling)
|
||||
{
|
||||
if (sibling->GetRenderZOrder() <= RenderZOrder)
|
||||
break;
|
||||
sibling = sibling->GetPrev();
|
||||
}
|
||||
}
|
||||
if (sibling)
|
||||
{
|
||||
Parent->m_Actors.InsertAfter(me, sibling);
|
||||
}
|
||||
else
|
||||
{
|
||||
Parent->m_Actors.PushFront(me);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Actor::AddComponent(RefPtr<Component> Component)
|
||||
{
|
||||
m_Components.PushBack(Component);
|
||||
Component->OnAdded(this);
|
||||
// 排序组件
|
||||
Component->ReorderComponents();
|
||||
// 如果组件有transform标签,则设置其位置
|
||||
if (Component->hasTag(Tag::TRANSFORM))
|
||||
Component->SetIterationPos(Pos);
|
||||
}
|
||||
|
||||
void Actor::RemoveComponent(RefPtr<Component> Component)
|
||||
|
|
@ -62,12 +99,32 @@ void Actor::RemoveComponent(RefPtr<Component> Component)
|
|||
m_Components.Remove(Component);
|
||||
}
|
||||
|
||||
void Actor::SetPos(SDL_Point pos)
|
||||
void Actor::SetPos(VecPos pos)
|
||||
{
|
||||
this->Pos = pos;
|
||||
RefPtr<Component> child = m_Components.GetFirst();
|
||||
while (child)
|
||||
{
|
||||
if (child->hasTag(Tag::TRANSFORM))
|
||||
child->SetIterationPos(pos);
|
||||
child = child->GetNext();
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Point Actor::GetPos()
|
||||
VecPos Actor::GetPos()
|
||||
{
|
||||
return this->Pos;
|
||||
}
|
||||
|
||||
int Actor::GetRenderZOrder()
|
||||
{
|
||||
return this->RenderZOrder;
|
||||
}
|
||||
|
||||
void Actor::SetRenderZOrder(int zOrder)
|
||||
{
|
||||
if(this->RenderZOrder != zOrder){
|
||||
this->RenderZOrder = zOrder;
|
||||
ReorderActors();
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,8 @@ public:
|
|||
void Update(float deltaTime) override;
|
||||
void Render(float deltaTime) override;
|
||||
void Clear() override;
|
||||
virtual void OnAdded(Scene *scene);
|
||||
void ReorderActors(); // 重新排序Actor
|
||||
|
||||
using IntrusiveListValue<RefPtr<Actor>>::GetNext;
|
||||
using IntrusiveListValue<RefPtr<Actor>>::GetPrev;
|
||||
|
|
@ -28,14 +30,17 @@ public:
|
|||
public:
|
||||
void AddComponent(RefPtr<Component> Component);
|
||||
void RemoveComponent(RefPtr<Component> Component);
|
||||
void SetPos(SDL_Point pos);
|
||||
SDL_Point GetPos();
|
||||
void SetPos(VecPos pos);
|
||||
VecPos GetPos();
|
||||
|
||||
public:
|
||||
Scene *Parent; // 指向父场景的指针,表示该Actor所属的场景
|
||||
SDL_Point Pos = {0, 0}; // 位置坐标
|
||||
VecPos Pos = {0, 0}; // 位置坐标
|
||||
|
||||
IntrusiveList<RefPtr<Component>> m_Components; // 组件列表
|
||||
|
||||
int RenderZOrder = 0; // 渲染层级
|
||||
int GetRenderZOrder();
|
||||
void SetRenderZOrder(int zOrder);
|
||||
private:
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,12 +28,10 @@ void Actor_base::SetCallbackOnUpdate(const UpdateCallback &cb)
|
|||
cb_update_ = cb;
|
||||
}
|
||||
|
||||
int Actor_base::GetRenderZOrder()
|
||||
{
|
||||
return this->RenderZOrder;
|
||||
void Actor_base::SetName(std::string name){
|
||||
m_Name = name;
|
||||
}
|
||||
|
||||
void Actor_base::SetRenderZOrder(int zOrder)
|
||||
{
|
||||
this->RenderZOrder = zOrder;
|
||||
std::string Actor_base::GetName(){
|
||||
return m_Name;
|
||||
}
|
||||
|
|
@ -24,13 +24,14 @@ public:
|
|||
/// \~chinese
|
||||
/// @brief 设置更新时的回调函数
|
||||
void SetCallbackOnUpdate(const UpdateCallback &cb);
|
||||
|
||||
|
||||
void SetName(std::string name);
|
||||
std::string GetName();
|
||||
private:
|
||||
/* data */
|
||||
UpdateCallback cb_update_; // 更新时的回调函数
|
||||
int RenderZOrder = 0; // 渲染层级
|
||||
|
||||
std::string m_Name;
|
||||
public:
|
||||
int GetRenderZOrder();
|
||||
void SetRenderZOrder(int zOrder);
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ void Animation::Init(std::string AniPath)
|
|||
// 标记该组件需要渲染和更新
|
||||
addTag(Tag::RENDER);
|
||||
addTag(Tag::UPDATE);
|
||||
addTag(Tag::TRANSFORM);
|
||||
|
||||
AniScriptParser::AniInfo Info = AssetManager::GetInstance().StructAniInfo(AniPath);
|
||||
this->AniPath = AniPath;
|
||||
|
|
@ -36,15 +37,18 @@ void Animation::Init(std::string AniPath)
|
|||
for (size_t i = 0; i < this->FrameArr.size(); i++)
|
||||
{
|
||||
AniScriptParser::AniFrame FrameObj = this->FrameArr[i];
|
||||
RefPtr<Sprite> SpriteObj = new Sprite();
|
||||
RefPtr<Sprite> SpriteObj = nullptr;
|
||||
if (!FrameObj.Img_Path.empty())
|
||||
{
|
||||
if (AdditionalOptions)
|
||||
{
|
||||
FrameObj.Img_Path = AdditionalOptions(FrameObj.Img_Path);
|
||||
}
|
||||
SpriteObj->Init(FrameObj.Img_Path, FrameObj.Img_Index);
|
||||
SpriteObj = new Sprite(FrameObj.Img_Path, FrameObj.Img_Index);
|
||||
SpriteObj->SetPos(FrameObj.Img_Pos);
|
||||
}
|
||||
else
|
||||
SpriteObj = new Sprite();
|
||||
SpriteArr.push_back(SpriteObj);
|
||||
}
|
||||
|
||||
|
|
@ -107,14 +111,7 @@ void Animation::Render(float deltaTime)
|
|||
{
|
||||
if (CurrentFrame)
|
||||
{
|
||||
SDL_Point PosData = Pos;
|
||||
SDL_Point ParentPos = Parent->GetPos();
|
||||
if (Parent)
|
||||
{
|
||||
PosData.x += ParentPos.x;
|
||||
PosData.y += ParentPos.y;
|
||||
}
|
||||
CurrentFrame->RenderByAni(deltaTime, PosData);
|
||||
CurrentFrame->Render(deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -129,18 +126,25 @@ void Animation::Clear()
|
|||
{
|
||||
}
|
||||
|
||||
void Animation::SetIterationPos(VecPos pos)
|
||||
{
|
||||
Component::SetIterationPos(pos);
|
||||
if (CurrentFrame)
|
||||
CurrentFrame->SetIterationPos(this->Pos + this->IterationPos);
|
||||
}
|
||||
|
||||
void Animation::FlushFrame(int Index)
|
||||
{
|
||||
// 同步当前帧
|
||||
CurrentFrameIndex = Index;
|
||||
// 当前帧更换为本帧
|
||||
CurrentFrame = SpriteArr[CurrentFrameIndex];
|
||||
// 设置精灵帧的迭代坐标为自己的坐标和自己的迭代坐标
|
||||
CurrentFrame->SetIterationPos(this->Pos + this->IterationPos);
|
||||
// 如果是整体染色 则直接使用染色帧
|
||||
// if (DyeAllFlag) CurrentFrame = DyeFrameList[CurrentFrameIndex];
|
||||
|
||||
AniScriptParser::AniFrame FrameInfo = FrameArr[CurrentFrameIndex];
|
||||
// 设置坐标
|
||||
SetPos(FrameInfo.Img_Pos);
|
||||
// 设置下帧延迟
|
||||
NextFrameDelay = FrameInfo.Delay;
|
||||
|
||||
|
|
@ -159,9 +163,9 @@ void Animation::FlushFrame(int Index)
|
|||
// 缩放
|
||||
if (FlagBuf.count("IMAGE_RATE"))
|
||||
{
|
||||
SDL_FPoint Rate = std::get<SDL_FPoint>(FlagBuf["IMAGE_RATE"]);
|
||||
SDL_Point Size = CurrentFrame->GetSize();
|
||||
CurrentFrame->SetSize(SDL_Point{int(Size.x * Rate.x), (int)(Size.y * Rate.y)});
|
||||
VecFPos Rate = std::get<VecFPos>(FlagBuf["IMAGE_RATE"]);
|
||||
VecSize Size = CurrentFrame->GetSize();
|
||||
CurrentFrame->SetSize(VecSize{int(Size.width * Rate.x), (int)(Size.width * Rate.y)});
|
||||
}
|
||||
// 线性减淡
|
||||
if (FlagBuf.count("GRAPHIC_EFFECT_LINEARDODGE"))
|
||||
|
|
@ -171,7 +175,7 @@ void Animation::FlushFrame(int Index)
|
|||
// 旋转
|
||||
if (FlagBuf.count("IMAGE_ROTATE"))
|
||||
{
|
||||
CurrentFrame->SetAnchor(SDL_FPoint{0.5, 0.5});
|
||||
CurrentFrame->SetAnchor(VecFPos{0.5, 0.5});
|
||||
CurrentFrame->SetAngle(std::get<float>(FlagBuf["IMAGE_ROTATE"]));
|
||||
}
|
||||
// 染色
|
||||
|
|
@ -247,28 +251,29 @@ void Animation::InterpolationLogic()
|
|||
}
|
||||
// 坐标
|
||||
{
|
||||
SDL_Point PosData = {
|
||||
VecPos PosData = {
|
||||
(int)(OldData.Img_Pos.x + (NewData.Img_Pos.x - OldData.Img_Pos.x) * InterRate),
|
||||
(int)(OldData.Img_Pos.y + (NewData.Img_Pos.y - OldData.Img_Pos.y) * InterRate)};
|
||||
SetPos(PosData);
|
||||
CurrentFrame->SetIterationPos(this->Pos + this->IterationPos);
|
||||
}
|
||||
// 缩放
|
||||
{
|
||||
SDL_FPoint OldRateData = {1.0, 1.0};
|
||||
SDL_FPoint NewRateData = {1.0, 1.0};
|
||||
VecFPos OldRateData = {1.0, 1.0};
|
||||
VecFPos NewRateData = {1.0, 1.0};
|
||||
if (OldData.Flag.count("IMAGE_RATE"))
|
||||
{
|
||||
OldRateData = std::get<SDL_FPoint>(OldData.Flag["IMAGE_RATE"]);
|
||||
OldRateData = std::get<VecFPos>(OldData.Flag["IMAGE_RATE"]);
|
||||
}
|
||||
if (NewData.Flag.count("IMAGE_RATE"))
|
||||
{
|
||||
NewRateData = std::get<SDL_FPoint>(NewData.Flag["IMAGE_RATE"]);
|
||||
NewRateData = std::get<VecFPos>(NewData.Flag["IMAGE_RATE"]);
|
||||
}
|
||||
SDL_Point ScaleData = {
|
||||
(int)(CurrentFrame->GetSize().x * (OldRateData.x + (NewRateData.x - OldRateData.x) * InterRate)),
|
||||
(int)(CurrentFrame->GetSize().y * (OldRateData.y + (NewRateData.y - OldRateData.y) * InterRate))};
|
||||
SDL_Point Size = CurrentFrame->GetSize();
|
||||
CurrentFrame->SetSize(SDL_Point{int(Size.x * ScaleData.x), (int)(Size.y * ScaleData.y)});
|
||||
VecSize ScaleData = {
|
||||
(int)(CurrentFrame->GetSize().width * (OldRateData.x + (NewRateData.x - OldRateData.x) * InterRate)),
|
||||
(int)(CurrentFrame->GetSize().height * (OldRateData.y + (NewRateData.y - OldRateData.y) * InterRate))};
|
||||
VecSize Size = CurrentFrame->GetSize();
|
||||
CurrentFrame->SetSize(VecSize{int(Size.width * ScaleData.width), (int)(Size.height * ScaleData.height)});
|
||||
}
|
||||
// 旋转
|
||||
{
|
||||
|
|
@ -286,22 +291,24 @@ void Animation::InterpolationLogic()
|
|||
}
|
||||
}
|
||||
|
||||
void Animation::SetSize(SDL_Point size)
|
||||
void Animation::SetSize(VecSize size)
|
||||
{
|
||||
this->Size = size;
|
||||
}
|
||||
|
||||
void Animation::SetPos(SDL_Point pos)
|
||||
void Animation::SetPos(VecPos pos)
|
||||
{
|
||||
this->Pos = pos;
|
||||
if (CurrentFrame)
|
||||
CurrentFrame->SetIterationPos(this->Pos + this->IterationPos);
|
||||
}
|
||||
|
||||
SDL_Point Animation::GetPos()
|
||||
VecPos Animation::GetPos()
|
||||
{
|
||||
return this->Pos;
|
||||
}
|
||||
|
||||
SDL_Point Animation::GetSize()
|
||||
VecSize Animation::GetSize()
|
||||
{
|
||||
return this->Size;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ public:
|
|||
void Render(float deltaTime) override;
|
||||
void OnAdded(Actor *actor) override;
|
||||
void Clear() override;
|
||||
void SetIterationPos(VecPos pos) override;
|
||||
|
||||
public:
|
||||
void FlushFrame(int Index);
|
||||
|
|
@ -86,13 +87,12 @@ public:
|
|||
// 附加选项
|
||||
std::function<std::string(std::string)> AdditionalOptions;
|
||||
|
||||
SDL_Point Pos = {0, 0}; // 位置坐标
|
||||
SDL_Point Size = {0, 0}; // 大小
|
||||
int RenderZOrder = 0; // 渲染层级
|
||||
VecPos Pos = {0, 0}; // 位置坐标
|
||||
VecSize Size = {0, 0}; // 大小
|
||||
|
||||
public:
|
||||
void SetSize(SDL_Point size);
|
||||
void SetPos(SDL_Point pos);
|
||||
SDL_Point GetSize();
|
||||
SDL_Point GetPos();
|
||||
void SetSize(VecSize size);
|
||||
void SetPos(VecPos pos);
|
||||
VecSize GetSize();
|
||||
VecPos GetPos();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -71,6 +71,36 @@ void Component::ReorderComponents()
|
|||
}
|
||||
}
|
||||
|
||||
void Component::SetIterationPos(VecPos pos)
|
||||
{
|
||||
this->IterationPos = pos;
|
||||
}
|
||||
|
||||
VecPos Component::GetIterationPos()
|
||||
{
|
||||
return this->IterationPos;
|
||||
}
|
||||
|
||||
void Component::SetIterationScale(VecSize scale)
|
||||
{
|
||||
this->IterationScale = scale;
|
||||
}
|
||||
|
||||
VecSize Component::GetIterationScale()
|
||||
{
|
||||
return this->IterationScale;
|
||||
}
|
||||
|
||||
void Component::SetIterationAngle(float angle)
|
||||
{
|
||||
this->IterationAngle = angle;
|
||||
}
|
||||
|
||||
float Component::GetIterationAngle()
|
||||
{
|
||||
return this->IterationAngle;
|
||||
}
|
||||
|
||||
void Component::SetRenderZOrder(int zOrder)
|
||||
{
|
||||
if (zOrder != this->RenderZOrder)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,23 @@ public:
|
|||
// 重新排列组件
|
||||
void ReorderComponents();
|
||||
|
||||
// 设置迭代的坐标
|
||||
virtual void SetIterationPos(VecPos pos);
|
||||
// 获取迭代的坐标
|
||||
VecPos GetIterationPos();
|
||||
// 设置迭代的缩放
|
||||
virtual void SetIterationScale(VecSize scale);
|
||||
// 获取迭代的缩放
|
||||
VecSize GetIterationScale();
|
||||
// 设置迭代的旋转角度
|
||||
virtual void SetIterationAngle(float angle);
|
||||
// 获取迭代的旋转角度
|
||||
float GetIterationAngle();
|
||||
|
||||
public:
|
||||
Actor *Parent = nullptr; // 指向父对象的指针,用于访问父对象
|
||||
int RenderZOrder; // 渲染层级
|
||||
int RenderZOrder = 0; // 渲染层级
|
||||
VecPos IterationPos = {0, 0}; // 迭代的坐标
|
||||
VecSize IterationScale = {0, 0}; // 迭代的缩放
|
||||
float IterationAngle = 0.0f; // 迭代的旋转角度
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,27 +1,34 @@
|
|||
#include "Sprite.h"
|
||||
#include "EngineCore/Game.h"
|
||||
#include "Text.h"
|
||||
#include "Render/Texture.h"
|
||||
Sprite::Sprite()
|
||||
{
|
||||
}
|
||||
|
||||
Sprite::Sprite(std::string imgPath, int Index)
|
||||
{
|
||||
Init(imgPath, Index);
|
||||
m_texture = new Texture(imgPath, Index);
|
||||
Init();
|
||||
}
|
||||
|
||||
Sprite::Sprite(std::string PngPath)
|
||||
{
|
||||
m_texture = new Texture(PngPath);
|
||||
Init();
|
||||
}
|
||||
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
}
|
||||
|
||||
void Sprite::Init(std::string imgPath, int Index)
|
||||
void Sprite::Init()
|
||||
{
|
||||
// 标记该组件需要渲染和更新
|
||||
addTag(Tag::RENDER);
|
||||
addTag(Tag::UPDATE);
|
||||
addTag(Tag::TRANSFORM);
|
||||
|
||||
m_texture = new Texture(imgPath, Index);
|
||||
Size = m_texture->TextureSize;
|
||||
}
|
||||
|
||||
RefPtr<Texture> Sprite::GetTexture()
|
||||
|
|
@ -50,39 +57,32 @@ void Sprite::Render(float deltaTime)
|
|||
SDL_Renderer *renderer = Game::GetInstance().GetRenderer();
|
||||
if (!m_texture)
|
||||
return;
|
||||
SDL_Rect dstrect = {Pos.x, Pos.y, Size.x, Size.y};
|
||||
|
||||
int XPos = IterationPos.x + Pos.x + m_texture->TexturePos.x;
|
||||
int YPos = IterationPos.y + Pos.y + m_texture->TexturePos.y;
|
||||
int XSize = Size.width;
|
||||
int YSize = Size.height;
|
||||
SDL_Rect dstrect = {XPos, YPos, XSize, YSize};
|
||||
|
||||
if (isRenderScreen)
|
||||
{
|
||||
if (Angle != 0 || flip != SDL_FLIP_NONE)
|
||||
{
|
||||
SDL_RenderCopyEx(renderer, m_texture->GetTexture(), NULL, &dstrect, Angle, &Anchor, flip);
|
||||
SDL_Point AnchorBuf = Anchor;
|
||||
SDL_RenderCopyEx(renderer, m_texture->GetTexture(), NULL, &dstrect, Angle, &AnchorBuf, flip);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_RenderCopy(renderer, m_texture->GetTexture(), NULL, &dstrect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Sprite::RenderByAni(float deltaTime, SDL_Point pos)
|
||||
{
|
||||
SDL_Renderer *renderer = Game::GetInstance().GetRenderer();
|
||||
if (!m_texture)
|
||||
return;
|
||||
SDL_Rect dstrect = {Pos.x + pos.x, Pos.y + pos.y, Size.x, Size.y};
|
||||
|
||||
if (Angle != 0 || flip != SDL_FLIP_NONE)
|
||||
{
|
||||
SDL_RenderCopyEx(renderer, m_texture->GetTexture(), NULL, &dstrect, Angle, &Anchor, flip);
|
||||
}
|
||||
else
|
||||
SDL_RenderCopy(renderer, m_texture->GetTexture(), NULL, &dstrect);
|
||||
}
|
||||
|
||||
void Sprite::Clear()
|
||||
{
|
||||
}
|
||||
|
||||
void Sprite::SetPos(SDL_Point pos)
|
||||
void Sprite::SetPos(VecPos pos)
|
||||
{
|
||||
Pos = pos;
|
||||
}
|
||||
|
|
@ -97,23 +97,23 @@ void Sprite::SetAngle(float angle)
|
|||
Angle = angle;
|
||||
}
|
||||
|
||||
void Sprite::SetAnchor(SDL_FPoint anchor)
|
||||
void Sprite::SetAnchor(VecFPos anchor)
|
||||
{
|
||||
Anchor.x = Size.x * anchor.x;
|
||||
Anchor.y = Size.y * anchor.y;
|
||||
Anchor.x = Size.width * anchor.x;
|
||||
Anchor.y = Size.height * anchor.y;
|
||||
}
|
||||
|
||||
void Sprite::SetSize(SDL_Point size)
|
||||
void Sprite::SetSize(VecSize size)
|
||||
{
|
||||
Size = size;
|
||||
}
|
||||
|
||||
SDL_Point Sprite::GetSize()
|
||||
VecSize Sprite::GetSize()
|
||||
{
|
||||
return Size;
|
||||
}
|
||||
|
||||
SDL_Point Sprite::GetPos()
|
||||
VecPos Sprite::GetPos()
|
||||
{
|
||||
return Pos;
|
||||
}
|
||||
|
|
@ -128,10 +128,10 @@ float Sprite::GetAngle()
|
|||
return Angle;
|
||||
}
|
||||
|
||||
SDL_FPoint Sprite::GetAnchor()
|
||||
VecFPos Sprite::GetAnchor()
|
||||
{
|
||||
SDL_FPoint P;
|
||||
P.x = Anchor.x / Size.x;
|
||||
P.y = Anchor.y / Size.y;
|
||||
VecFPos P;
|
||||
P.x = Anchor.x / Size.width;
|
||||
P.y = Anchor.y / Size.height;
|
||||
return P;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#include <string>
|
||||
#include "EngineCore/Asset_ImagePack.h"
|
||||
#include "EngineFrame/Component/Component.h"
|
||||
#include "EngineFrame/Render/Texture.h"
|
||||
|
||||
class Game;
|
||||
/**
|
||||
|
|
@ -24,6 +25,11 @@ public:
|
|||
* @param Index 索引值
|
||||
*/
|
||||
Sprite(std::string imgPath, int Index);
|
||||
/**
|
||||
* @brief Sprite类的带参数构造函数
|
||||
* @param imgPath 纹理图片文件路径
|
||||
*/
|
||||
Sprite(std::string PngPath);
|
||||
/**
|
||||
* @brief Sprite类的析构函数
|
||||
*/
|
||||
|
|
@ -33,10 +39,8 @@ public:
|
|||
using Component::Init;
|
||||
/**
|
||||
* @brief 初始化Sprite组件
|
||||
* @param imgPath 纹理图片路径
|
||||
* @param Index 索引值
|
||||
*/
|
||||
void Init(std::string imgPath, int Index);
|
||||
void Init();
|
||||
/**
|
||||
* @brief 处理事件
|
||||
* @param e SDL事件指针
|
||||
|
|
@ -52,11 +56,6 @@ public:
|
|||
* @param deltaTime 时间增量
|
||||
*/
|
||||
void Render(float deltaTime) override;
|
||||
/**
|
||||
* @brief 渲染组件
|
||||
* @param deltaTime 时间增量
|
||||
*/
|
||||
void RenderByAni(float deltaTime, SDL_Point pos);
|
||||
/**
|
||||
* @brief 清理组件资源
|
||||
*/
|
||||
|
|
@ -69,10 +68,10 @@ public:
|
|||
RefPtr<Texture> GetTexture();
|
||||
|
||||
public:
|
||||
SDL_Point Pos = {0, 0}; // 位置坐标
|
||||
SDL_Point TextureSize = {0, 0}; // 纹理大小
|
||||
SDL_Point Size = {0, 0}; // 大小
|
||||
SDL_Point Anchor = {0, 0}; // 中心点
|
||||
VecPos Pos = {0, 0}; // 位置坐标
|
||||
VecSize TextureSize = {0, 0}; // 纹理大小
|
||||
VecSize Size = {0, 0}; // 大小
|
||||
VecPos Anchor = {0, 0}; // 中心点
|
||||
float Angle = 0.0f; // 旋转角度
|
||||
SDL_RendererFlip flip = SDL_FLIP_NONE; // 翻转
|
||||
|
||||
|
|
@ -81,24 +80,24 @@ public:
|
|||
|
||||
public:
|
||||
// 设置坐标
|
||||
void SetPos(SDL_Point pos);
|
||||
void SetPos(VecPos pos);
|
||||
// 设置混合模式
|
||||
void SetBlendMode(SDL_BlendMode blendMode);
|
||||
// 设置旋转角度
|
||||
void SetAngle(float angle);
|
||||
// 设置中心点
|
||||
void SetAnchor(SDL_FPoint anchor);
|
||||
void SetAnchor(VecFPos anchor);
|
||||
// 设置大小
|
||||
void SetSize(SDL_Point size);
|
||||
void SetSize(VecSize size);
|
||||
|
||||
// 获取坐标
|
||||
SDL_Point GetPos();
|
||||
VecPos GetPos();
|
||||
// 获取混合模式
|
||||
SDL_BlendMode GetBlendMode();
|
||||
// 获取旋转角度
|
||||
float GetAngle();
|
||||
// 获取中心点
|
||||
SDL_FPoint GetAnchor();
|
||||
VecFPos GetAnchor();
|
||||
// 获取大小
|
||||
SDL_Point GetSize();
|
||||
VecSize GetSize();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,282 @@
|
|||
// GLESRenderer.cpp
|
||||
#include "EngineFrame/Render/GLESRenderer.h"
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <glm/ext/matrix_float4x4.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
// 顶点着色器源码
|
||||
const char *vertexShaderSource = R"(
|
||||
#version 300 es
|
||||
precision mediump float;
|
||||
|
||||
layout(location = 0) in vec2 aPosition;
|
||||
layout(location = 1) in vec2 aTexCoord;
|
||||
|
||||
out vec2 vTexCoord;
|
||||
|
||||
uniform mat4 uProjection;
|
||||
uniform mat4 uModel;
|
||||
|
||||
void main() {
|
||||
gl_Position = uProjection * uModel * vec4(aPosition, 0.0, 1.0);
|
||||
vTexCoord = aTexCoord;
|
||||
}
|
||||
)";
|
||||
|
||||
// 片段着色器源码
|
||||
const char *fragmentShaderSource = R"(
|
||||
#version 300 es
|
||||
precision mediump float;
|
||||
|
||||
in vec2 vTexCoord;
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform sampler2D uTexture;
|
||||
uniform vec4 uColor;
|
||||
|
||||
void main() {
|
||||
FragColor = texture(uTexture, vTexCoord) * uColor;
|
||||
}
|
||||
)";
|
||||
|
||||
GLESRenderer::GLESRenderer(SDL_Window *window) : m_window(window), m_glContext(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
GLESRenderer::~GLESRenderer()
|
||||
{
|
||||
if (m_glContext)
|
||||
{
|
||||
SDL_GL_DeleteContext(m_glContext);
|
||||
}
|
||||
|
||||
glDeleteProgram(m_shaderProgram);
|
||||
glDeleteShader(m_vertexShader);
|
||||
glDeleteShader(m_fragmentShader);
|
||||
glDeleteBuffers(1, &m_vbo);
|
||||
glDeleteVertexArrays(1, &m_vao);
|
||||
}
|
||||
|
||||
bool GLESRenderer::Initialize()
|
||||
{
|
||||
// 设置 OpenGL ES 属性
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||
|
||||
// 创建 OpenGL ES 上下文
|
||||
m_glContext = SDL_GL_CreateContext(m_window);
|
||||
if (!m_glContext)
|
||||
{
|
||||
std::cerr << "Failed to create OpenGL ES context: " << SDL_GetError() << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 初始化 GLEW (如果需要) 或者直接使用 OpenGL ES 函数
|
||||
|
||||
// 创建着色器程序
|
||||
if (!CreateShaderProgram())
|
||||
{
|
||||
std::cerr << "Failed to create shader program" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// 设置视口
|
||||
int w, h;
|
||||
SDL_GetWindowSize(m_window, &w, &h);
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
// 设置正交投影
|
||||
SetOrthographicProjection(w, h);
|
||||
|
||||
// 启用混合
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
// 创建VAO和VBO
|
||||
glGenVertexArrays(1, &m_vao);
|
||||
glGenBuffers(1, &m_vbo);
|
||||
|
||||
glBindVertexArray(m_vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
|
||||
|
||||
// 设置顶点属性指针
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void *)0);
|
||||
glEnableVertexAttribArray(0);
|
||||
|
||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void *)(2 * sizeof(float)));
|
||||
glEnableVertexAttribArray(1);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindVertexArray(0);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLESRenderer::Clear()
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// 清空批处理
|
||||
m_renderBatch.clear();
|
||||
}
|
||||
|
||||
void GLESRenderer::Present()
|
||||
{
|
||||
// 按Z顺序排序
|
||||
std::stable_sort(m_renderBatch.begin(), m_renderBatch.end(),
|
||||
[](const RenderCommand &a, const RenderCommand &b)
|
||||
{
|
||||
return a.z_order < b.z_order;
|
||||
});
|
||||
|
||||
// 使用着色器程序
|
||||
glUseProgram(m_shaderProgram);
|
||||
|
||||
// 设置投影矩阵
|
||||
GLint projLoc = glGetUniformLocation(m_shaderProgram, "uProjection");
|
||||
// 这里需要设置正交投影矩阵
|
||||
|
||||
// 渲染批处理中的所有命令
|
||||
for (const auto &cmd : m_renderBatch)
|
||||
{
|
||||
// 绑定纹理
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, cmd.texture);
|
||||
glUniform1i(glGetUniformLocation(m_shaderProgram, "uTexture"), 0);
|
||||
|
||||
// 计算模型矩阵(位置、旋转、缩放)
|
||||
glm::mat4 model = glm::mat4(1.0f);
|
||||
model = glm::translate(model, glm::vec3(cmd.dstrect.x, cmd.dstrect.y, 0.0f));
|
||||
|
||||
if (cmd.angle != 0)
|
||||
{
|
||||
// 应用旋转
|
||||
model = glm::translate(model, glm::vec3(cmd.center.x, cmd.center.y, 0.0f));
|
||||
model = glm::rotate(model, glm::radians(static_cast<float>(cmd.angle)), glm::vec3(0.0f, 0.0f, 1.0f));
|
||||
model = glm::translate(model, glm::vec3(-cmd.center.x, -cmd.center.y, 0.0f));
|
||||
}
|
||||
|
||||
model = glm::scale(model, glm::vec3(cmd.dstrect.w, cmd.dstrect.h, 1.0f));
|
||||
|
||||
// 设置模型矩阵
|
||||
GLint modelLoc = glGetUniformLocation(m_shaderProgram, "uModel");
|
||||
glUniformMatrix4fv(modelLoc, 1, GL_FALSE, glm::value_ptr(model));
|
||||
|
||||
// 绘制矩形
|
||||
glBindVertexArray(m_vao);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
// 交换缓冲区
|
||||
SDL_GL_SwapWindow(m_window);
|
||||
}
|
||||
|
||||
void GLESRenderer::RenderCopy(GLuint texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
|
||||
{
|
||||
RenderCommand cmd;
|
||||
cmd.texture = texture;
|
||||
if (dstrect)
|
||||
cmd.dstrect = *dstrect;
|
||||
cmd.angle = 0;
|
||||
cmd.flip = SDL_FLIP_NONE;
|
||||
cmd.z_order = 0; // 需要从Sprite获取Z顺序
|
||||
|
||||
m_renderBatch.push_back(cmd);
|
||||
}
|
||||
|
||||
void GLESRenderer::RenderCopyEx(GLuint texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect,
|
||||
double angle, const SDL_Point *center, SDL_RendererFlip flip)
|
||||
{
|
||||
RenderCommand cmd;
|
||||
cmd.texture = texture;
|
||||
if (dstrect)
|
||||
cmd.dstrect = *dstrect;
|
||||
cmd.angle = angle;
|
||||
if (center)
|
||||
cmd.center = *center;
|
||||
cmd.flip = flip;
|
||||
cmd.z_order = 0; // 需要从Sprite获取Z顺序
|
||||
|
||||
m_renderBatch.push_back(cmd);
|
||||
}
|
||||
|
||||
bool GLESRenderer::CompileShader(const char *source, GLenum type, GLuint &shader)
|
||||
{
|
||||
shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &source, NULL);
|
||||
glCompileShader(shader);
|
||||
|
||||
GLint success;
|
||||
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
GLchar infoLog[512];
|
||||
glGetShaderInfoLog(shader, 512, NULL, infoLog);
|
||||
std::cerr << "Shader compilation failed: " << infoLog << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GLESRenderer::LinkProgram(GLuint program)
|
||||
{
|
||||
glLinkProgram(program);
|
||||
|
||||
GLint success;
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||
if (!success)
|
||||
{
|
||||
GLchar infoLog[512];
|
||||
glGetProgramInfoLog(program, 512, NULL, infoLog);
|
||||
std::cerr << "Program linking failed: " << infoLog << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GLESRenderer::CreateShaderProgram()
|
||||
{
|
||||
if (!CompileShader(vertexShaderSource, GL_VERTEX_SHADER, m_vertexShader))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CompileShader(fragmentShaderSource, GL_FRAGMENT_SHADER, m_fragmentShader))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_shaderProgram = glCreateProgram();
|
||||
glAttachShader(m_shaderProgram, m_vertexShader);
|
||||
glAttachShader(m_shaderProgram, m_fragmentShader);
|
||||
|
||||
if (!LinkProgram(m_shaderProgram))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
glDeleteShader(m_vertexShader);
|
||||
glDeleteShader(m_fragmentShader);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GLESRenderer::SetOrthographicProjection(int width, int height)
|
||||
{
|
||||
// 设置正交投影矩阵
|
||||
glm::mat4 projection = glm::ortho(0.0f, static_cast<float>(width),
|
||||
static_cast<float>(height), 0.0f,
|
||||
-1.0f, 1.0f);
|
||||
|
||||
glUseProgram(m_shaderProgram);
|
||||
GLint projLoc = glGetUniformLocation(m_shaderProgram, "uProjection");
|
||||
glUniformMatrix4fv(projLoc, 1, GL_FALSE, glm::value_ptr(projection));
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
// GLESRenderer.h
|
||||
#pragma once
|
||||
|
||||
#include <GLES3/gl3.h>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class GLESRenderer
|
||||
{
|
||||
public:
|
||||
GLESRenderer(SDL_Window *window);
|
||||
~GLESRenderer();
|
||||
|
||||
bool Initialize();
|
||||
void Clear();
|
||||
void Present();
|
||||
|
||||
// 模拟 SDL_RenderCopy 功能
|
||||
void RenderCopy(GLuint texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect);
|
||||
void RenderCopyEx(GLuint texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect,
|
||||
double angle, const SDL_Point *center, SDL_RendererFlip flip);
|
||||
|
||||
// // 纹理管理
|
||||
// GLuint CreateTexture(const std::string &path);
|
||||
// GLuint CreateTextureFromSurface(SDL_Surface *surface);
|
||||
// void DestroyTexture(GLuint texture);
|
||||
|
||||
// // 设置渲染状态
|
||||
// void SetDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
|
||||
|
||||
private:
|
||||
SDL_Window *m_window;
|
||||
SDL_GLContext m_glContext;
|
||||
|
||||
// 着色器程序
|
||||
GLuint m_shaderProgram;
|
||||
GLuint m_vertexShader;
|
||||
GLuint m_fragmentShader;
|
||||
|
||||
// 顶点缓冲区对象
|
||||
GLuint m_vbo;
|
||||
GLuint m_vao;
|
||||
|
||||
// 批处理系统
|
||||
struct RenderCommand
|
||||
{
|
||||
GLuint texture;
|
||||
SDL_Rect dstrect;
|
||||
double angle;
|
||||
SDL_Point center;
|
||||
SDL_RendererFlip flip;
|
||||
int z_order;
|
||||
};
|
||||
|
||||
std::vector<RenderCommand> m_renderBatch;
|
||||
|
||||
// 编译着色器
|
||||
bool CompileShader(const char *source, GLenum type, GLuint &shader);
|
||||
bool LinkProgram(GLuint program);
|
||||
|
||||
// 创建着色器程序
|
||||
bool CreateShaderProgram();
|
||||
|
||||
// 设置正交投影矩阵
|
||||
void SetOrthographicProjection(int width, int height);
|
||||
};
|
||||
|
|
@ -1,22 +1,37 @@
|
|||
#include "Texture.h"
|
||||
#include "EngineFrame/Render/Texture.h"
|
||||
#include "EngineCore/Asset_ImagePack.h"
|
||||
#include "EngineCore/Game.h"
|
||||
#include "Texture.h"
|
||||
|
||||
Texture::Texture()
|
||||
{
|
||||
}
|
||||
|
||||
Texture::Texture(std::string PngPath)
|
||||
{
|
||||
SDL_Surface *surface = IMG_Load(PngPath.c_str());
|
||||
if (!surface)
|
||||
{
|
||||
SDL_Log("无法加载图片: %s", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
m_texture = SDL_CreateTextureFromSurface(Game::GetInstance().GetRenderer(), surface);
|
||||
if (!m_texture)
|
||||
{
|
||||
SDL_Log("无法创建纹理: %s", SDL_GetError());
|
||||
SDL_FreeSurface(surface); // 记得释放surface
|
||||
return;
|
||||
}
|
||||
|
||||
this->TextureSize.width = surface->w;
|
||||
this->TextureSize.height = surface->h;
|
||||
this->TextureFramepos.width = surface->w;
|
||||
this->TextureFramepos.height = surface->h;
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
Texture::Texture(std::string imgPath, int Index)
|
||||
{
|
||||
Init(imgPath, Index);
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
SDL_DestroyTexture(m_texture);
|
||||
}
|
||||
|
||||
void Texture::Init(std::string imgPath, int Index)
|
||||
{
|
||||
Asset_ImagePack::IMG *Info = Asset_ImagePack::GetInstance().GetIMG(imgPath);
|
||||
if (Info->lpImgName == "sprite/interface/base.img")
|
||||
|
|
@ -38,10 +53,15 @@ void Texture::Init(std::string imgPath, int Index)
|
|||
|
||||
this->TexturePos.x = Buf.Xpos;
|
||||
this->TexturePos.y = Buf.Ypos;
|
||||
this->TextureSize.x = Buf.Width;
|
||||
this->TextureSize.y = Buf.Height;
|
||||
this->TextureFramepos.x = Buf.FrameXpos;
|
||||
this->TextureFramepos.y = Buf.FrameYpos;
|
||||
this->TextureSize.width = Buf.Width;
|
||||
this->TextureSize.height = Buf.Height;
|
||||
this->TextureFramepos.width = Buf.FrameXpos;
|
||||
this->TextureFramepos.height = Buf.FrameYpos;
|
||||
}
|
||||
|
||||
Texture::~Texture()
|
||||
{
|
||||
SDL_DestroyTexture(m_texture);
|
||||
}
|
||||
|
||||
SDL_Texture *Texture::GetTexture()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include <SDL.h>
|
||||
#include <string>
|
||||
#include "Tool/RefPtr.h"
|
||||
#include "Tool/RefObject.h"
|
||||
|
||||
class Texture : public RefObject
|
||||
{
|
||||
|
|
@ -9,18 +11,17 @@ private:
|
|||
SDL_Texture *m_texture = nullptr;
|
||||
|
||||
public:
|
||||
SDL_Point TextureSize = {0, 0}; // 纹理大小
|
||||
SDL_Point TexturePos = {0, 0}; // 纹理位置
|
||||
SDL_Point TextureFramepos = {0, 0}; // 帧域宽高
|
||||
VecSize TextureSize = {0, 0}; // 纹理大小
|
||||
VecPos TexturePos = {0, 0}; // 纹理位置
|
||||
VecSize TextureFramepos = {0, 0}; // 帧域宽高
|
||||
|
||||
public:
|
||||
Texture(/* args */);
|
||||
Texture(std::string PngPath);
|
||||
Texture(std::string imgPath, int Index);
|
||||
~Texture();
|
||||
|
||||
public:
|
||||
void Init(std::string imgPath, int Index);
|
||||
|
||||
void SetBlendMode(SDL_BlendMode blendMode);
|
||||
// 获取混合模式
|
||||
SDL_BlendMode GetBlendMode();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ void Scene::Exit()
|
|||
void Scene::AddChild(RefPtr<Actor> actor)
|
||||
{
|
||||
m_Actors.PushBack(actor);
|
||||
actor->Parent = this;
|
||||
actor->OnAdded(this);
|
||||
// 排序演员
|
||||
actor->ReorderActors();
|
||||
}
|
||||
|
||||
void Scene::Update(float deltaTime)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ public:
|
|||
|
||||
public:
|
||||
void AddChild(RefPtr<Actor> actor);
|
||||
|
||||
private:
|
||||
IntrusiveList<RefPtr<Actor>> m_Actors;
|
||||
|
||||
};
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <cstddef>
|
||||
#include <SDL.h>
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 不可拷贝对象
|
||||
|
|
@ -23,3 +24,58 @@ private:
|
|||
|
||||
Noncopyable &operator=(const Noncopyable &) = delete;
|
||||
};
|
||||
|
||||
typedef struct VecPos
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
// 构造函数,方便初始化
|
||||
VecPos(int x_ = 0, int y_ = 0) : x(x_), y(y_) {}
|
||||
|
||||
// 定义到 SDL_Point 的转换运算符
|
||||
operator SDL_Point() const
|
||||
{
|
||||
return {x, y}; // 直接返回包含 x、y 的 SDL_Point
|
||||
}
|
||||
|
||||
// 加法运算符重载:两个 VecPos 相加
|
||||
VecPos operator+(const VecPos &other) const
|
||||
{
|
||||
return VecPos(x + other.x, y + other.y);
|
||||
}
|
||||
|
||||
// 减法运算符重载:两个 VecPos 相减
|
||||
VecPos operator-(const VecPos &other) const
|
||||
{
|
||||
return VecPos(x - other.x, y - other.y);
|
||||
}
|
||||
|
||||
// 复合赋值加法:当前对象加上另一个 VecPos
|
||||
VecPos &operator+=(const VecPos &other)
|
||||
{
|
||||
x += other.x;
|
||||
y += other.y;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// 复合赋值减法:当前对象减去另一个 VecPos
|
||||
VecPos &operator-=(const VecPos &other)
|
||||
{
|
||||
x -= other.x;
|
||||
y -= other.y;
|
||||
return *this;
|
||||
}
|
||||
} VecPos;
|
||||
|
||||
typedef struct VecFPos
|
||||
{
|
||||
float x;
|
||||
float y;
|
||||
} VecFPos;
|
||||
|
||||
typedef struct VecSize
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
} VecSize;
|
||||
|
|
@ -3,9 +3,10 @@
|
|||
#include <cstdint>
|
||||
enum class Tag
|
||||
{
|
||||
NONE = 0, // 无标签
|
||||
UPDATE = 1 << 0, // 更新标签
|
||||
RENDER = 1 << 1, // 渲染标签
|
||||
NONE = 0, // 无标签
|
||||
UPDATE = 1 << 0, // 更新标签
|
||||
RENDER = 1 << 1, // 渲染标签
|
||||
TRANSFORM = 1 << 2, // 变换标签
|
||||
};
|
||||
|
||||
constexpr Tag operator|(Tag a, Tag b)
|
||||
|
|
|
|||
|
|
@ -24,10 +24,14 @@
|
|||
|
||||
void InitScript()
|
||||
{
|
||||
SDL_Log("开始初始化PVF");
|
||||
SDL_Log("开始初始化PVF 和 NPK");
|
||||
// 初始化脚本资源系统
|
||||
Asset_Script::GetInstance().Init();
|
||||
SDL_Log("PVF初始化完成!");
|
||||
// 初始化Image资源系统
|
||||
Asset_ImagePack::GetInstance().Init();
|
||||
// 更改全局游戏类初始化标志
|
||||
Global_Game::GetInstance().InitFlag = true;
|
||||
SDL_Log("初始化完成!");
|
||||
}
|
||||
|
||||
void RunSetup()
|
||||
|
|
@ -41,7 +45,7 @@ void RunSetup()
|
|||
RefPtr<Scene_Loading_UI> sceneUI = new Scene_Loading_UI;
|
||||
Game::GetInstance().ChangeUIScene(sceneUI);
|
||||
|
||||
ThreadPool::GetInstance().enqueue(InitScript);
|
||||
ThreadPool::GetInstance().enqueueToThread(2, InitScript);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
|
|
@ -53,7 +57,7 @@ int main(int argc, char *argv[])
|
|||
chdir("/switch/Lenheart/MyGame/");
|
||||
|
||||
// 初始化Image资源系统
|
||||
Asset_ImagePack::GetInstance().Init();
|
||||
Asset_ImagePack::GetInstance();
|
||||
// 初始化脚本资源系统
|
||||
Asset_Script::GetInstance();
|
||||
// 初始化线程池
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ void SquirrelEx::Init()
|
|||
sqstd_register_stringlib(v);
|
||||
|
||||
sq_setprintfunc(v, printfunc, errorfunc);
|
||||
RegisterSDLFunctions(v);
|
||||
// RegisterSDLFunctions(v);
|
||||
}
|
||||
|
||||
void SquirrelEx::RequestNetScript(std::string Ip, std::string Port)
|
||||
|
|
|
|||
|
|
@ -1,146 +1,146 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <squirrel.h> // Squirrel核心头文件
|
||||
#include <sqstdio.h> // Squirrel标准IO库
|
||||
#include <sqstdaux.h> // 新增:包含 sqstd_seterrorhandlers 等辅助函数
|
||||
#include <sqstdblob.h> // 新增:包含 sqstd_register_bloblib 函数
|
||||
#include <sqstdsystem.h> // 新增:包含 sqstd_register_systemlib 函数
|
||||
#include <sqstdmath.h> // 新增:包含 sqstd_register_mathlib 函数
|
||||
#include <sqstdstring.h> // 新增:包含 sqstd_register_stringlib 函数
|
||||
#include "EngineCore/Asset_ImagePack.h"
|
||||
#include "EngineCore/Game.h"
|
||||
// #pragma once
|
||||
// #include <string>
|
||||
// #include <squirrel.h> // Squirrel核心头文件
|
||||
// #include <sqstdio.h> // Squirrel标准IO库
|
||||
// #include <sqstdaux.h> // 新增:包含 sqstd_seterrorhandlers 等辅助函数
|
||||
// #include <sqstdblob.h> // 新增:包含 sqstd_register_bloblib 函数
|
||||
// #include <sqstdsystem.h> // 新增:包含 sqstd_register_systemlib 函数
|
||||
// #include <sqstdmath.h> // 新增:包含 sqstd_register_mathlib 函数
|
||||
// #include <sqstdstring.h> // 新增:包含 sqstd_register_stringlib 函数
|
||||
// #include "EngineCore/Asset_ImagePack.h"
|
||||
// #include "EngineCore/Game.h"
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
// #include <SDL2/SDL.h>
|
||||
// #include <SDL2/SDL_image.h>
|
||||
// #include <SDL2/SDL_ttf.h>
|
||||
|
||||
// 辅助函数:检查SDL错误并抛出Squirrel异常
|
||||
static void checkSDLError(HSQUIRRELVM v)
|
||||
{
|
||||
const char *err = SDL_GetError();
|
||||
if (err && *err)
|
||||
{
|
||||
sq_throwerror(v, err);
|
||||
SDL_ClearError();
|
||||
}
|
||||
}
|
||||
// // 辅助函数:检查SDL错误并抛出Squirrel异常
|
||||
// static void checkSDLError(HSQUIRRELVM v)
|
||||
// {
|
||||
// const char *err = SDL_GetError();
|
||||
// if (err && *err)
|
||||
// {
|
||||
// sq_throwerror(v, err);
|
||||
// SDL_ClearError();
|
||||
// }
|
||||
// }
|
||||
|
||||
// SDL_GetTicks 绑定
|
||||
static SQInteger sdl_GetTicks(HSQUIRRELVM v)
|
||||
{
|
||||
sq_pushinteger(v, SDL_GetTicks());
|
||||
return 1;
|
||||
}
|
||||
// // SDL_GetTicks 绑定
|
||||
// static SQInteger sdl_GetTicks(HSQUIRRELVM v)
|
||||
// {
|
||||
// sq_pushinteger(v, SDL_GetTicks());
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
static SQInteger sdl_CreateTexture(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *imgPath;
|
||||
SQInteger Index;
|
||||
sq_getstring(v, 2, &imgPath);
|
||||
sq_getinteger(v, 3, &Index);
|
||||
// static SQInteger sdl_CreateTexture(HSQUIRRELVM v)
|
||||
// {
|
||||
// const SQChar *imgPath;
|
||||
// SQInteger Index;
|
||||
// sq_getstring(v, 2, &imgPath);
|
||||
// sq_getinteger(v, 3, &Index);
|
||||
|
||||
Asset_ImagePack::IMG *Info = Asset_ImagePack::GetInstance().GetIMG(imgPath);
|
||||
Asset_ImagePack::ImgInfo &Buf = Info->lp_lplist[Index];
|
||||
SDL_Texture *m_texture = SDL_CreateTexture(
|
||||
Game::GetInstance().GetRenderer(),
|
||||
SDL_PIXELFORMAT_ARGB8888, // 匹配RGBA数据格式
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
Buf.Width, Buf.Height);
|
||||
int pitch = Buf.Width * 4;
|
||||
SDL_UpdateTexture(m_texture, NULL, Buf.PNGdata, pitch);
|
||||
// Asset_ImagePack::IMG *Info = Asset_ImagePack::GetInstance().GetIMG(imgPath);
|
||||
// Asset_ImagePack::ImgInfo &Buf = Info->lp_lplist[Index];
|
||||
// SDL_Texture *m_texture = SDL_CreateTexture(
|
||||
// Game::GetInstance().GetRenderer(),
|
||||
// SDL_PIXELFORMAT_ARGB8888, // 匹配RGBA数据格式
|
||||
// SDL_TEXTUREACCESS_STREAMING,
|
||||
// Buf.Width, Buf.Height);
|
||||
// int pitch = Buf.Width * 4;
|
||||
// SDL_UpdateTexture(m_texture, NULL, Buf.PNGdata, pitch);
|
||||
|
||||
sq_pushuserpointer(v, m_texture);
|
||||
return 1;
|
||||
}
|
||||
// sq_pushuserpointer(v, m_texture);
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
static SQInteger sdl_DrawImg(HSQUIRRELVM v)
|
||||
{
|
||||
SQUserPointer m_texture;
|
||||
SQInteger PosX, PosY, Width, Height;
|
||||
// static SQInteger sdl_DrawImg(HSQUIRRELVM v)
|
||||
// {
|
||||
// SQUserPointer m_texture;
|
||||
// SQInteger PosX, PosY, Width, Height;
|
||||
|
||||
sq_getuserpointer(v, 2, &m_texture);
|
||||
sq_getinteger(v, 3, &PosX);
|
||||
sq_getinteger(v, 4, &PosY);
|
||||
sq_getinteger(v, 5, &Width);
|
||||
sq_getinteger(v, 6, &Height);
|
||||
// sq_getuserpointer(v, 2, &m_texture);
|
||||
// sq_getinteger(v, 3, &PosX);
|
||||
// sq_getinteger(v, 4, &PosY);
|
||||
// sq_getinteger(v, 5, &Width);
|
||||
// sq_getinteger(v, 6, &Height);
|
||||
|
||||
SDL_Rect Rect = {(int)PosX, (int)PosY, (int)Width, (int)Height};
|
||||
SDL_RenderCopy(Game::GetInstance().GetRenderer(), (SDL_Texture *)m_texture, NULL, &Rect);
|
||||
// SDL_Rect Rect = {(int)PosX, (int)PosY, (int)Width, (int)Height};
|
||||
// SDL_RenderCopy(Game::GetInstance().GetRenderer(), (SDL_Texture *)m_texture, NULL, &Rect);
|
||||
|
||||
return 0;
|
||||
}
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
static SQInteger sdl_DrawImgEx(HSQUIRRELVM v)
|
||||
{
|
||||
const SQChar *imgPath;
|
||||
SQInteger Index, PosX, PosY, BlendMode;
|
||||
SQFloat Rotate;
|
||||
// static SQInteger sdl_DrawImgEx(HSQUIRRELVM v)
|
||||
// {
|
||||
// const SQChar *imgPath;
|
||||
// SQInteger Index, PosX, PosY, BlendMode;
|
||||
// SQFloat Rotate;
|
||||
|
||||
sq_getstring(v, 2, &imgPath);
|
||||
sq_getinteger(v, 3, &Index);
|
||||
sq_getinteger(v, 4, &PosX);
|
||||
sq_getinteger(v, 5, &PosY);
|
||||
sq_getinteger(v, 6, &BlendMode);
|
||||
sq_getfloat(v, 7, &Rotate);
|
||||
// sq_getstring(v, 2, &imgPath);
|
||||
// sq_getinteger(v, 3, &Index);
|
||||
// sq_getinteger(v, 4, &PosX);
|
||||
// sq_getinteger(v, 5, &PosY);
|
||||
// sq_getinteger(v, 6, &BlendMode);
|
||||
// sq_getfloat(v, 7, &Rotate);
|
||||
|
||||
Asset_ImagePack::IMG *Info = Asset_ImagePack::GetInstance().GetIMG(imgPath);
|
||||
Asset_ImagePack::ImgInfo &Buf = Info->lp_lplist[Index];
|
||||
SDL_Point pivotPoint = {
|
||||
(int)(0.5 * Buf.Width),
|
||||
(int)(0.5 * Buf.Height)};
|
||||
// Asset_ImagePack::IMG *Info = Asset_ImagePack::GetInstance().GetIMG(imgPath);
|
||||
// Asset_ImagePack::ImgInfo &Buf = Info->lp_lplist[Index];
|
||||
// SDL_Point pivotPoint = {
|
||||
// (int)(0.5 * Buf.Width),
|
||||
// (int)(0.5 * Buf.Height)};
|
||||
|
||||
SDL_Texture *m_texture = SDL_CreateTexture(
|
||||
Game::GetInstance().GetRenderer(),
|
||||
SDL_PIXELFORMAT_ARGB8888, // 匹配RGBA数据格式
|
||||
SDL_TEXTUREACCESS_STREAMING,
|
||||
Buf.Width, Buf.Height);
|
||||
SDL_SetTextureBlendMode(m_texture, (SDL_BlendMode)BlendMode);
|
||||
int pitch = Buf.Width * 4;
|
||||
SDL_UpdateTexture(m_texture, NULL, Buf.PNGdata, pitch);
|
||||
SDL_Rect Rect = {(int)PosX, (int)PosY, Buf.Width, Buf.Height};
|
||||
SDL_RenderCopyEx(Game::GetInstance().GetRenderer(), m_texture, NULL, &Rect, Rotate, &pivotPoint, SDL_FLIP_NONE);
|
||||
SDL_DestroyTexture(m_texture);
|
||||
// SDL_Texture *m_texture = SDL_CreateTexture(
|
||||
// Game::GetInstance().GetRenderer(),
|
||||
// SDL_PIXELFORMAT_ARGB8888, // 匹配RGBA数据格式
|
||||
// SDL_TEXTUREACCESS_STREAMING,
|
||||
// Buf.Width, Buf.Height);
|
||||
// SDL_SetTextureBlendMode(m_texture, (SDL_BlendMode)BlendMode);
|
||||
// int pitch = Buf.Width * 4;
|
||||
// SDL_UpdateTexture(m_texture, NULL, Buf.PNGdata, pitch);
|
||||
// SDL_Rect Rect = {(int)PosX, (int)PosY, Buf.Width, Buf.Height};
|
||||
// SDL_RenderCopyEx(Game::GetInstance().GetRenderer(), m_texture, NULL, &Rect, Rotate, &pivotPoint, SDL_FLIP_NONE);
|
||||
// SDL_DestroyTexture(m_texture);
|
||||
|
||||
return 0;
|
||||
}
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
void RegisterSDLFunctions(HSQUIRRELVM v)
|
||||
{
|
||||
// 创建SDL命名空间
|
||||
sq_pushstring(v, "SDL", -1);
|
||||
sq_newtable(v);
|
||||
// void RegisterSDLFunctions(HSQUIRRELVM v)
|
||||
// {
|
||||
// // 创建SDL命名空间
|
||||
// sq_pushstring(v, "SDL", -1);
|
||||
// sq_newtable(v);
|
||||
|
||||
// 注册SDL函数
|
||||
// // 注册SDL函数
|
||||
|
||||
// 获取Ticks函数
|
||||
sq_pushstring(v, "GetTicks", -1);
|
||||
sq_newclosure(v, sdl_GetTicks, 0);
|
||||
sq_setparamscheck(v, 1, NULL);
|
||||
sq_rawset(v, -3);
|
||||
// // 获取Ticks函数
|
||||
// sq_pushstring(v, "GetTicks", -1);
|
||||
// sq_newclosure(v, sdl_GetTicks, 0);
|
||||
// sq_setparamscheck(v, 1, NULL);
|
||||
// sq_rawset(v, -3);
|
||||
|
||||
// 创建纹理
|
||||
sq_pushstring(v, "CreateTexture", -1);
|
||||
sq_newclosure(v, sdl_CreateTexture, 0);
|
||||
// sq_setparamscheck(v, 3, NULL);
|
||||
sq_rawset(v, -3);
|
||||
// // 创建纹理
|
||||
// sq_pushstring(v, "CreateTexture", -1);
|
||||
// sq_newclosure(v, sdl_CreateTexture, 0);
|
||||
// // sq_setparamscheck(v, 3, NULL);
|
||||
// sq_rawset(v, -3);
|
||||
|
||||
// 渲染一个Img
|
||||
sq_pushstring(v, "DrawImg", -1);
|
||||
sq_newclosure(v, sdl_DrawImg, 0);
|
||||
// sq_setparamscheck(v, 5, NULL);
|
||||
sq_rawset(v, -3);
|
||||
// // 渲染一个Img
|
||||
// sq_pushstring(v, "DrawImg", -1);
|
||||
// sq_newclosure(v, sdl_DrawImg, 0);
|
||||
// // sq_setparamscheck(v, 5, NULL);
|
||||
// sq_rawset(v, -3);
|
||||
|
||||
// 渲染一个ImgEx
|
||||
sq_pushstring(v, "DrawImgEx", -1);
|
||||
sq_newclosure(v, sdl_DrawImgEx, 0);
|
||||
sq_rawset(v, -3);
|
||||
// // 渲染一个ImgEx
|
||||
// sq_pushstring(v, "DrawImgEx", -1);
|
||||
// sq_newclosure(v, sdl_DrawImgEx, 0);
|
||||
// sq_rawset(v, -3);
|
||||
|
||||
// 注册SDL常量
|
||||
// // 注册SDL常量
|
||||
|
||||
sq_pushstring(v, "RENDERER_ACCELERATED", -1);
|
||||
sq_pushinteger(v, SDL_RENDERER_ACCELERATED);
|
||||
sq_rawset(v, -3);
|
||||
// sq_pushstring(v, "RENDERER_ACCELERATED", -1);
|
||||
// sq_pushinteger(v, SDL_RENDERER_ACCELERATED);
|
||||
// sq_rawset(v, -3);
|
||||
|
||||
// 将SDL表添加到全局命名空间
|
||||
sq_rawset(v, -3);
|
||||
}
|
||||
// // 将SDL表添加到全局命名空间
|
||||
// sq_rawset(v, -3);
|
||||
// }
|
||||
|
|
@ -198,7 +198,7 @@ namespace AniScriptParser
|
|||
}
|
||||
|
||||
// 坐标
|
||||
FrameObject.Img_Pos = SDL_Point{blob.getInt(), blob.getInt()};
|
||||
FrameObject.Img_Pos = VecPos{blob.getInt(), blob.getInt()};
|
||||
|
||||
// Img中的项目数量
|
||||
int Img_Flag_Count = blob.getUShort();
|
||||
|
|
@ -235,7 +235,7 @@ namespace AniScriptParser
|
|||
case 7:
|
||||
{
|
||||
Key = "IMAGE_RATE";
|
||||
SDL_FPoint pos{
|
||||
VecFPos pos{
|
||||
blob.getFloat(),
|
||||
blob.getFloat()};
|
||||
FrameObject.Flag.emplace(Key, pos);
|
||||
|
|
|
|||
|
|
@ -6,14 +6,15 @@
|
|||
#include <SDL.h>
|
||||
#include "Tool/Blob.hpp"
|
||||
#include "Tool/Tool_String.h"
|
||||
#include "Tool/Common.h"
|
||||
|
||||
namespace AniScriptParser
|
||||
{
|
||||
using AniFlag = std::variant<
|
||||
int,
|
||||
float,
|
||||
SDL_Point,
|
||||
SDL_FPoint,
|
||||
VecPos,
|
||||
VecFPos,
|
||||
std::string,
|
||||
std::vector<int>,
|
||||
std::vector<float>>;
|
||||
|
|
@ -21,7 +22,7 @@ namespace AniScriptParser
|
|||
{
|
||||
std::string Img_Path; // img路径
|
||||
int Img_Index; // img索引
|
||||
SDL_Point Img_Pos; // img位置
|
||||
VecPos Img_Pos; // img位置
|
||||
std::vector<std::vector<int>> AttackBox; // 攻击框
|
||||
std::vector<std::vector<int>> DamageBox; // 受击框
|
||||
std::unordered_map<std::string, AniFlag> Flag; // Frame特效数据
|
||||
|
|
|
|||
|
|
@ -25,6 +25,9 @@ public:
|
|||
// 字体资源
|
||||
std::vector<TTF_Font *> Fonts;
|
||||
|
||||
// 游戏资源初始化标志
|
||||
bool InitFlag = false;
|
||||
|
||||
private:
|
||||
Global_Game(/* args */);
|
||||
~Global_Game();
|
||||
|
|
|
|||
|
|
@ -27,16 +27,16 @@ void Scene_Loading_UI::Enter()
|
|||
RefPtr<Actor> actor = new Actor;
|
||||
AddChild(actor);
|
||||
|
||||
RefPtr<Sprite> BackGroundSp = new Sprite("sprite/interface2/nowloading/nowloading.img", 1);
|
||||
RefPtr<Sprite> BackGroundSp = new Sprite("ImagePacks2/Loading1.png");
|
||||
actor->AddComponent(BackGroundSp);
|
||||
RefPtr<Sprite> BackGround2Sp = new Sprite("sprite/interface2/nowloading/nowloading.img", 0);
|
||||
BackGround2Sp->SetPos(SDL_Point{0, 686});
|
||||
RefPtr<Sprite> BackGround2Sp = new Sprite("ImagePacks2/Loading0.png");
|
||||
BackGround2Sp->SetPos(VecPos{0, 686});
|
||||
actor->AddComponent(BackGround2Sp);
|
||||
RefPtr<Sprite> LoadCircleSp = new Sprite("sprite/interface2/nowloading/nowloading.img", 4);
|
||||
RefPtr<Sprite> LoadCircleSp = new Sprite("ImagePacks2/Loading2.png");
|
||||
LoadCircleSp->SetName("LoadCircle");
|
||||
LoadCircleSp->SetPos(SDL_Point{1280 - 60, 686 - 60});
|
||||
LoadCircleSp->SetPos(VecPos{1280 - 60, 686 - 60});
|
||||
LoadCircleSp->SetBlendMode(SDL_BLENDMODE_ADD);
|
||||
LoadCircleSp->SetAnchor(SDL_FPoint{0.5, 0.5});
|
||||
LoadCircleSp->SetAnchor(VecFPos{0.5, 0.5});
|
||||
actor->AddComponent(LoadCircleSp);
|
||||
|
||||
actor->SetCallbackOnUpdate([LoadCircleSp](float deltaTime) mutable
|
||||
|
|
@ -56,7 +56,7 @@ void Scene_Loading_UI::HandleEvents(SDL_Event *e)
|
|||
void Scene_Loading_UI::Update(float deltaTime)
|
||||
{
|
||||
Scene::Update(deltaTime);
|
||||
if (Asset_Script::GetInstance().InitFlag)
|
||||
if (Global_Game::GetInstance().InitFlag)
|
||||
{
|
||||
// 设定游戏层场景
|
||||
RefPtr<Scene_Test> scene = new Scene_Test;
|
||||
|
|
|
|||
|
|
@ -18,22 +18,25 @@ public:
|
|||
public:
|
||||
void Enter() override
|
||||
{
|
||||
RefPtr<Actor> actor = new Actor;
|
||||
AddChild(actor);
|
||||
for (size_t i = 0; i < 1000; i++)
|
||||
{
|
||||
RefPtr<Actor> actor = new Actor;
|
||||
AddChild(actor);
|
||||
|
||||
RefPtr<Animation> ani3 = new Animation("common/commoneffect/animation/priestslowheal1.ani");
|
||||
actor->AddComponent(ani3);
|
||||
ani3->SetRenderZOrder(1000);
|
||||
// RefPtr<Animation> ani3 = new Animation("common/commoneffect/animation/priestslowheal1.ani");
|
||||
// actor->AddComponent(ani3);
|
||||
// ani3->SetRenderZOrder(1000);
|
||||
|
||||
RefPtr<Animation> ani = new Animation("common/anton/main.ani");
|
||||
actor->AddComponent(ani);
|
||||
ani->SetRenderZOrder(500);
|
||||
// RefPtr<Animation> ani = new Animation("common/anton/main.ani");
|
||||
// actor->AddComponent(ani);
|
||||
// ani->SetRenderZOrder(500);
|
||||
|
||||
RefPtr<Animation> ani2 = new Animation("common/anton/face/0/0.ani");
|
||||
actor->AddComponent(ani2);
|
||||
ani2->SetRenderZOrder(1000);
|
||||
|
||||
actor->SetPos(SDL_Point{500, 500});
|
||||
RefPtr<Sprite> sprite = new Sprite("sprite/item/avatar/swordman/0sm_acap.img", 0);
|
||||
actor->AddComponent(sprite);
|
||||
// RefPtr<Animation> ani2 = new Animation("common/anton/face/0/0.ani");
|
||||
// actor->AddComponent(ani2);
|
||||
// ani2->SetRenderZOrder(1000);
|
||||
}
|
||||
|
||||
SDL_Log("进入了选择角色场景!");
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue