我试图将CCSprite扩展到CocosSharp中的任何分辨率,这就是我所拥有的:
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);
}
我希望当它添加到场景中时,它会根据设备分辨率进行调整...任何提示?
感谢。
答案 0 :(得分:0)
嗯,我认为为了做到这一点,你必须有另一个带高清图像的文件夹,并根据设备分辨率,你使用'em ...但我做了以下,它对我有用:
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