Exemplo n.º 1
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            var n = new CCMenuItem[] { _title, _content, _yes, _no };

            foreach (var m in n)
            {
                //m.ZOrder = 500;
            }

            _menu = new ModalMenu()
            {
                Position = new CCPoint(GlobalGameData.Window_Center_X, GlobalGameData.Window_Center_Y - 40),
            };

            foreach (var item in n)
            {
                _menu.AddChild(item);
            }

            //          AddChild(_backGround);
            _menu.AlignItemsVertically(30);
            //            _menu.AlignItemsHorizontally(20);

            layer.AddChild(_menu /*,layer.ZOrder+1*/);
            CCLog.Log($"[OreOreLog]:[layer]{layer.ZOrder}");
            CCLog.Log($"[OreOreLog]:[menu]{_menu.ZOrder}");
        }
Exemplo n.º 2
0
        public NodeToWorld()
        {
            //
            // This code tests that nodeToParent works OK:
            //  - It tests different anchor Points
            //  - It tests different children anchor points

            CCSprite back = CCSprite.spriteWithFile(TestResource.s_back3);

            addChild(back, -10);
            back.anchorPoint = (new CCPoint(0, 0));
            CCSize backSize = back.contentSize;

            CCMenuItem item = CCMenuItemImage.itemFromNormalImage(TestResource.s_PlayNormal, TestResource.s_PlaySelect);
            CCMenu     menu = CCMenu.menuWithItems(item);

            menu.alignItemsVertically();
            menu.position = (new CCPoint(backSize.width / 2, backSize.height / 2));
            back.addChild(menu);

            CCActionInterval rot = CCRotateBy.actionWithDuration(5, 360);
            CCAction         fe  = CCRepeatForever.actionWithAction(rot);

            item.runAction(fe);

            CCActionInterval   move      = CCMoveBy.actionWithDuration(3, new CCPoint(200, 0));
            CCActionInterval   move_back = (CCActionInterval)move.reverse();
            CCFiniteTimeAction seq       = CCSequence.actions(move, move_back);
            CCAction           fe2       = CCRepeatForever.actionWithAction((CCActionInterval)seq);

            back.runAction(fe2);
        }
Exemplo n.º 3
0
        public YesNoDialog(string title, string content, Action <object> yes, Action <object> no)
        {
            _title = new MenuItemNoActionLable(new CCLabel(title, "arial", 40))
            {
                //Position=new CCPoint(GlobalGameData.Window_Center_X,GlobalGameData.Window_Center_Y+50),
                Color = CCColor3B.White,
            };
            _content = new MenuItemNoActionLable(new CCLabel(content, "arial", 20))
            {
                //Position=new CCPoint(GlobalGameData.Window_Center_X,GlobalGameData.Window_Center_Y),
                Color = CCColor3B.White,
            };
            _yes = new CCMenuItemLabel(new CCLabel("はい", "arial", 50)
            {
                // Position = new CCPoint(GlobalGameData.Window_Center_X, GlobalGameData.Window_Center_Y)
            }, yes);
            _no = new CCMenuItemLabel(new CCLabel("いいえ", "arial", 50)
            {
                //Position = new CCPoint(GlobalGameData.Window_Center_X, GlobalGameData.Window_Center_Y)
            }, no);

            int margin          = 10;
            var drawNode_height = _title.ContentSize.Height + _content.ContentSize.Height + _yes.ContentSize.Height + 3 * margin;
            var drawNode_width  = 2 * margin + _content.ContentSize.Width;

            var _drawNode = new CCDrawNode();

            _drawNode.DrawRect(new CCRect(GlobalGameData.Window_Center_X, GlobalGameData.Window_Center_Y, drawNode_width, drawNode_height), CCColor4B.White);
            //            _backGround = _drawNode;
        }
Exemplo n.º 4
0
        public void reset()
        {
            Random random   = new Random();
            int    localtag = 0;

            localtag++;

            // TO TRIGGER THE BUG:
            // remove the itself from parent from an action
            // The menu will be removed, but the instance will be alive
            // and then a new node will be allocated occupying the memory.
            // => CRASH BOOM BANG
            CCNode node = getChildByTag(localtag - 1);

            Debug.WriteLine("Menu: %p", node);
            removeChild(node, false);
            //	[self removeChildByTag:localtag-1 cleanup:NO];

            CCMenuItem item1 = CCMenuItemFont.itemFromString("One", this, menuCallback);

            Debug.WriteLine("MenuItemFont: %p", item1);
            CCMenuItem item2 = CCMenuItemFont.itemFromString("Two", this, menuCallback);
            CCMenu     menu  = CCMenu.menuWithItems(item1, item2);

            menu.alignItemsVertically();

            float x = random.Next() * 50;
            float y = random.Next() * 50;

            menu.position = CCPointExtension.ccpAdd(menu.position, new CCPoint(x, y));
            addChild(menu, 0, localtag);

            //[self check:self];
        }
Exemplo n.º 5
0
        public LayerLevels()
        {
            //关卡选择层
            CCPoint offset = new CCPoint(170, 180);

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    //关卡的按钮
                    CCMenuItemSprite level = CCMenuItemSprite.itemFromNormalSprite(
                        CCSprite.spriteWithSpriteFrameName("btn_level1.png"),
                        CCSprite.spriteWithSpriteFrameName("btn_level2.png"),
                        this, click_level);
                    CCMenu menu = CCMenu.menuWithItems(level);
                    //位置相对于左上的UI界面
                    menu.position = CCDirector.sharedDirector().convertToUI(new CCPoint(offset.x + 160 * i, offset.y + 85 * j));
                    this.addChild(menu);
                    //创建一个MenuItem,用作文本内容
                    CCMenuItem menuitem = new CCMenuItem();
                    //指定Arial的字体描述,保证fonts里有Arial.spritefont
                    var text = CCLabelTTF.labelWithString((j * 4 + i + 1).ToString(), "Arial", 12);
                    //将颜色指定为黑色
                    text.Color = new ccColor3B();
                    menuitem.addChild(text);
                    menu.addChild(menuitem);
                }
            }
        }
