From 123f00c426d216734cb19e3ca25b04d411307be5 Mon Sep 17 00:00:00 2001 From: Lenheart <947330670@qq.com> Date: Wed, 25 Dec 2024 11:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9C=B0=E5=9B=BE=E6=91=84?= =?UTF-8?q?=E5=83=8F=E6=9C=BA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqr/User/Object/Map/MapCamera.nut | 122 ++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 sqr/User/Object/Map/MapCamera.nut diff --git a/sqr/User/Object/Map/MapCamera.nut b/sqr/User/Object/Map/MapCamera.nut new file mode 100644 index 0000000..021700b --- /dev/null +++ b/sqr/User/Object/Map/MapCamera.nut @@ -0,0 +1,122 @@ +/* +文件名:MapCamera.nut +路径:User/Object/Map/MapCamera.nut +创建日期:2024-12-22 21:56 +文件用途: +*/ +class MapCamera { + //摄像机坐标 + X = 0; + Y = 0; + Z = 0; + + NextX = 0; + + //镜头可行坐标 + MovableAreaX = 0; + MovableAreaY = 0; + + + //背景偏移量 + BackgroundOffset = 0; + //背景层移动速率 + BackgroundMoveSpeed = 1.0; + //人物中线长度 + CharacterLineLength = 0; + + //地图对象 + MyMapParent = null; + //跟随对象 + MyFromParent = null; + //摄像机朝向 + Direction = 1; + //摄像机朝向时间 + DirectionTime = 1; + + //缩放比率 + CameraRate = 1.0; + + constructor(gMap) { + MyMapParent = gMap.weakref(); + } + + + /* + * @函数作用:设置跟随对象 + */ + function SetFromParent(FromParent) { + MyFromParent = FromParent.weakref(); + } + + + /* + * @函数作用: + */ + function SetPosition(gx, gy, gz) { + X = gx * CameraRate; + Y = gy * CameraRate; + Z = gz * CameraRate; + } + + /* + * @函数作用: 增加坐标偏移 + */ + function AddPosition(Type, Value) { + switch (Type) { + case 0: //X + X += Value; + break; + case 1: //Y + Y += Value; + break; + case 2: //Z + Z += Value; + break; + } + } + + /* + * @函数作用: 通过父对象同步自身坐标 + */ + function SyncPosByFromParent(MillisecondsDuration) { + if (MyFromParent) { + local R_X, R_Y, R_Z; + + // //X轴移动特殊判断 + // R_X = MyFromParent.X; + // //为超出中线长度时摄像机不会改变位置 + // if (R_X <= (X + CharacterLineLength) && R_X >= (X - CharacterLineLength)) R_X = X; + // //超出以后 补足位置 + // else if (R_X > (X + CharacterLineLength)) R_X = R_X - CharacterLineLength; + // else if (R_X<(X - CharacterLineLength)) R_X = R_X + CharacterLineLength; + + + //判断是否超出可行区域 + R_X = Math.Min(Math.Max(MyFromParent.X, 533), MovableAreaX - 533); + R_Y = Math.Min(Math.Max(MyFromParent.Y, 300), MovableAreaY - 300); + R_Z = MyFromParent.Z; + + SetPosition(R_X, R_Y, R_Z); + } + } + + /* + * @函数作用:Update + */ + function OnUpdate(Dt) { + //同步自身与跟随对象的坐标 + SyncPosByFromParent(Dt); + + //刷新地图图层的坐标 + foreach(Name, Layer in MyMapParent.LayerObject) { + //X屏幕宽度一般 Y屏幕宽度一半 +Z轴运算 在加统一120的偏移 在家background的偏移 + if (Name == "distantback") { + Layer.SetPosition((-X + 533) * BackgroundMoveSpeed, -Y + Z + 300 + 120 + BackgroundOffset); + } else { + Layer.SetPosition((-X + 533), -Y + Z + 300 + 120 + BackgroundOffset); + } + } + } + + +} \ No newline at end of file