如何在CocosSharp (Android)中缩放CCSprite到任何分辨率
本文关键字:CCSprite 缩放 任何 分辨率 CocosSharp Android | 更新日期: 2023-09-27 18:12:37
我试图在CocosSharp中缩放CCSprite到任何分辨率,这是我得到的:
void AddTruck ()
{
var spriteSheet = new CCSpriteSheet ("animations/truck.plist");
var animationFrames = spriteSheet.Frames.FindAll ((x) => x.TextureFilename.StartsWith ("frame"));
walkAnim = new CCAnimation (animationFrames, 0.1f);
walkRepeat = new CCRepeatForever (new CCAnimate (walkAnim));
truck = new CCSprite (animationFrames.First ()) { Name = "Truck" };
truck.Scale = 0.70f;
AddChild (truck);
}
我希望当它添加到场景时,它会根据设备分辨率调整大小…任何建议吗?
谢谢。
嗯,我认为为了做到这一点,你必须有另一个带有高清图像的文件夹,根据设备分辨率,你使用它们…但是我做了下面的操作,它对我有效:
float ResTruck(CCSprite sprite)
{
float scale = 0.0f;
float resWid = CCScene.DefaultDesignResolutionSize.Width;
float resHei = CCScene.DefaultDesignResolutionSize.Height;
if (resWid > 500)
scale = 0.70f;
else if (resWid > 1080)
scale = 0.90f;
else if (resWid > 1300)
scale = 1.0f;
return scale;
}
然后,我给我的精灵设置scale值:
float scale = ResTruck(truck);
truck.Scale = scale;
就是这样:v