Exemplo n.º 6
0
        public RenderTextureSave()
        {
            CCSize s = CCDirector.sharedDirector().getWinSize();

            // create a render texture, this is what we are going to draw into
            m_pTarget = CCRenderTexture.renderTextureWithWidthAndHeight((int)s.width, (int)s.height);
            //m_pTarget->retain();
            m_pTarget.position = new CCPoint(s.width / 2, s.height / 2);

            // note that the render texture is a CCNode, and contains a sprite of its texture for convience,
            // so we can just parent it to the scene like any other CCNode
            this.addChild(m_pTarget, -1);

            // create a brush image to draw into the texture with
            m_pBrush = CCSprite.spriteWithFile("Images/fire.png");
            //m_pBrush->retain();
            m_pBrush.Opacity = 20;
            //this->setIsTouchEnabled(true);
            isTouchEnabled = true;

            // Save Image menu
            CCMenuItemFont.FontSize = 16;
            CCMenuItem item1 = CCMenuItemFont.itemFromString("Save Image", this, saveImage);
            CCMenuItem item2 = CCMenuItemFont.itemFromString("Clear", this, clearImage);
            CCMenu     menu  = CCMenu.menuWithItems(item1, item2);

            this.addChild(menu);
            menu.alignItemsVertically();
            menu.position = new CCPoint(s.width - 80, s.height - 30);
        }
Exemplo n.º 7
0
        public IntervalLayer()
        {
            m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f;

            CCSize s = CCDirector.sharedDirector().getWinSize();

            // sun
            //CCParticleSystem sun = CCParticleSun.node();
            //sun.Texture = CCTextureCache.sharedTextureCache().addImage("Images/fire");
            //sun.position = (new CCPoint(s.width - 32, s.height - 32));

            ////sun.setTotalParticles(130);
            //sun.Life = (0.6f);
            //this.addChild(sun);

            // timers
            m_label0 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4");
            m_label1 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4");
            m_label2 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4");
            m_label3 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4");
            m_label4 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4");

            base.scheduleUpdate();
            schedule(step1);
            schedule(step2, 0);
            schedule(step3, 1.0f);
            schedule(step4, 2.0f);

            m_label1.position = new CCPoint(s.width * 2 / 6, s.height / 2);
            m_label2.position = new CCPoint(s.width * 3 / 6, s.height / 2);
            m_label3.position = new CCPoint(s.width * 4 / 6, s.height / 2);
            m_label4.position = new CCPoint(s.width * 5 / 6, s.height / 2);

            addChild(m_label0);
            addChild(m_label1);
            addChild(m_label2);
            addChild(m_label3);
            addChild(m_label4);

            // Sprite
            CCSprite sprite = CCSprite.spriteWithFile(s_pPathGrossini);

            sprite.position = new CCPoint(40, 50);

            CCJumpBy jump = CCJumpBy.actionWithDuration(3, new CCPoint(s.width - 80, 0), 50, 4);

            addChild(sprite);
            sprite.runAction(CCRepeatForever.actionWithAction(
                                 (CCActionInterval)(CCSequence.actions(jump, jump.reverse()))
                                 )
                             );
            // pause button
            CCMenuItem item1 = CCMenuItemFont.itemFromString("Pause", this, onPause);
            CCMenu     menu  = CCMenu.menuWithItems(item1);

            menu.position = new CCPoint(s.width / 2, s.height - 50);

            addChild(menu);
        }
        public override bool init()
        {
            // always call "super" init
            // Apple recommends to re-assign "self" with the "super" return value
            if (base.init())
            {
                isTouchEnabled = true;
                // ask director the the window size
                CCSize       size = CCDirector.sharedDirector().getWinSize();
                CCLayerColor layer;
                CCUserDefault.sharedUserDefault().setBoolForKey("bool", true);
                for (int i = 0; i < 5; i++)
                {
                    ccColor4B c = new ccColor4B((byte)(i * 20), (byte)(i * 20), (byte)(i * 20), 255);
                    CCUserDefault.sharedUserDefault().setStringForKey("i" + i, c.ToString());
                }
                CCUserDefault.sharedUserDefault().flush();
                bool testValue = CCUserDefault.sharedUserDefault().getBoolForKey("bool", false);
                if (!testValue)
                {
                    CCLog.Log("CCUserDefault: Test failed b/c the 'bool' value was not true when it was expected.");
                }
                for (int i = 0; i < 5; i++)
                {
                    string cstr = CCUserDefault.sharedUserDefault().getStringForKey("i" + i, null);
                    if (cstr == null)
                    {
                        CCLog.Log("CCUserDefault: The color for iteration #" + i + " is null.");
                        continue;
                    }
                    ccColor4B c = new ccColor4B((byte)(i * 20), (byte)(i * 20), (byte)(i * 20), 255);
                    layer                       = CCLayerColor.layerWithColor(c);
                    layer.contentSize           = new CCSize(i * 100, i * 100);
                    layer.position              = new CCPoint(size.width / 2, size.height / 2);
                    layer.anchorPoint           = new CCPoint(0.5f, 0.5f);
                    layer.isRelativeAnchorPoint = true;
                    addChild(layer, -1 - i);
                }

                // create and initialize a Label
                CCLabelTTF label = CCLabelTTF.labelWithString("ccUserDefault Test", "Arial", 14);
                CCMenuItem item1 = CCMenuItemFont.itemFromString("restart", this, restart);

                CCMenu menu = CCMenu.menuWithItems(item1);
                menu.alignItemsVertically();
                menu.position = new CCPoint(size.width / 2, 100);
                addChild(menu);

                // position the label on the center of the screen
                label.position = new CCPoint(size.width / 2, size.height / 2);

                // add the label as a child to this Layer
                addChild(label);
                return(true);
            }
            return(false);
        }
Exemplo n.º 9
0
        public void menuCallback(CCObject pSender)
        {
            // get the userdata, it's the index of the menu item clicked
            CCMenuItem pMenuItem = (CCMenuItem)(pSender);
            int nIdx = pMenuItem.zOrder - 10000;

            // create the test scene and run it
            TestScene pScene = CreateTestScene(nIdx);
            if (pScene != null)
            {
                pScene.runThisTest();
            }
        }
Exemplo n.º 10
0
        void MenuCallback(object sender)
        {
            // get the userdata, it's the index of the menu item clicked
            CCMenuItem menuItem = (CCMenuItem)sender;
            var        nIdx     = menuItem.ZOrder - MENU_ITEM_Z_ORDER;

            // create the test scene and run it
            TestScene scene = CreateTestScene(nIdx);

            if (scene != null)
            {
                scene.runThisTest();
            }
        }
Exemplo n.º 11
0
        public void menuCallback(CCMenuItem pSender)
        {
            // get the userdata, it's the index of the menu item clicked
            CCMenuItem pMenuItem = (CCMenuItem)(pSender);
            int        nIdx      = (int)pMenuItem.UserData;

            // create the test scene and run it
            TestScene pScene = CreateTestScene(nIdx);

            if (pScene != null)
            {
                CCApplication.SharedApplication.GamePadDPadUpdate   -= _GamePadDPadDelegate;
                CCApplication.SharedApplication.GamePadButtonUpdate -= _GamePadButtonDelegate;
                pScene.runThisTest();
            }
        }
