推
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
BaseObject::BaseObject()
|
||||
{
|
||||
Init(); // 调用了RenderBase的Init函数 对象才会被执行回调
|
||||
// 对象要使用中心锚点
|
||||
SetAnchor({0.5f, 0.5f});
|
||||
}
|
||||
|
||||
@@ -11,21 +11,16 @@ BaseObject::~BaseObject()
|
||||
{
|
||||
}
|
||||
|
||||
void BaseObject::Update(float deltaTime)
|
||||
{
|
||||
Actor::Update(deltaTime);
|
||||
}
|
||||
|
||||
void BaseObject::SetPosition(VecFPos3 pos)
|
||||
{
|
||||
if(pos == this->Position)
|
||||
return;
|
||||
if (pos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder(pos.y); // 设置渲染顺序
|
||||
SetZOrder(pos.y); // 设置渲染顺序
|
||||
}
|
||||
this->Position = pos;
|
||||
SetPos(Vec2{this->Position.x, this->Position.y - this->Position.z});
|
||||
Actor::SetPosition(this->Position.x, this->Position.y - this->Position.z);
|
||||
}
|
||||
|
||||
VecFPos3 BaseObject::GetPosition()
|
||||
@@ -38,7 +33,7 @@ void BaseObject::SetXpos(int x)
|
||||
if (x == this->Position.x)
|
||||
return;
|
||||
this->Position.x = x;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
Actor::SetPosition(this->Position.x, this->Position.y - this->Position.z);
|
||||
}
|
||||
|
||||
void BaseObject::SetYpos(int y)
|
||||
@@ -47,10 +42,10 @@ void BaseObject::SetYpos(int y)
|
||||
return;
|
||||
if (y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder(y); // 设置渲染顺序
|
||||
SetZOrder(y); // 设置渲染顺序
|
||||
}
|
||||
this->Position.y = y;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
Actor::SetPosition(this->Position.x, this->Position.y - this->Position.z);
|
||||
}
|
||||
|
||||
void BaseObject::SetZpos(int z)
|
||||
@@ -58,7 +53,7 @@ void BaseObject::SetZpos(int z)
|
||||
if (z == this->Position.z)
|
||||
return;
|
||||
this->Position.z = z;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
Actor::SetPosition(this->Position.x, this->Position.y - this->Position.z);
|
||||
}
|
||||
|
||||
int BaseObject::GetXpos()
|
||||
@@ -84,11 +79,11 @@ void BaseObject::MoveBy(VecFPos3 pos)
|
||||
return;
|
||||
if (RealPos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder(RealPos.y); // 设置渲染顺序
|
||||
SetZOrder(RealPos.y); // 设置渲染顺序
|
||||
}
|
||||
if (RealPos != this->Position){
|
||||
this->Position = RealPos;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
Actor::SetPosition({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,28 +95,28 @@ void BaseObject::MoveBy(int x, int y, int z)
|
||||
return;
|
||||
if (RealPos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder(RealPos.y); // 设置渲染顺序
|
||||
SetZOrder(RealPos.y); // 设置渲染顺序
|
||||
}
|
||||
if (RealPos != this->Position)
|
||||
{
|
||||
this->Position = RealPos;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
Actor::SetPosition({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
}
|
||||
|
||||
void BaseObject::SetDirection(int dir)
|
||||
{
|
||||
this->Direction = dir;
|
||||
Vec2 sc = GetScale();
|
||||
glm::vec2 sc = GetScale();
|
||||
// 朝右
|
||||
if (dir == 0)
|
||||
{
|
||||
SetScale(Vec2({SDL_fabsf(sc.x), sc.y}));
|
||||
SetScale(SDL_fabsf(sc.x), sc.y);
|
||||
}
|
||||
// 朝左
|
||||
else if (dir == 1)
|
||||
{
|
||||
SetScale(Vec2({-SDL_fabsf(sc.x), sc.y}));
|
||||
SetScale(-SDL_fabsf(sc.x), sc.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user