【问题标题】:How to add background image in CocosSharp?如何在 CocosSharp 中添加背景图片?
【发布时间】:2018-07-27 12:17:23
【问题描述】:

我已使用此代码在 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 添加到与屏幕尺寸相同的图像中。

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢您的回复,会尝试一下并通知您。
    • 这并没有解决问题,我添加了内容大小以根据屏幕大小添加背景图像。
    猜你喜欢
    • 2022-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-04
    • 2020-07-09
    相关资源
    最近更新 更多