Exemplo n.º 12
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            var label = new CCLabelBMFont("Enable AtlasItem", "fonts/bitmapFontTest3.fnt");
            var item1 = new CCMenuItemLabelBMFont(label, this.menuCallback2);

            CCMenuItemFont.FontSize = 28;
            CCMenuItemFont.FontName = "arial";

            var item2 = new CCMenuItemFont("--- Go Back ---", this.menuCallback);

            // We do not have an HD version of the menuitemsprite so internally CocosSharp tries to convert our
            // rectangle coordinates passed to work with HD images so the coordinates are off.  We will just
            // modify this here to make sure we have the correct sizes when they are passed.
            var spriteNormal   = new CCSprite(s_MenuItem, new CCRect(0, 23 * 2, 115, 23));
            var spriteSelected = new CCSprite(s_MenuItem, new CCRect(0, 23 * 1, 115, 23));
            var spriteDisabled = new CCSprite(s_MenuItem, new CCRect(0, 23 * 0, 115, 23));


            var item3 = new CCMenuItemImage(spriteNormal, spriteSelected, spriteDisabled, this.menuCallback3);

            m_disabledItem         = item3;
            m_disabledItem.Enabled = false;

            var menu = new CCMenu(item1, item2, item3);

            menu.Position = new CCPoint(0, 0);

            var s = Layer.VisibleBoundsWorldspace.Size;

            item1.Position = new CCPoint(s.Width / 2 - 150, s.Height / 2);
            item2.Position = new CCPoint(s.Width / 2 - 200, s.Height / 2);
            item3.Position = new CCPoint(s.Width / 2, s.Height / 2 - 100);

            var jump = new CCJumpBy(3, new CCPoint(400, 0), 50, 4);

            item2.RepeatForever(jump, jump.Reverse());

            var spin1 = new CCRotateBy(3, 360);

            item1.RepeatForever(spin1);
            item2.RepeatForever(spin1);
            item3.RepeatForever(spin1);

            AddChild(menu);
        }
Exemplo n.º 13
0
        public MenuLayer3()
        {
            CCMenuItemFont.FontName = "Arial";
            CCMenuItemFont.FontSize = 28;

            CCLabelBMFont   label = CCLabelBMFont.labelWithString("Enable AtlasItem", "fonts/fnt/bitmapFontTest3");
            CCMenuItemLabel item1 = CCMenuItemLabel.itemWithLabel(label, this, this.menuCallback2);
            CCMenuItemFont  item2 = CCMenuItemFont.itemFromString("--- Go Back ---", this, this.menuCallback);

            m_item2 = item2;
            m_item1 = item1;
            CCSprite spriteNormal   = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 2, 115, 23));
            CCSprite spriteSelected = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 1, 115, 23));
            CCSprite spriteDisabled = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 0, 115, 23));


            CCMenuItemSprite item3 = CCMenuItemSprite.itemFromNormalSprite(spriteNormal, spriteSelected, spriteDisabled, this, this.menuCallback3);

            m_disabledItem         = item3;
            m_disabledItem.Enabled = false;
            m_item3 = item3;

            CCMenu menu = CCMenu.menuWithItems(item1, item2, item3);

            menu.position = new CCPoint(0, 0);

            addChild(menu);
            CCSize s = CCDirector.sharedDirector().getWinSize();

            m_item1.position = new CCPoint(s.width / 2 - 150, s.height / 2);
            m_item2.position = new CCPoint(s.width / 2 - 200, s.height / 2);
            m_item3.position = new CCPoint(s.width / 2, s.height / 2 - 100);
            CCJumpBy         jump  = CCJumpBy.actionWithDuration(3, new CCPoint(400, 0), 50, 4);
            CCActionInterval spin1 = CCRotateBy.actionWithDuration(3, 360);
            CCActionInterval spin2 = (CCActionInterval)(spin1.copy());
            CCActionInterval spin3 = (CCActionInterval)(spin1.copy());

            m_item1.runAction(CCRepeatForever.actionWithAction(spin1));
            m_item2.runAction(CCRepeatForever.actionWithAction(
                                  (CCActionInterval)(CCSequence.actions(jump, jump.reverse()))
                                  )
                              );
            m_item2.runAction(CCRepeatForever.actionWithAction(spin2)); // Augments the jump
            m_item3.runAction(CCRepeatForever.actionWithAction(spin3));
        }
Exemplo n.º 14
0
        public TestController()
        {
            // Add close menu
            closeMenuItem = new CCMenuItemImage(TestResource.s_pPathClose, TestResource.s_pPathClose, CloseCallback);
            closeMenu     = new CCMenu(closeMenuItem);

            CCMenuItemFont.FontName = "MarkerFelt";
            CCMenuItemFont.FontSize = 22;


            #if !PSM && !WINDOWS_PHONE
            #if NETFX_CORE && !WINDOWS_UWP
            versionLabel = new CCLabel("v" + this.GetType().GetAssemblyName().Version.ToString(), "arial", 30);
#elif WINDOWS_UWP
            versionLabel = new CCLabel("v" + this.GetType().GetTypeInfo().Assembly.GetName().Version.ToString(), "arial", 30);
#else
            versionLabel = new CCLabel("v" + this.GetType().Assembly.GetName().Version.ToString(), "fonts/arial", 24, CCLabelFormat.SpriteFont);
#endif
            AddChild(versionLabel, 20000);
            #endif

            // Add test list menu
            testListMenu = new CCMenu();

            var i = 0;
            foreach (var test in testCases.Keys)
            {
                var label    = new CCLabel(test, "fonts/arial", 24, CCLabelFormat.SpriteFont);
                var menuItem = new CCMenuItemLabel(label, MenuCallback);

                testListMenu.AddChild(menuItem, i++ + MENU_ITEM_Z_ORDER);
                testListMenuItems.Add(menuItem);
            }

            LINE_SPACE = (int)(testListMenuItems[0].ContentSize.Height * 1.5f);

            #if XBOX || OUYA
            CCSprite sprite = new CCSprite("Images/aButton");
            AddChild(sprite, 10001);
            menuIndicator = sprite;
            #endif

            AddChild(testListMenu);
            AddChild(closeMenu, 1);
        }
        public ChooseLevelLayer()
        {
            SetupBackground();
            menuHeader  = new CCMenuItemImage("LevelsScene/game-mode.png", "LevelsScene/game-mode.png", OnGoBack);
            button8x10  = new CCMenuItemImage("LevelsScene/btn-8x10.png", "LevelsScene/btn-8x10-down.png", SetField8x10);
            button12x12 = new CCMenuItemImage("LevelsScene/btn-12x12.png", "LevelsScene/btn-12x12-down.png", SetField12x12);
            button13x15 = new CCMenuItemImage("LevelsScene/btn-13x15.png", "LevelsScene/btn-13x15-down.png", SetField13x15);
#if WINDOWS_PHONE || ANDROID
            button8x10.Scale = button12x12.Scale = button13x15.Scale = 0.6f;
#endif
            var chooseLevelMenu = new CCMenu(menuHeader, button8x10, button12x12, button13x15);
            chooseLevelMenu.AlignItemsVerticallyWithPadding(10);
            AddChild(chooseLevelMenu);


            menuHeader.Position  += new CCPoint(0, 300);
            button13x15.Position -= new CCPoint(0, 1000);
        }
