Forum Libraries, Components, and Plugins
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

CCSprite in Android?


I'm just loading a background image, and it works fine in the wp8.1 emulator, but when I execute in the android emulators it does not appear, and I don't see any exception.
I'm new using CocosSharp, so I guess I'm doing something wrong, but can't figure it out.
Any help will be very welcome.

Here is my code:

    public static void LoadGame(object sender, EventArgs e)
        CCGameView gameView = sender as CCGameView;

        if (gameView != null)
            var contentSearchPaths = new List<string>() { "Fonts", "Sounds", "Images" };
            CCSizeI viewSize = gameView.ViewSize;

            int width = 720;
            int height = (int)(720 * ((double)Math.Max(viewSize.Width, viewSize.Height) / (double)Math.Min(viewSize.Width, viewSize.Height)));

            // Set world dimensions
            Data.Common.ViewSize = new CCSizeI(width, height);
            gameView.DesignResolution = Data.Common.ViewSize;

            CCSprite.DefaultTexelToContentSizeRatio = 2.0f;

            gameView.ContentManager.SearchPaths = contentSearchPaths;

            gameView.RunWithScene(new Scenes.LanguageSelection(gameView));

public class LanguageSelection : CCScene
    CCLayer layerBackgorund;

    public LanguageSelection(CCGameView gameView) : base(gameView)
        layerBackgorund = new Layers.Background();

public class Background : CCLayer
    private CCSprite background;

    public Background() : base()
        background = new CCSprite("background.png")
            AnchorPoint = new CCPoint(0, 0),
            IsAntialiased = true,
            Position = new CCPoint(0, 0),
            ContentSize = Common.ViewSize

Best Answers


  • Victor.ChelaruVictor.Chelaru USMember, Xamarin Team Xamurai
    edited April 2016

    Unfortunately CocosSharp does not (by default) throw exceptions when files are missing, so problems like these can be a pain to solve.

    You may want to turn on logging which will output errors to help you diagnose the problem:

        CCLog.Logger = Console.WriteLine;

    Full code sample can be found here:

    Without knowing more about your project structure, I'd guess your assets/Content folder does not have the file, or it's in the wrong location, or it's using the wrong build operation. Do you have your file in the assets/Content/Images folder?

    You can follow along this walkthrough to see how to add assets to Android:

  • angerurothangeruroth USMember
    edited April 2016

    Thanks Victor,

    You are right, it says "CocosSharpTests: Texture background.png was not found."
    Although, I'm using the default Images folder for wp8.1 and Android:
    WinPhone > Content/Images/background.png
    Droid > Assets/Content/Images/background.png
    Maybe I'm missing something in the initialization?

Sign In or Register to comment.