Forum Libraries, Components, and Plugins

Handling phone orientation change

Hi all,

I've just started using cocossharp for a little game project that I am working on. I am trying to get it so that I can control how stuff is positioned and looks in both landscape and portrait views. I have 2 designs for the screen, one for portrait and one for landscape. When the phone rotates it should reposition all the elements so that it uses the correct design. Does anyone have any ideas for how to do this?

My current attempt stores metadata against each CCNode that describes its position etc. For each orientation. When an orientation change event fires I call setdesignresolution with the new screensize and recursively call an OnOrientationChanged function that walks the node tree and applies the relevant settings.

The problem that I am having is that CCdrawNodes and CCLabels appear stretched when I change the design resolution. Maybe there is a way to get them to recalculate or will I have to recreate them all? Am I going about this all wrong?



  • rr2d2rr2d2 USMember ✭✭

    When you change orientations the activity is destroyed and created again so If I were you I would have two seperate ViewCreated events to load your game for either landscape or portrait, like so:

    CCGameView gameView = (CCGameView)FindViewById(Resource.Id.GameView);
    if (IsLandscape)
        gameView.ViewCreated += LoadLandscapeGame;
         gameView.ViewCreated += LoadPortraitGame;


    In your Game Layer class pass in the orientation and take two different paths in your game layer on how to set up labels, nodes etc.

Sign In or Register to comment.