Exemplo n.º 16
0
        public MenuLayer3()
        {
            CCMenuItemFont.FontName = "arial";
            CCMenuItemFont.FontSize = 28;

            CCLabelBMFont   label = new CCLabelBMFont("Enable AtlasItem", "fonts/bitmapFontTest3.fnt");
            CCMenuItemLabel item1 = new CCMenuItemLabel(label, this.menuCallback2);
            CCMenuItemFont  item2 = new CCMenuItemFont("--- Go Back ---", this.menuCallback);

            CCSprite spriteNormal   = new CCSprite(s_MenuItem, new CCRect(0, 23 * 2, 115, 23));
            CCSprite spriteSelected = new CCSprite(s_MenuItem, new CCRect(0, 23 * 1, 115, 23));
            CCSprite spriteDisabled = new CCSprite(s_MenuItem, new CCRect(0, 23 * 0, 115, 23));


            CCMenuItemSprite item3 = new CCMenuItemSprite(spriteNormal, spriteSelected, spriteDisabled, this.menuCallback3);

            m_disabledItem         = item3;
            m_disabledItem.Enabled = false;

            CCMenu menu = new CCMenu(item1, item2, item3);

            menu.Position = new CCPoint(0, 0);

            CCSize s = CCDirector.SharedDirector.WinSize;

            item1.Position = new CCPoint(s.Width / 2 - 150, s.Height / 2);
            item2.Position = new CCPoint(s.Width / 2 - 200, s.Height / 2);
            item3.Position = new CCPoint(s.Width / 2, s.Height / 2 - 100);
            CCJumpBy jump = new CCJumpBy(3, new CCPoint(400, 0), 50, 4);

            item2.RunAction(new CCRepeatForever(
                                (CCActionInterval)(new CCSequence(jump, jump.Reverse()))
                                )
                            );
            CCActionInterval spin1 = new CCRotateBy(3, 360);
            CCActionInterval spin2 = (CCActionInterval)(spin1.Copy());
            CCActionInterval spin3 = (CCActionInterval)(spin1.Copy());

            item1.RunAction(new CCRepeatForever(spin1));
            item2.RunAction(new CCRepeatForever(spin2));
            item3.RunAction(new CCRepeatForever(spin3));

            AddChild(menu);
        }
Exemplo n.º 17
0
        public Layer3()
        {
            CCMenuItemFont.DefaultFontName = "Marker Felt";
            CCMenuItemFont.DefaultFontSize = 28;

            CCLabelBMFont label = new CCLabelBMFont("Enable AtlasItem", "bitmapFontTest3.fnt");
            CCMenuItemLabel item1 = new CCMenuItemLabel(label, this, new MonoMac.ObjCRuntime.Selector("menuCallback2:"));
            CCMenuItemFont item2 = new CCMenuItemFont("--- Go Back ---", this, new MonoMac.ObjCRuntime.Selector("menuCallback:"));

            CCSprite spriteNormal = new CCSprite ("menuitemsprite.png", new RectangleF (0, 23 * 2, 115, 23));
            CCSprite spriteSelected = new CCSprite ("menuitemsprite.png", new RectangleF (0, 23 * 1, 115, 23));
            CCSprite spriteDisabled = new CCSprite ("menuitemsprite.png", new RectangleF (0, 23 * 0, 115, 23));

            CCMenuItemSprite item3 = new CCMenuItemSprite (spriteNormal, spriteSelected, spriteDisabled, this, new MonoMac.ObjCRuntime.Selector("menuCallback3:"));
            disabledItem = item3;
            disabledItem.Enabled = false;

            NSArray arrayOfItems = NSArray.FromObjects(item1, item2, item3);
            CCMenu menu = new CCMenu(arrayOfItems);

            CGSize s = CCDirector.SharedDirector().WinSize ();

            item1.Position = new CCPoint(s.Width/2 - 150, s.Height/2);
            item2.Position = new CCPoint(s.Width/2 - 200, s.Height/2);
            item3.Position = new CCPoint(s.Width/2, s.Height/2 - 100);

            var jump = new CCJumpBy(3, new CCPoint(400,0), 50, 4);
            item2.RunAction (new CCRepeatForever ((CCActionInterval)CCSequence.Actions (jump, jump.Reverse ())));
            var spin1 = new CCRotateBy (3, 360);
            var spin2 = (CCRotateBy)spin1.Copy ();
            var spin3 = (CCRotateBy)spin1.Copy ();

            item1.RunAction (new CCRepeatForever (spin1));
            item2.RunAction (new CCRepeatForever (spin2));
            item3.RunAction (new CCRepeatForever (spin3));

            this.AddChild (menu);
            menu.Position = new CCPoint(0, 0);
        }
Exemplo n.º 18
0
        public BuildingMgr()
        {
            List <CCMenuItemImage> buildingMenuOpts = new List <CCMenuItemImage>();

            this.ownedBuildings = new List <Building>();
            CCMenuItem[] buildingMenuItems = new CCMenuItem[GodClass.BuildingDict.Count];
            int          i = 0;

            foreach (KeyValuePair <string, string> entry in GodClass.BuildingDict)
            {
                JObject buildingJson         = JObject.Parse(entry.Value);
                string  selectableMenuSprite = (string)buildingJson["selectableMenuSprite"];
                string  disabledMenuSprite   = (string)buildingJson["disabledMenuSprite"];
                buildingMenuItems[i] = new CCMenuItemImage(selectableMenuSprite, disabledMenuSprite, GetBuildingAdder(entry.Key));

                i++;
            }
            this.buildingMenu          = new CCMenu(buildingMenuItems);
            this.buildingMenu.Position = new CCPoint(600, 350);
            this.buildingMenu.AlignItemsHorizontally(10);
            GodClass.hudLayer.AddChild(buildingMenu);
        }
