首页 > 解决方案 > 如何用背景图像填充 CCLayer?

问题描述

在资源中添加我的图像后,我注意到我的图像仅出现在屏幕的左下角并且尺寸减小了。

如何在我的 CLLayer 上填充图像作为背景?

我尝试将图像添加为子图像并更改其内容的大小但没有成功

  CCSprite sprite = new CCSprite("img.png");
  AddChild(sprite);

在此处输入图像描述

标签: xamarincocossharp

解决方案


您可以设置AnchorPointAnchorMiddle,则图像可以在 CCLayer 的中心:

CCSprite sprite = new CCSprite ("ship.png");
sprite.AnchorPoint = CCPoint.AnchorMiddle;
AddChild(sprite);

如果想让图像填充CCLayer,似乎没有办法改变精灵的大小。所以可能需要将图像的大小改变得更大。

https://docs.microsoft.com/en-us/xamarin/graphics-games/cocossharp/entities#creating-the-ship-entity


推荐阅读