Forum Libraries, Components, and Plugins

CCGameView ProgressBar CCLayer

Any examples on how to show the ProgressBar or something in that lines when CCGameView is loading the CCLayer (GameLayer)? GameLayer loads box2D world and other bodies. This is is taking time and I want to display/show a progressbar or something to indicate that the game is loading.

MainActivity has CCGameView. Appreciate any help!

Tagged:

Posts

  • Ruslan0990Ruslan0990 DEMember ✭✭

    Hi DUNES, I recently implemented a loading screen in my game but I'm not sure if it is the 'right' way to do it. So please write if find some issues with it.

    In my android project inside of gameActivity in OnCreate:

     
      gameView = (CCGameView)FindViewById(Resource.Id.GameView);
      gameView.ViewCreated += LoadGame;
     
     

    The LoadGame function starts the LoadingLayer and give it the CCGameView as a parameter:

     
       void LoadGame(object sender, EventArgs e) 
            {
                CCGameView gameView = sender as CCGameView;
                if (gameView != null)
                {
                    gameView.DesignResolution = new CCSizeI(600, 1200); 
                    gameView.ResolutionPolicy = CCViewResolutionPolicy.ShowAll; 
                    gameScene = new CCScene(gameView);
                    gameScene.AddLayer(new LoadingLayer( gameView)); 
                    gameView.RunWithScene(gameScene);
                }
            }
     
     

    The LoadingLayer is a simple CCLayer which uses the received CCGameView to load the assets. Also it preloads sounds and shows a spinner:

     
      public class LoadingLayer : CCLayerColor
        {
            CCScene myGameScene;
            CCGameView myGameView;
            CCLabel spinner;
            public LoadingLayer( CCGameView gv ) : base(CCColor4B.LightGray)
            {
                myGameView = gv;
                myGameScene = new CCScene(gv);
            }
    
            protected override void AddedToScene()
            {
                base.AddedToScene();
                var redColor = new CCColor3B(255, 0, 0);
                var label = new CCLabel("Loading...", "HelveticaNeue-Bold", 24)
                {
                    PositionX = VisibleBoundsWorldspace.Center.X,
                    PositionY = VisibleBoundsWorldspace.Size.Width/8,
                    Color = redColor ,
                    HorizontalAlignment = CCTextAlignment.Center,
                    VerticalAlignment = CCVerticalTextAlignment.Center,
                    AnchorPoint = CCPoint.AnchorMiddle
                };
                AddChild(label);
                // add a rotatting plus 
                spinner = new CCLabel("+", "HelveticaNeue-Bold", 100)
                {
                    Position = VisibleBoundsWorldspace.Center,
                    Color = redColor ,
                    HorizontalAlignment = CCTextAlignment.Center,
                    VerticalAlignment = CCVerticalTextAlignment.Center,
                    AnchorPoint = CCPoint.AnchorMiddle
                };
                AddChild(spinner);
                var rotate = new CCRepeatForever(new CCRotateBy(0.2f, 90f));
                spinner.RunAction(rotate);
            }
    
            public override async void OnEnter()
            {
                base.OnEnter();
                await StartGame();
            }
    
            // Here most of the asset loading it taking place
            private async Task StartGame()
            {
                var contentSearchPaths = new List() { "Fonts", "Sounds" };
                contentSearchPaths.Add("Images/Ld/");  
                CCSprite.DefaultTexelToContentSizeRatio = 1.0f;
                myGameView.ContentManager.SearchPaths = contentSearchPaths;
    
                CCAudioEngine.SharedEngine.PreloadBackgroundMusic("Sounds/backgroundMusic");
                CCAudioEngine.SharedEngine.PreloadEffect("Sounds/swing");
    
                myGameScene.AddLayer(new GameLayer());
                await Task.Delay(1000);
                this.Scene.Director.ReplaceScene(myGameScene);
            }
    
        }
     
     
  • DuITAppsDuITApps USMember ✭✭

    @Ruslan0990 Thank you so much for your reply. I will implement this approach and will keep you posted.

  • DuITAppsDuITApps USMember ✭✭
    edited September 2016

    @Ruslan0990 I tried your option and it is working. I had to adjust few things like Scale factor for my game (I have not included these changes in the game I had published). Google Play link is here. https://play.google.com/store/apps/details?id=com.dunesinfotech.xstrike

    If you have Android phone, please download. It takes time to load and I'm still looking forward to implement a Progress Ring and not sure how to do that though!

  • Ruslan0990Ruslan0990 DEMember ✭✭
    edited September 2016

    @DuITApps Yeah nice App you have there. Where are you from? Do you want to help me with my release ?

Sign In or Register to comment.