Exemplo n.º 19
0
        public TestController()
        {
            // Add close menu
            closeMenuItem = new CCMenuItemImage(TestResource.s_pPathClose, TestResource.s_pPathClose, CloseCallback);
            closeMenu     = new CCMenu(closeMenuItem);

            CCMenuItemFont.FontName = "MarkerFelt";
            CCMenuItemFont.FontSize = 22;


            #if !PSM && !WINDOWS_PHONE
            #if NETFX_CORE
            versionLabel = new CCLabelTtf("v" + this.GetType().GetAssemblyName().Version.ToString(), "arial", 30);
            #else
            versionLabel = new CCLabelTtf("v" + this.GetType().Assembly.GetName().Version.ToString(), "arial", 30);
            #endif
            AddChild(versionLabel, 20000);
            #endif

            // Add test list menu
            testListMenu = new CCMenu();
            for (int i = 0; i < (int)(TestCases.TESTS_COUNT); ++i)
            {
                CCLabelTtf label    = new CCLabelTtf(Tests.g_aTestNames[i], "arial", 50);
                CCMenuItem menuItem = new CCMenuItemLabelTTF(label, MenuCallback);

                testListMenu.AddChild(menuItem, i + MENU_ITEM_Z_ORDER);
                testListMenuItems.Add(menuItem);
            }

            #if XBOX || OUYA
            CCSprite sprite = new CCSprite("Images/aButton");
            AddChild(sprite, 10001);
            menuIndicator = sprite;
            #endif

            AddChild(testListMenu);
            AddChild(closeMenu, 1);
        }
Exemplo n.º 20
0
        public override bool init()
        {
            // always call "super" init
            // Apple recommends to re-assign "self" with the "super" return value
            if (base.init())
            {
                isTouchEnabled = true;
                // ask director the the window size
                CCSize       size = CCDirector.sharedDirector().getWinSize();
                CCLayerColor layer;
                for (int i = 0; i < 5; i++)
                {
                    layer                       = CCLayerColor.layerWithColor(new ccColor4B((byte)(i * 20), (byte)(i * 20), (byte)(i * 20), 255));
                    layer.contentSize           = new CCSize(i * 100, i * 100);
                    layer.position              = new CCPoint(size.width / 2, size.height / 2);
                    layer.anchorPoint           = new CCPoint(0.5f, 0.5f);
                    layer.isRelativeAnchorPoint = true;
                    addChild(layer, -1 - i);
                }

                // create and initialize a Label
                CCLabelTTF label = CCLabelTTF.labelWithString("Hello World", "Marker Felt", 64);
                CCMenuItem item1 = CCMenuItemFont.itemFromString("restart", this, restart);

                CCMenu menu = CCMenu.menuWithItems(item1);
                menu.alignItemsVertically();
                menu.position = new CCPoint(size.width / 2, 100);
                addChild(menu);

                // position the label on the center of the screen
                label.position = new CCPoint(size.width / 2, size.height / 2);

                // add the label as a child to this Layer
                addChild(label);
                return(true);
            }
            return(false);
        }
Exemplo n.º 21
0
        public TestNavigationLayer()
        {
            TitleLabel = new CCLabel(Title, "arial", 32, CCLabelFormat.SpriteFont);
            AddChild(TitleLabel, TestScene.TITLE_LEVEL);

            string subtitleStr = Subtitle;

            if (!string.IsNullOrEmpty(subtitleStr))
            {
                SubtitleLabel                     = new CCLabel(subtitleStr, "arial", 16, CCLabelFormat.SpriteFont);
                SubtitleLabel.AnchorPoint         = CCPoint.AnchorMiddleTop;
                SubtitleLabel.HorizontalAlignment = CCTextAlignment.Center;
                AddChild(SubtitleLabel, TestScene.TITLE_LEVEL);
            }

            backMenuItem    = new CCMenuItemImage(TestResource.s_pPathB1, TestResource.s_pPathB2, BackCallback);
            restartMenuItem = new CCMenuItemImage(TestResource.s_pPathR1, TestResource.s_pPathR2, RestartCallback);
            nextMenuItem    = new CCMenuItemImage(TestResource.s_pPathF1, TestResource.s_pPathF2, NextCallback);

            navigationMenu = new CCMenu(backMenuItem, restartMenuItem, nextMenuItem);

            AddChild(navigationMenu, TestScene.MENU_LEVEL);
        }
Exemplo n.º 22
0
        public TestNavigationLayer()
        {
            TitleLabel             = new CCLabelTtf(Title, "arial", 60);
            TitleLabel.AnchorPoint = new CCPoint(0.5f, 0.5f);
            AddChild(TitleLabel, TestScene.TITLE_LEVEL);

            string subtitleStr = Subtitle;

            if (!string.IsNullOrEmpty(subtitleStr))
            {
                SubtitleLabel             = new CCLabelTtf(subtitleStr, "arial", 30);
                SubtitleLabel.AnchorPoint = new CCPoint(0.5f, 0.5f);
                AddChild(SubtitleLabel, TestScene.TITLE_LEVEL);
            }

            backMenuItem    = new CCMenuItemImage(TestResource.s_pPathB1, TestResource.s_pPathB2, BackCallback);
            restartMenuItem = new CCMenuItemImage(TestResource.s_pPathR1, TestResource.s_pPathR2, RestartCallback);
            nextMenuItem    = new CCMenuItemImage(TestResource.s_pPathF1, TestResource.s_pPathF2, NextCallback);

            navigationMenu = new CCMenu(backMenuItem, restartMenuItem, nextMenuItem);

            AddChild(navigationMenu, TestScene.MENU_LEVEL);
        }
Exemplo n.º 23
0
        public override bool init()
        {
            bool bRet = false;

            do
            {
                if (!base.init())
                {
                    break;
                }
                isTouchEnabled = true;
                CCSize s = CCDirector.sharedDirector().getWinSize();


                CCMenuItem item = CCMenuItemFont.itemFromString("Rotate Device", this, new SEL_MenuHandler(rotateDevice));
                CCMenu     menu = CCMenu.menuWithItems(item);
                menu.position = new CCPoint(s.width / 2, s.height / 2);
                addChild(menu);

                bRet = true;
            } while (false);

            return(bRet);
        }
