首页 > 解决方案 > 如何在 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 添加到与屏幕尺寸相同的图像中。

标签: xamarinxamarin.formsxamarin.androidgame-developmentcocossharp

解决方案


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

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

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


推荐阅读