Trying to create a scene with a sprite (background), need help

Here is what I'm doing but instead of a sprite background, I get pitch black screen on iOS Simulator:

void CreateScene ()
{
    var viewCenter = new Vector2 (Graphics.Width  * 0.50f * PixelSize, 
                                  Graphics.Height * 0.50f * PixelSize);

    var scene = new Scene();
    scene.CreateComponent<Octree>();
    scene.CreateComponent<DebugRenderer>();

    // Background
    var bgNode = scene.CreateChild( "Background" );
    bgNode.SetPosition2D( viewCenter );
    var bgSprite = bgNode.CreateComponent<StaticSprite2D>();
    var sprite = ResourceCache.GetSprite2D( "bg.png" );
    if (sprite == null) throw new ArgumentException();
    bgSprite.Sprite = sprite;

    // Camera
    var cameraNode = scene.CreateChild( "MainCamera" );
    cameraNode.Position = new Vector3 (0.0f, 0.0f, 0.0f); // Note that Z setting is discarded; use camera.zoom instead (see MoveCamera() below for example)
    var camera = cameraNode.CreateComponent<Camera>();
    camera.Orthographic = true;
    camera.OrthoSize = Graphics.Height * PixelSize;
    camera.Zoom = 1.0f * Math.Min( Graphics.Width  / 1920.0f, 
                                   Graphics.Height / 1280.0f );

    Renderer.SetViewport( 0, new Viewport (Context, scene, camera, null) );
}

What Am I doing wrong? Thanks!

Posts

  • EgorBoEgorBo BYXamarin Team ✭✭✭
    edited January 2016

    @MikeGringauz
    1) bg.png should be located in Resources/Data/bg.png (in the project). ContentType=BundleResource
    2) Since you use custom assets you should provide a folder name (data in our case):
    MyGame() : base(new ApplicationOptions("Data")) {}
    3) Disable "Optimize PNG images files for iOS" in the project properties (iOS build tab)
    should work :smile:

Sign In or Register to comment.