Exemplo n.º 24
0
        public void menuCallback(CCObject pSender)
        {
            // get the userdata, it's the index of the menu item clicked
            CCMenuItem pMenuItem = (CCMenuItem)(pSender);
            int        nIdx      = pMenuItem.zOrder - 10000;

            switch (nIdx)
            {
            // play background music
            case 0:

                SimpleAudioEngine.sharedEngine().playBackgroundMusic(CCFileUtils.fullPathFromRelativePath(MUSIC_FILE), true);
                break;

            // stop background music
            case 1:
                SimpleAudioEngine.sharedEngine().stopBackgroundMusic();
                break;

            // pause background music
            case 2:
                SimpleAudioEngine.sharedEngine().pauseBackgroundMusic();
                break;

            // resume background music
            case 3:
                SimpleAudioEngine.sharedEngine().resumeBackgroundMusic();
                break;

            // rewind background music
            case 4:
                SimpleAudioEngine.sharedEngine().rewindBackgroundMusic();
                break;

            // is background music playing
            case 5:
                if (SimpleAudioEngine.sharedEngine().isBackgroundMusicPlaying())
                {
                    Debug.WriteLine("background music is playing");
                }
                else
                {
                    Debug.WriteLine("background music is not playing");
                }
                break;

            // play effect
            case 6:
                m_nSoundId = SimpleAudioEngine.sharedEngine().playEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE));
                break;

            // play effect
            case 7:
                m_nSoundId = SimpleAudioEngine.sharedEngine().playEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE), true);
                break;

            // stop effect
            case 8:
                SimpleAudioEngine.sharedEngine().stopEffect(m_nSoundId);
                break;

            // unload effect
            case 9:
                SimpleAudioEngine.sharedEngine().unloadEffect(CCFileUtils.fullPathFromRelativePath(EFFECT_FILE));
                break;

            // add bakcground music volume
            case 10:
                SimpleAudioEngine.sharedEngine().setBackgroundMusicVolume(SimpleAudioEngine.sharedEngine().getBackgroundMusicVolume() + 0.1f);
                break;

            // sub backgroud music volume
            case 11:
                SimpleAudioEngine.sharedEngine().setBackgroundMusicVolume(SimpleAudioEngine.sharedEngine().getBackgroundMusicVolume() - 0.1f);
                break;

            // add effects volume
            case 12:
                SimpleAudioEngine.sharedEngine().setEffectsVolume(SimpleAudioEngine.sharedEngine().getEffectsVolume() + 0.1f);
                break;

            // sub effects volume
            case 13:
                SimpleAudioEngine.sharedEngine().setEffectsVolume(SimpleAudioEngine.sharedEngine().getEffectsVolume() - 0.1f);
                break;
            }
        }
Exemplo n.º 25
0
        void Init()
        {
            var gesture = CCEventListenerGesture.Create();

            gesture.SetSwipeThreshouldDistance(80);
            gesture.OnSwipeEnded = (swipe) =>
            {
                isSwiped = false;
                switch (swipe)
                {
                case CCEventListenerGesture.SwipeDirection.NONE:
                    break;

                case CCEventListenerGesture.SwipeDirection.UP:
                case CCEventListenerGesture.SwipeDirection.DOWN:
                case CCEventListenerGesture.SwipeDirection.LEFT:       //ふぉーるするー
                case CCEventListenerGesture.SwipeDirection.RIGHT:
                    CCLog.Log($"[OreOreLog]:{nameof(TestLayer)}{this.ZOrder}");

                    var goGame = new CCMenuItemLabel(new CCLabel("ゲームであそぶ", "Arial", 40),
                                                     _ =>
                    {
                        ChangeScene(new Loading(new GameAssetsLoader(new GameAssets())));
                        var dig = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog;
                        dig.Close();
                    });


                    var goTitle = new CCMenuItemLabel(new CCLabel("タイトルにもどる", "Arial", 40),
                                                      _ =>
                    {
                        ChangeScene(new Loading(new TitleAssetsLoader()));
                        var dig = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog;
                        dig.Close();
                    });

                    var cancel = new CCMenuItemLabel(new CCLabel("キャンセル", "Arial", 40),
                                                     _ =>
                    {
                        var dig = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog;
                        dig.Close();
                        RemoveChild(dig);
                        isSwiped = false;
                    });
                    var sns_share = new CCMenuItemLabel(new CCLabel("ランキングのシェア", "Arial", 40),
                                                        _ =>
                    {
                        var dig = GetChildByTag(ModalMenuDialog.TAG) as ModalMenuDialog;
                        dig.Close();
                        RemoveChild(dig);

                        void Share(CCLayer layer)
                        {
                            CCRenderTexture rt = new CCRenderTexture(VisibleBoundsWorldspace.Size, VisibleBoundsWorldspace.Size, CCSurfaceFormat.Color, CCDepthFormat.Depth24Stencil8);
                            rt.BeginWithClear(CCColor4B.Black);
                            layer.Visit();
                            rt.End();
                            rt.Sprite.Position           = VisibleBoundsWorldspace.Center;
                            CCRenderCommand shareCommand = new CCCustomCommand(
                                () => {
                                using (MemoryStream ms = new MemoryStream())
                                {
                                    //rt.Texture.SaveAsPng(ms, (int)layer.VisibleBoundsWorldspace.Size.Width, (int)layer.VisibleBoundsWorldspace.Size.Height);
                                    //ShareControl.ShareImage(ms);
                                    rt.SaveToStream(ms, CCImageFormat.Png);
                                    var _share = Xamarin.Forms.DependencyService.Get <IShareSNS>();

                                    string text = "";
                                    if (_rankingData.IsRankinCurrentPlayData)
                                    {
                                        int score = _rankingData.Ranks[_rankingData.RankinIndex].Score;
                                        if (_rankingData.RankinIndex == 0)
                                        {
                                            text = $"わたしのスコア:{score}点" +
                                                   $"\n" +
                                                   $"ハイスコア更新しました!";
                                        }
                                        else
                                        {
                                            text = $"わたしのスコア:{score}点" +
                                                   $"\n" +
                                                   $"ランキング更新しました!";
                                        }
                                    }
                                    else
                                    {
                                        text = "今のランキングです!";
                                    }

                                    string hashTag = "#撃ち続けろ";

                                    text = text + "\n" + hashTag;
                                    _share.Post(text, ms);
                                }
                            });
                            Renderer.AddCommand(shareCommand);
                        }
                        Share(this);
                        isSwiped = false;
                        return;
                    });

                    var menuItems = new[] { goGame, goTitle, sns_share, cancel };

                    var menu = new ModalMenu(menuItems)
                    {
                        Position = new CCPoint(GlobalGameData.Window_Center_X, GlobalGameData.Window_Center_Y - 30),
                    };

                    menu.AlignItemsVertically(30);

                    var dialog = new ModalMenuDialog(menu);

                    AddChild(dialog, 1, ModalMenuDialog.TAG);


                    isSwiped = true;
                    break;

                default:
                    break;
                }
            };
            AddEventListener(gesture, this.Point.First());

            var touch = new CCEventListenerTouchOneByOne();

            touch.OnTouchBegan = (_, __) =>
            {
                foreach (var label in _rankPointsLabel)
                {
                    if (label.Label.BoundingBoxTransformedToWorld.ContainsPoint(_.Location))
                    {
                        selectedMenuItem = label;
                        label.Selected   = true;
                        return(true);
                    }
                }
                return(false);
            };
            touch.OnTouchMoved = (_, __) =>
            {
                CCMenuItem current = null;
                foreach (var label in _rankPointsLabel)
                {
                    if (label.Label.BoundingBoxTransformedToWorld.ContainsPoint(_.Location))
                    {
                        current = label; break;
                    }
                }
                if (current != selectedMenuItem)
                {
                    if (selectedMenuItem != null)
                    {
                        selectedMenuItem.Selected = false;
                    }

                    if (current != null)
                    {
                        current.Selected = true;
                    }
                    selectedMenuItem = current;
                }
            };
            touch.OnTouchEnded = /*EventListener_TouchEnded*/
                                 (_, __) =>
            {
                if (selectedMenuItem != null)
                {
                    selectedMenuItem.Selected = false;
                    selectedMenuItem.Activate();
                }
            };
            AddEventListener(touch, this);

            if (_rankingData.CurrentPlayData != null)
            {
                var currentScoreLabel = new CCLabel($"あなたのスコア:{_rankingData.CurrentPlayData.Score}点", "arial", 20)
                {
                    Position    = new CCPoint(20, GlobalGameData.Window_Height - 20),
                    AnchorPoint = CCPoint.AnchorMiddleLeft
                };
                AddChild(currentScoreLabel);
                if (_rankingData.IsRankinCurrentPlayData)
                {
                    var omedetoLabel = new CCLabel("ランクインおめでとう!", "arial", 20)
                    {
                        Position = new CCPoint(380, GlobalGameData.Window_Height - 20)
                    };
                    AddChild(omedetoLabel);
                }
            }
            systemLabel = new CCLabel("スワイプ:メニューを開く  スコアを選ぶ:リプレイ", "arial", 20)
            {
                Position    = new CCPoint(20, 20),
                AnchorPoint = CCPoint.AnchorMiddleLeft,
                Visible     = false
            };
            AddChild(systemLabel);
        }
