2016-10-10 70 views
0

我想縮放CCSprite在CocosSharp任何決議,這是我的本錢:如何在CocosSharp(Android)中將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); 
    } 

而且我想,當其添加到現場,它根據設備的分辨率大小。 .. 有小費嗎?

謝謝。

回答

0

嗯,我認爲爲了做到這一點,你必須有另一個文件夾與高清圖像,並根據設備的分辨率,你使用'時間...但我做了以下,它爲我工作:

 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; 
    } 

然後,我ASING的 「規模」 的價值我的精靈:

  float scale = ResTruck(truck); 

     truck.Scale = scale; 

就是這樣:v

相關問題