如何在CocosSharp中添加背景图片?

时间:2018-07-27 12:17:24

标签: xamarin xamarin.forms xamarin.android game-development cocossharp

我已经使用此代码在CCLayer中添加背景图片,但是它不起作用:

public class GameLayer : CCLayerColor
{
    private CCSprite background; 
    public GameLayer() : base(CCColor4B.Transparent)
    {       
        background = new CCSprite("cbg")
        {
            AnchorPoint = new CCPoint(0, 0),
            IsAntialiased = true,
            Position = new CCPoint(0, 0),

        };
        this.AddChild(background);
    }
}

我的问题是图像正在显示,但不像背景图像那样具有屏幕尺寸,它仅显示在屏幕的左下角。

编辑

已解决: 为解决此问题,我在图像中添加了与屏幕尺寸相同的Contnetsize。

1 个答案:

答案 0 :(得分:1)

这是我用来显示背景的代码:

var sprite = new CCSprite("bg.jpg");
sprite.AnchorPoint = new CCPoint(0, 0);
sprite.IsAntialiased = false;
layer.AddChild(sprite);

几乎相同的代码,但是CocosSharp有时会有奇怪的行为。