Exemplo n.º 26
0
        public MenuTest()
        {
            CCDirector director = CCDirector.SharedDirector ();
            SizeF size = director.WinSize ();
            CCMenu menu = null;

            CCSprite spriteNormal = new CCSprite ("menuitemsprite.png", new RectangleF (0, 23 * 2, 115, 23));
            CCSprite spriteSelected = new CCSprite ("menuitemsprite.png", new RectangleF (0, 23 * 1, 115, 23));
            CCSprite spriteDisabled = new CCSprite ("menuitemsprite.png", new RectangleF (0, 23 * 0, 115, 23));
            CCMenuItemSprite item1 = new CCMenuItemSprite (spriteNormal, spriteSelected, spriteDisabled,
                delegate (NSObject sender) {
                CCScene scene1 = new CCScene ();
                scene1.AddChild (Layer2.Node());
                CCDirector.SharedDirector ().ReplaceScene (scene1);
            });

            CCMenuItemImage item2 = new CCMenuItemImage ("SendScoreButton.png", "SendScoreButtonPressed.png", null, cb);

            CCLabelAtlas labelAtlas = new CCLabelAtlas ("0123456789", "fps_images.png", 12, 32, '.');
            CCMenuItemLabel item3 = new CCMenuItemLabel(labelAtlas,
                delegate (NSObject sender) {
                CCDirector.SharedDirector ().EventDispatcher.AddMouseDelegate (this, -128-1);
                this.Schedule (new MonoMac.ObjCRuntime.Selector ("allowTouches"), 5.0f);
            });

            item3.DisabledColor = new ccColor3B (32, 32, 64);
            item3.Color = new ccColor3B (200, 200, 255);
            disabledItem = item3;

            CCMenuItemFont item4 = new CCMenuItemFont ("I toggle enabled items",
                delegate {
                disabledItem.Enabled = !disabledItem.Enabled;
            }
            );
            item4.FontSize = 20;
            item4.FontName = "Marker Felt";

            CCLabelBMFont label = new CCLabelBMFont ("configuration", "bitmapFontTest3.fnt");
            CCMenuItemLabel item5 = new CCMenuItemLabel (label,
                delegate {
                CCScene scene = new CCScene ();
                scene.AddChild (new Layer4 ());
                CCDirector.SharedDirector ().ReplaceScene (scene);
            });
            item5.Scale = 0.8f;

            CCMenuItemFont.DefaultFontName = "Marker Felt";
            CCMenuItemFont item6 = new CCMenuItemFont ("Priority Test",
                delegate (NSObject sender) {
                CCScene scene = new CCScene();
                scene.AddChild (new LayerPriorityTest());
                CCDirector.SharedDirector ().PushScene (scene);
            });

            CCMenuItemFont.DefaultFontName = "Courier New";
            CCMenuItemFont.DefaultFontSize = 30;
            CCMenuItemFont item7 = new CCMenuItemFont ("Quit",
                delegate {
                director.View.Window.Close ();
            });

            CCTintBy color_action = new CCTintBy(0.5f, 0, -255, -255);
            var color_back = color_action.Reverse ();
            var seq = new CCSequence (color_action, color_back);
            item7.RunAction (new CCRepeatForever (seq));

            menu = new CCMenu (item1, item2, item3, item4, item5, item6, item7);
            menu.AlignItemsVertically ();

            for (uint i = 0; i < menu.Children.Count(); i++) {
                CCNode child = (CCNode)menu.Children.ObjectAtIndex(i);
                PointF dstPoint = child.Position;
                int offset = (int)(size.Width/2) + 50;
                if (i % 2 == 0)
                    offset = -offset;
                child.Position = new PointF(dstPoint.X + offset, dstPoint.Y);
                child.RunAction(new CCEaseElasticOut(
                    new CCMoveBy(2, new PointF(dstPoint.X - offset, 0)), 0.35f));
            }

            menu.Position = new PointF(size.Width/2, size.Height/2);
            this.AddChild(menu);
        }
