Exemple #1
0
        public MenuLayer1()
        {

			// Register Touch Event
			touchListener = new CCEventListenerTouchOneByOne();
			touchListener.IsSwallowTouches = true;

			touchListener.OnTouchBegan = onTouchBegan;
			touchListener.OnTouchMoved = onTouchMoved;
			touchListener.OnTouchEnded = onTouchEnded;
			touchListener.OnTouchCancelled = onTouchCancelled;

			AddEventListener(touchListener, 1);

			// 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.
			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));


            var item1 = new CCMenuItemImage(spriteNormal, spriteSelected, spriteDisabled, this.menuCallback);

            // Image Item
            var item2 = new CCMenuItemImage(s_SendScore, s_PressSendScore, this.menuCallback2);

            // Label Item (LabelAtlas)
            var labelAtlas = new CCLabelAtlas("0123456789", "Images/fps_Images.png", 12, 32, '.');
            var item3 = new CCMenuItemLabelAtlas(labelAtlas, this.menuCallbackDisabled);
            item3.DisabledColor = new CCColor3B(32, 32, 64);
            item3.Color = new CCColor3B(200, 200, 255);

            // Font Item
			CCMenuItemFont item4 = new CCMenuItemFont("I toggle enable items", (sender) => 
				{
					disabledItem.Enabled = !disabledItem.Enabled;

				});

            // Label Item (CCLabelBMFont)
            CCLabelBMFont label = new CCLabelBMFont("configuration", "fonts/bitmapFontTest3.fnt");
            CCMenuItemLabelBMFont item5 = new CCMenuItemLabelBMFont(label, this.menuCallbackConfig);


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

			CCMenuItemFont.FontSize = 30;
            // Events
            CCMenuItemFont item6 = new CCMenuItemFont("Priority Test", menuCallbackPriorityTest);

            // Font Item
			CCMenuItemFont item7 = new CCMenuItemFont("Quit", this.onQuit);
			item7.RepeatForever(color_action, color_action.Reverse());

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

            disabledItem = item3;
            disabledItem.Enabled = false;

            AddChild(menu);
			menu.Scale = 0;
			menu.RunAction(new CCScaleTo(1, 1));
        }
Exemple #2
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            // 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 item1 = new CCMenuItemImage(spriteNormal, spriteSelected, spriteDisabled, this.menuCallback);

            // Image Item
            var item2 = new CCMenuItemImage(s_SendScore, s_PressSendScore, this.menuCallback2);

            // Label Item (LabelAtlas)
            var labelAtlas = new CCLabelAtlas("0123456789", "Images/fps_Images.png", 12, 32, '.');
            var item3 = new CCMenuItemLabelAtlas(labelAtlas, this.menuCallbackDisabled);
            item3.DisabledColor = new CCColor3B(32, 32, 64);
            item3.Color = new CCColor3B(200, 200, 255);

            // Font Item
            var item4 = new CCMenuItemFont("I toggle enable items", (sender) => 
                {
                    disabledItem.Enabled = !disabledItem.Enabled;

                });

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


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

            CCMenuItemFont.FontSize = 30;
            // Events
            var item6 = new CCMenuItemFont("Priority Test", menuCallbackPriorityTest);

            // Font Item
            var item7 = new CCMenuItemFont("Quit", this.onQuit);
            item7.RepeatForever(color_action, color_action.Reverse());

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

            disabledItem = item3;
            disabledItem.Enabled = false;

            AddChild(menu);
            menu.Scale = 0;
            menu.RunAction(new CCScaleTo(1, 1));

			// elastic effect
            var s = Layer.VisibleBoundsWorldspace.Size;

			int i = 0;
			CCNode child;
			var pArray = menu.Children;
			object 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(new CCEaseElasticOut(new CCMoveBy(2, new CCPoint(dstPoint.X - offset, 0)), 0.35f));
					i++;

				}
			}
		}