コード例 #1
0
        private void CreateTheButtons()
        {
            CCNode theLayer = GetChildByTag(kTheLayer);

            theLayer.RemoveAllChildrenByTag(kTheButtons);
            int space = 10; // px

            max_w = 0f;
            max_h = 0f;

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    // Add the buttons
                    var button = standardButtonWithTitle(CCRandom.Next(30).ToString());
                    button.SetAdjustBackgroundImage(false);  // Tells the button that the background image must not be adjust
                    // It'll use the prefered size of the background image
                    button.Position = new CCPoint(button.ContentSize.Width / 2 + (button.ContentSize.Width + space) * i,
                                                  button.ContentSize.Height / 2 + (button.ContentSize.Height + space) * j);
                    theLayer.AddChild(button, kTheButtons);

                    max_w = Math.Max(button.ContentSize.Width * (i + 1) + space * i, max_w);
                    max_h = Math.Max(button.ContentSize.Height * (j + 1) + space * j, max_h);
                }
            }
        }