Exemplo n.º 27
0
        public void menuCallback(object pSender)
        {
            // get the userdata, it's the index of the menu item clicked
            CCMenuItem pMenuItem = (CCMenuItem)(pSender);
            int        nIdx      = pMenuItem.ZOrder - 10000;

            switch (nIdx)
            {
            // play background music
            case 0:

                SimpleAudioEngine.SharedEngine.PlayBackgroundMusic(CCFileUtils.FullPathFromRelativePath(MUSIC_FILE), true);
                break;

            // stop background music
            case 1:
                SimpleAudioEngine.SharedEngine.StopBackgroundMusic();
                break;

            // pause background music
            case 2:
                SimpleAudioEngine.SharedEngine.PauseBackgroundMusic();
                break;

            // resume background music
            case 3:
                SimpleAudioEngine.SharedEngine.ResumeBackgroundMusic();
                break;

            // rewind background music
            case 4:
                SimpleAudioEngine.SharedEngine.RewindBackgroundMusic();
                break;

            // is background music playing
            case 5:
                if (SimpleAudioEngine.SharedEngine.IsBackgroundMusicPlaying())
                {
                    CCLog.Log("background music is playing");
                }
                else
                {
                    CCLog.Log("background music is not playing");
                }
                break;

            // play effect
            case 6:
                m_nSoundId = SimpleAudioEngine.SharedEngine.PlayEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE));
                break;

            // play effect
            case 7:
                m_nSoundId = SimpleAudioEngine.SharedEngine.PlayEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE), true);
                break;

            // stop effect
            case 8:
                SimpleAudioEngine.SharedEngine.StopEffect(m_nSoundId);
                break;

            // unload effect
            case 9:
                SimpleAudioEngine.SharedEngine.UnloadEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE));
                break;

            // add bakcground music volume
            case 10:
                SimpleAudioEngine.SharedEngine.BackgroundMusicVolume = SimpleAudioEngine.SharedEngine.BackgroundMusicVolume + 0.1f;
                break;

            // sub backgroud music volume
            case 11:
                SimpleAudioEngine.SharedEngine.BackgroundMusicVolume = SimpleAudioEngine.SharedEngine.BackgroundMusicVolume - 0.1f;
                break;

            // add effects volume
            case 12:
                SimpleAudioEngine.SharedEngine.EffectsVolume = SimpleAudioEngine.SharedEngine.EffectsVolume + 0.1f;
                break;

            // sub effects volume
            case 13:
                SimpleAudioEngine.SharedEngine.EffectsVolume = SimpleAudioEngine.SharedEngine.EffectsVolume - 0.1f;
                break;
            }
        }
Exemplo n.º 28
0
 /// <summary>
 /// The follow methods offered to lua
 /// creates a menu item with a item
 /// </summary>
 public static CCMenuItemToggle itemWithItem(CCMenuItem item)
 {
     CCMenuItemToggle pRet = new CCMenuItemToggle();
     pRet.initWithItem(item);
     return pRet;
 }
Exemplo n.º 29
0
 /// <summary>
 /// add more menu item
 /// </summary>
 public void addSubItem(CCMenuItem item)
 {
     this.m_pSubItems.Add(item);
 }
Exemplo n.º 30
0
 /// <summary>
 /// initializes a menu item with a item
 /// </summary>
 public bool initWithItem(CCMenuItem item)
 {
     base.initWithTarget(null, null);
     this.m_pSubItems = new List<CCMenuItem>();
     m_pSubItems.Add(item);
     this.SelectedIndex = 0;
     return true;
 }
Exemplo n.º 31
0
        public MenuLayer1()
        {
            CCMenuItemFont.FontSize = 30;
            CCMenuItemFont.FontName = "Arial";
            base.isTouchEnabled     = true;
            // Font Item

            CCSprite spriteNormal   = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 2, 115, 23));
            CCSprite spriteSelected = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 1, 115, 23));
            CCSprite spriteDisabled = CCSprite.spriteWithFile(s_MenuItem, new CCRect(0, 23 * 0, 115, 23));

            CCMenuItemSprite item1 = CCMenuItemSprite.itemFromNormalSprite(spriteNormal, spriteSelected, spriteDisabled, this, this.menuCallback);

            // Image Item
            CCMenuItem item2 = CCMenuItemImage.itemFromNormalImage(s_SendScore, s_PressSendScore, this, this.menuCallback2);

            // Label Item (LabelAtlas)
            CCLabelAtlas    labelAtlas = CCLabelAtlas.labelWithString("0123456789", "Images/fps_images", 16, 24, '.');
            CCMenuItemLabel item3      = CCMenuItemLabel.itemWithLabel(labelAtlas, this, this.menuCallbackDisabled);

            item3.DisabledColor = new ccColor3B(32, 32, 64);
            item3.Color         = new ccColor3B(200, 200, 255);

            // Font Item
            CCMenuItemFont item4 = CCMenuItemFont.itemFromString("I toggle enable items", this, this.menuCallbackEnable);

            item4.FontSizeObj = 20;
            item4.FontNameObj = "Arial";

            // Label Item (CCLabelBMFont)
            CCLabelBMFont   label = CCLabelBMFont.labelWithString("configuration", "fonts/fnt/bitmapFontTest3");
            CCMenuItemLabel item5 = CCMenuItemLabel.itemWithLabel(label, this, this.menuCallbackConfig);


            // Testing issue #500
            item5.scale = 0.8f;

            // Font Item
            CCMenuItemFont item6 = CCMenuItemFont.itemFromString("Quit", this, this.onQuit);

            CCActionInterval   color_action = CCTintBy.actionWithDuration(0.5f, 0, -255, -255);
            CCActionInterval   color_back   = (CCActionInterval)color_action.reverse();
            CCFiniteTimeAction seq          = CCSequence.actions(color_action, color_back);

            item6.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq));

            CCMenu menu = CCMenu.menuWithItems(item1, item2, item3, item4, item5, item6);

            menu.alignItemsVertically();

            // elastic effect
            CCSize        s = CCDirector.sharedDirector().getWinSize();
            int           i = 0;
            CCNode        child;
            List <CCNode> pArray  = menu.children;
            CCObject      pObject = null;

            if (pArray.Count > 0)
            {
                for (int j = 0; j < pArray.Count; j++)
                {
                    pObject = pArray[j];
                    if (pObject == null)
                    {
                        break;
                    }
                    child = (CCNode)pObject;
                    CCPoint dstPoint = child.position;
                    int     offset   = (int)(s.width / 2 + 50);
                    if (i % 2 == 0)
                    {
                        offset = -offset;
                    }

                    child.position = new CCPoint(dstPoint.x + offset, dstPoint.y);
                    child.runAction(CCEaseElasticOut.actionWithAction(CCMoveBy.actionWithDuration(2, new CCPoint(dstPoint.x - offset, 0)), 0.35f));
                    i++;
                }
            }
            m_disabledItem         = item3;
            m_disabledItem.Enabled = false;

            addChild(menu);
        }
Exemplo n.º 32
0
        /// <summary>
        /// initializes a menu item from a list of items with a target selector
        /// </summary>
        public bool initWithTarget(SelectorProtocol target, SEL_MenuHandler selector, CCMenuItem[] items)
        {
            base.initWithTarget(target, selector);
            this.m_pSubItems = new List<CCMenuItem>();
            foreach (var item in items)
            {
                m_pSubItems.Add(item);
            }

            this.SelectedIndex = 0;
            return true;
        }