How can I know the width and hight of a CCNodeGrid?

Hi guys, I am a new developer using cocossharp to build a game.

I really want to know how to get the width and hight of a CCNodeGrid, is that equal to its child(CCSprite)?

If so, then how to get the width and hight of a CCSprite?

If I want to change the size of a CCSprite, changing the CCScale is the only way? Can I just set its size using 2 float numbers?

I also feel quite confused about making a game suitable for different size of screens..... who can give me some advices?

Thank you so much :D

Best Answers

  • Victor.ChelaruVictor.Chelaru US Xamurai
    Accepted Answer

    I really want to know how to get the width and hight of a CCNodeGrid, is that equal to its child(CCSprite)?

    I don't have a lot of experience with CCNodeGrids so I can't be of too much help, but I have used the CCNodeGrid class with a CCFadeOutBLTiles to makde a sprite fade out. In this context, the CCNodeGrid takes up the entirety of the screen and is used for the effect. The CCSprite within the CCNodeGrid can be sized independently.

    If so, then how to get the width and hight of a CCSprite?

    var width = sprite.ContentSize.Width;
    var height = sprite.ContentSize.Height;
    

    If I want to change the size of a CCSprite, changing the CCScale is the only way? Can I just set its size using 2 float numbers?

    You can do this a few ways:

    1. You can resize your art. This is preferred as games with differently-scaled art often bad. Having the same pixel size for all your sprites will make your game look consistent.
    2. You can adjust the Scale value:

      sprite.Scale = 2; // will make the sprite show 2x as large
      
    3. You can set the width and height individually by assigning the ContentSize property:

      sprite.ContentSize = new CCSize(500, 100); // 500 units wide, 100 units tall
      

    I also feel quite confused about making a game suitable for different size of screens..... who can give me some advices?

    You can read about resolutions on this guide:

    https://developer.xamarin.com/guides/cross-platform/game_development/cocossharp/resolutions/

Answers

  • Victor.ChelaruVictor.Chelaru USMember, Xamarin Team Xamurai
    Accepted Answer

    I really want to know how to get the width and hight of a CCNodeGrid, is that equal to its child(CCSprite)?

    I don't have a lot of experience with CCNodeGrids so I can't be of too much help, but I have used the CCNodeGrid class with a CCFadeOutBLTiles to makde a sprite fade out. In this context, the CCNodeGrid takes up the entirety of the screen and is used for the effect. The CCSprite within the CCNodeGrid can be sized independently.

    If so, then how to get the width and hight of a CCSprite?

    var width = sprite.ContentSize.Width;
    var height = sprite.ContentSize.Height;
    

    If I want to change the size of a CCSprite, changing the CCScale is the only way? Can I just set its size using 2 float numbers?

    You can do this a few ways:

    1. You can resize your art. This is preferred as games with differently-scaled art often bad. Having the same pixel size for all your sprites will make your game look consistent.
    2. You can adjust the Scale value:

      sprite.Scale = 2; // will make the sprite show 2x as large
      
    3. You can set the width and height individually by assigning the ContentSize property:

      sprite.ContentSize = new CCSize(500, 100); // 500 units wide, 100 units tall
      

    I also feel quite confused about making a game suitable for different size of screens..... who can give me some advices?

    You can read about resolutions on this guide:

    https://developer.xamarin.com/guides/cross-platform/game_development/cocossharp/resolutions/

Sign In or Register to comment.