public MenuLayerPriorityTest() { // Testing empty menu m_pMenu1 = new CCMenu(); m_pMenu2 = new CCMenu(); // Menu 1 CCMenuItemFont item1 = new CCMenuItemFont("Return to Main Menu", menuCallback); CCMenuItemFont item2 = new CCMenuItemFont("Disable menu for 5 seconds", disableMenuCallback); m_pMenu1.AddChild(item1); m_pMenu1.AddChild(item2); m_pMenu1.AlignItemsVertically(2); AddChild(m_pMenu1); // Menu 2 m_bPriority = true; //CCMenuItemFont.setFontSize(48); item1 = new CCMenuItemFont("Toggle priority", togglePriorityCallback); item1.Scale = 1.5f; item1.Color = new CCColor3B(0, 0, 255); m_pMenu2.AddChild(item1); AddChild(m_pMenu2); }
private bool InitTableViewTestLayer() { var winSize = Layer.VisibleBoundsWorldspace.Size; var tableView = new CCTableView(this, new CCSize(250, 60)); tableView.Direction = CCScrollViewDirection.Horizontal; tableView.Position = new CCPoint(20, winSize.Height / 2 - 30); tableView.Delegate = this; this.AddChild(tableView); tableView.ReloadData(); tableView = new CCTableView(this, new CCSize(60, 280)); tableView.Direction = CCScrollViewDirection.Vertical; tableView.Position = new CCPoint(winSize.Width - 150, winSize.Height / 2 - 120); tableView.Delegate = this; tableView.VerticalFillOrder = CCTableViewVerticalFillOrder.FillTopDown; this.AddChild(tableView); tableView.ReloadData(); // Back Menu var itemBack = new CCMenuItemFont("Back", toExtensionsMainLayer); itemBack.Position = new CCPoint(winSize.Width - 50, 25); var menuBack = new CCMenu(itemBack); menuBack.Position = CCPoint.Zero; AddChild(menuBack); return true; }
public override void OnEnter() { base.OnEnter(); // Testing empty menu menu1 = new CCMenu(); menu2 = new CCMenu(); // Menu 1 var item1 = new CCMenuItemFont("Return to Main Menu", menuCallback); var item2 = new CCMenuItemFont("Disable menu for 5 seconds", disableMenuCallback); menu1.AddChild(item1); menu1.AddChild(item2); menu1.AlignItemsVertically(2); AddChild(menu1); // Menu 2 priority = true; //CCMenuItemFont.setFontSize(48); item1 = new CCMenuItemFont("Toggle priority", togglePriorityCallback); item1.Scale = 1.5f; item1.Color = new CCColor3B(0, 0, 255); menu2.AddChild(item1); AddChild(menu2); }
public void reset() { 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); CCLog.Log("Menu: %p", node); RemoveChild(node, false); // [self removeChildByTag:localtag-1 cleanup:NO]; CCMenuItem item1 = new CCMenuItemFont("One", menuCallback); CCLog.Log("MenuItemFont: %p", item1); CCMenuItem item2 = new CCMenuItemFont("Two", menuCallback); CCMenu menu = new CCMenu(item1, item2); menu.AlignItemsVertically(); float x = CCRandom.Next() * 50; float y = CCRandom.Next() * 50; menu.Position = menu.Position + new CCPoint(x, y); AddChild(menu, 0, localtag); //[self check:self]; }
public override void OnEnter() { base.OnEnter(); var s = Layer.VisibleBoundsWorldspace.Size; CCMenuItemFont.FontSize = 24; CCMenuItemFont.FontName = "arial"; var pMainItem = new CCMenuItemFont("Back", toMainLayer); pMainItem.Position = new CCPoint(s.Width - 50, 25); var pMenu = new CCMenu(pMainItem); pMenu.Position = new CCPoint(0, 0); if (m_bControlMenuVisible) { var item1 = new CCMenuItemImage("Images/b1", "Images/b2", backCallback); var item2 = new CCMenuItemImage("Images/r1", "Images/r2", restartCallback); var item3 = new CCMenuItemImage("Images/f1", "Images/f2", nextCallback); item1.Position = new CCPoint(s.Width / 2 - 100, 30); item2.Position = new CCPoint(s.Width / 2, 30); item3.Position = new CCPoint(s.Width / 2 + 100, 30); pMenu.AddChild(item1, PerformanceTestScene.kItemTagBasic); pMenu.AddChild(item2, PerformanceTestScene.kItemTagBasic); pMenu.AddChild(item3, PerformanceTestScene.kItemTagBasic); } AddChild(pMenu); }
public IntervalLayer() { m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f; CCSize s = Layer.VisibleBoundsWorldspace.Size; // sun CCParticleSystem sun = new CCParticleSun(new CCPoint(s.Width / 2, s.Height / 2)); sun.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire"); sun.Position = (new CCPoint(s.Width - 32, s.Height - 32)); sun.TotalParticles = 130; sun.Life = (0.6f); AddChild(sun); // timers m_label0 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt"); m_label1 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt"); m_label2 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt"); m_label3 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt"); m_label4 = new CCLabelBMFont("0", "fonts/bitmapFontTest4.fnt"); Schedule (); Schedule(step1); Schedule(step2, 0); Schedule(step3, 1.0f); Schedule(step4, 2.0f); m_label0.Position = new CCPoint(s.Width * 1 / 6, s.Height / 2); 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 = new CCSprite(s_pPathGrossini); sprite.Position = new CCPoint(40, 50); CCJumpBy jump = new CCJumpBy (3, new CCPoint(s.Width - 80, 0), 50, 4); AddChild(sprite); sprite.RunAction(new CCRepeatForever ( (CCFiniteTimeAction) (new CCSequence(jump, jump.Reverse()))) ); // pause button CCMenuItem item1 = new CCMenuItemFont("Pause", onPause); CCMenu menu = new CCMenu(item1); menu.Position = new CCPoint(s.Width / 2, s.Height - 50); AddChild(menu); }
public override void OnEnter() { base.OnEnter(); CCSize s = Layer.VisibleBoundsWorldspace.Size; CCMenuItemFont pMainItem = new CCMenuItemFont("Back", backCallback); pMainItem.Position = new CCPoint(s.Width - 50, 25); CCMenu pMenu = new CCMenu(pMainItem, null); pMenu.Position = new CCPoint(0, 0); AddChild(pMenu); }
public virtual void initWithQuantityOfNodes(int nNodes) { //srand(time()); CCSize s = Layer.VisibleBoundsWorldspace.Size; // Title var label = new CCLabel(title(), "arial", 32, CCLabelFormat.SpriteFont); AddChild(label, 1); label.Position = new CCPoint(s.Width / 2, s.Height - 32); label.Color = new CCColor3B(255, 255, 40); // Subtitle string strSubTitle = subtitle(); if (strSubTitle.Length > 0) { var l = new CCLabel(strSubTitle, "arial", 16, CCLabelFormat.SpriteFont); AddChild(l, 1); l.Position = new CCPoint(s.Width / 2, s.Height - 80); } lastRenderedCount = 0; currentQuantityOfNodes = 0; quantityOfNodes = nNodes; CCMenuItemFont.FontSize = 64; CCMenuItemFont.FontName = "arial"; CCMenuItemFont decrease = new CCMenuItemFont(" - ", onDecrease); decrease.Color = new CCColor3B(0, 200, 20); CCMenuItemFont increase = new CCMenuItemFont(" + ", onIncrease); increase.Color = new CCColor3B(0, 200, 20); CCMenu menu = new CCMenu(decrease, increase); menu.AlignItemsHorizontally(); menu.Position = new CCPoint(s.Width / 2, s.Height / 2 + 15); AddChild(menu, 1); var infoLabel = new CCLabel("0 nodes", "arial", 30, CCLabelFormat.SpriteFont); infoLabel.Color = new CCColor3B(0, 200, 20); infoLabel.Position = new CCPoint(s.Width / 2, s.Height / 2 - 15); AddChild(infoLabel, 1, PerformanceNodeChildrenTest.kTagInfoLayer); NodeChildrenMenuLayer pMenu = new NodeChildrenMenuLayer(true, PerformanceNodeChildrenTest.TEST_COUNT, PerformanceNodeChildrenTest.s_nCurCase); AddChild(pMenu); updateQuantityLabel(); updateQuantityOfNodes(); }
public SceneTestLayer1() { CCMenuItemFont item1 = new CCMenuItemFont("(1) Test PushScene", onPushScene); CCMenuItemFont item2 = new CCMenuItemFont("(1) Test PushScene w/Transition", onPushSceneTran); CCMenuItemFont item3 = new CCMenuItemFont("(1) Quit", onQuit); popMenuItem = new CCMenuItemFont("(1) Test PopScene w/Transition", onPopSceneTran); theMenu = new CCMenu(item1, item2, item3, popMenuItem); theMenu.AlignItemsVertically(); AddChild(theMenu); CCSprite sprite = new CCSprite(SceneTestScene.grossini) { Tag = SceneTestScene.GROSSINI_TAG }; AddChild(sprite); }
public SceneTestLayer3() : base(new CCColor4B(0, 0, 255, 255)) { var item0 = new CCMenuItemFont("(3) Touch to pushScene (self)", item0Clicked); var item1 = new CCMenuItemFont("(3) Touch to popScene", item1Clicked); var item2 = new CCMenuItemFont("(3) Touch to popToRootScene", item2Clicked); var item3 = new CCMenuItemFont("(3) Touch to popToSceneStackLevel(2)", item3Clicked); CCMenu menu = new CCMenu(item0, item1, item2, item3); menu.AlignItemsVertically(); AddChild(menu); CCSprite sprite = new CCSprite(SceneTestScene.grossini) { Tag = SceneTestScene.GROSSINI_TAG}; AddChild(sprite); }
public CCControlScene() { // Get the screensize CCSize screensize = Layer.VisibleBoundsWorldspace.Size; var pBackItem = new CCMenuItemFont("Back", toExtensionsMainLayer); pBackItem.Position = new CCPoint(screensize.Width - 50, 25); var pBackMenu = new CCMenu(pBackItem); pBackMenu.Position = CCPoint.Zero; AddChild(pBackMenu, 10); // Add the generated background var background = new CCSprite("extensions/background"); background.Position = new CCPoint(screensize.Width / 2, screensize.Height / 2); AddChild(background); // Add the ribbon var ribbon = new CCScale9SpriteFile("extensions/ribbon", new CCRect(1, 1, 48, 55)); ribbon.ContentSize = new CCSize(screensize.Width, 57); ribbon.Position = new CCPoint(screensize.Width / 2.0f, screensize.Height - ribbon.ContentSize.Height / 2.0f); AddChild(ribbon); // Add the title setSceneTitleLabel(new CCLabelTtf(" ", "Arial", 12)); m_pSceneTitleLabel.Position = new CCPoint(screensize.Width / 2, screensize.Height - m_pSceneTitleLabel.ContentSize.Height / 2 - 5); AddChild(m_pSceneTitleLabel, 1); // Add the subtitle setSceneSubtitleLabel(new CCLabelTtf(" ", "Arial", 12)); m_pSceneSubtitleLabel.Position = new CCPoint(screensize.Width / 2, screensize.Height - m_pSceneTitleLabel.ContentSize.Height - m_pSceneSubtitleLabel.ContentSize.Height / 2 - 10); AddChild(m_pSceneSubtitleLabel, 1); // Add the menu var item1 = new CCMenuItemImage("Images/b1", "Images/b2", previousCallback); var item2 = new CCMenuItemImage("Images/r1", "Images/r2", restartCallback); var item3 = new CCMenuItemImage("Images/f1", "Images/f2", nextCallback); var menu = new CCMenu(item1, item3, item2); menu.Position = CCPoint.Zero; item1.Position = new CCPoint(screensize.Width / 2 - 100, 37); item2.Position = new CCPoint(screensize.Width / 2, 35); item3.Position = new CCPoint(screensize.Width / 2 + 100, 37); AddChild(menu, 1); }
public SceneTestLayer2() { m_timeCounter = 0; CCMenuItemFont item1 = new CCMenuItemFont("(2) replaceScene", onReplaceScene); CCMenuItemFont item2 = new CCMenuItemFont("(2) replaceScene w/transition", onReplaceSceneTran); CCMenuItemFont item3 = new CCMenuItemFont("(2) Go Back", onGoBack); popMenuItem = new CCMenuItemFont("(2) Test popScene w/transition", onPopSceneTran); theMenu = new CCMenu(item1, item2, item3, popMenuItem); theMenu.AlignItemsVertically(); AddChild(theMenu); CCSprite sprite = new CCSprite(SceneTestScene.grossini) { Tag = SceneTestScene.GROSSINI_TAG }; AddChild(sprite); }
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); }
public override void OnEnter() { base.OnEnter(); var s = Layer.VisibleBoundsWorldspace.Size; var pMenu = new CCMenu(); pMenu.Position = CCPoint.Zero; CCMenuItemFont.FontSize = 24; CCMenuItemFont.FontName = "arial"; for (int i = 0; i < ExtensionsTestScene.TEST_MAX_COUNT; ++i) { var pItem = new CCMenuItemFont(ExtensionsTestScene.testsName[i], menuCallback); pItem.Position = new CCPoint(s.Width / 2, s.Height - (i + 1) * ExtensionsTestScene.LINE_SPACE); pMenu.AddChild(pItem, ExtensionsTestScene.kItemTagBasic + i); } AddChild(pMenu); }
public Bug914Layer() { // always call "super" init // Apple recommends to re-assign "self" with the "super" return value // Register Touch Event var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesBegan = onTouchesBegan; touchListener.OnTouchesMoved = onTouchesMoved; AddEventListener(touchListener); // ask director the the window size CCSize size = Layer.VisibleBoundsWorldspace.Size; CCLayerColor layer; for (int i = 0; i < 5; i++) { layer = new CCLayerColor(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.IgnoreAnchorPointForPosition = true; AddChild(layer, -1 - i); } // create and initialize a Label var label = new CCLabel("Hello World", "Marker Felt", 64, CCLabelFormat.SpriteFont); CCMenuItem item1 = new CCMenuItemFont("restart", restart); CCMenu menu = new CCMenu(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); }
public RenderTextureSave() { // create a brush image to draw into the texture with brush = new CCSprite("Images/fire"); // It's possible to modify the Brushes blending function by CCBlendFunc bbf = new CCBlendFunc (CCOGLES.GL_ONE, CCOGLES.GL_ONE_MINUS_SRC_ALPHA); brush.BlendFunc = bbf; brush.Color = CCColor3B.Red; brush.Opacity = 20; // Save image menu CCMenuItemFont.FontSize = 16; CCMenuItemFont.FontName = "arial"; CCMenuItem item1 = new CCMenuItemFont("Save Image", SaveImage); CCMenuItem item2 = new CCMenuItemFont("Clear", ClearImage); saveImageMenu = new CCMenu(item1, item2); AddChild(saveImageMenu); }
public RenderTextureDrawNode() { canvasNode = new CCDrawNode(); AddChild(canvasNode); // Save image menu CCMenuItemFont.FontSize = 16; CCMenuItemFont.FontName = "arial"; CCMenuItem item1 = new CCMenuItemFont("Save Image", SaveImage); CCMenuItem item2 = new CCMenuItemFont("Clear", ClearImage); saveImageMenu = new CCMenu(item1, item2); AddChild(saveImageMenu); // Register for touch events var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesEnded = OnTouchesEnded; touchListener.OnTouchesBegan = OnTouchesBegan; touchListener.OnTouchesMoved = OnTouchesMoved; AddEventListener(touchListener, this); }
public override void OnEnter() { base.OnEnter(); CCSize s = Layer.VisibleBoundsWorldspace.Size; CCMenu pMenu = new CCMenu(null); pMenu.Position = new CCPoint(0, 0); CCMenuItemFont.FontSize = 18; CCMenuItemFont.FontName = "arial"; for (int i = 0; i < PerformanceTestScene.MAX_COUNT; ++i) { CCMenuItemFont pItem = new CCMenuItemFont(PerformanceTestScene.testsName[i], menuCallback); pItem.Position = new CCPoint(s.Width / 2, s.Height - (i + 1) * PerformanceTestScene.LINE_SPACE); pMenu.AddChild(pItem, PerformanceTestScene.kItemTagBasic + i); } AddChild(pMenu); }
public override void OnEnter() { base.OnEnter(); CCSize s = Layer.VisibleBoundsWorldspace.Size; m_pItmeMenu = new CCMenu(null); for (int i = 0; i < BugsTestScene.MAX_COUNT; ++i) { CCMenuItemFont pItem = new CCMenuItemFont(BugsTestScene.testsName[i], menuCallback); pItem.Position = new CCPoint(s.Width / 2, s.Height - (i + 1) * BugsTestScene.LINE_SPACE); m_pItmeMenu.AddChild(pItem, BugsTestScene.kItemTagBasic + i); } m_pItmeMenu.Position = BugsTestScene.s_tCurPos; AddChild(m_pItmeMenu); // Register Touch Event var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesBegan = onTouchesBegan; touchListener.OnTouchesMoved = onTouchesMoved; AddEventListener(touchListener); }
public MenuLayer4() { CCMenuItemFont.FontSize = 18; CCMenuItemFont.FontName = "arial"; CCMenuItemFont title1 = new CCMenuItemFont("Sound"); title1.Enabled = false; CCMenuItemFont.FontSize = 34; CCMenuItemToggle item1 = new CCMenuItemToggle(this.menuCallback, new CCMenuItemFont("On"), new CCMenuItemFont("Off")); CCMenuItemFont.FontSize = 18; CCMenuItemFont title2 = new CCMenuItemFont("Music"); title2.Enabled = false; CCMenuItemFont.FontSize = 34; CCMenuItemToggle item2 = new CCMenuItemToggle(this.menuCallback, new CCMenuItemFont("On"), new CCMenuItemFont("Off")); CCMenuItemFont.FontSize = 18; CCMenuItemFont title3 = new CCMenuItemFont("Quality"); title3.Enabled = false; CCMenuItemFont.FontSize = 34; CCMenuItemToggle item3 = new CCMenuItemToggle(this.menuCallback, new CCMenuItemFont("High"), new CCMenuItemFont("Low")); CCMenuItemFont.FontSize = 18; CCMenuItemFont title4 = new CCMenuItemFont("Orientation"); title4.Enabled = false; CCMenuItemFont.FontSize = 34; CCMenuItemToggle item4 = new CCMenuItemToggle(this.menuCallback, new CCMenuItemFont("Off")); item4.AddToggleMenuItems(new CCMenuItemFont ("33%"), new CCMenuItemFont ("66%"), new CCMenuItemFont ("100%")); // you can change the one of the items by doing this item4.SelectedIndex = 2; CCLabelBMFont label = new CCLabelBMFont("go back", "fonts/bitmapFontTest3.fnt"); CCMenuItemLabelBMFont back = new CCMenuItemLabelBMFont(label, this.backCallback); CCMenu menu = new CCMenu( title1, title2, item1, item2, title3, title4, item3, item4, back) { Tag = 36 }; // 9 items. menu.AlignItemsInColumns(2, 2, 2, 2, 1); AddChild(menu); }
public void initWithSubTest(int asubtest, int nNodes) { //srandom(0); subtestNumber = asubtest; m_pSubTest = new SubTest(); m_pSubTest.initWithSubTest(asubtest, this); CCSize s = Layer.VisibleBoundsWorldspace.Size; lastRenderedCount = 0; quantityNodes = 0; CCMenuItemFont.FontSize = 64; CCMenuItemFont.FontName = "arial"; CCMenuItemFont decrease = new CCMenuItemFont(" - ", onDecrease); decrease.Color = new CCColor3B(0, 200, 20); CCMenuItemFont increase = new CCMenuItemFont(" + ", onIncrease); increase.Color = new CCColor3B(0, 200, 20); CCMenu menu = new CCMenu(decrease, increase); menu.AlignItemsHorizontally(); menu.Position = new CCPoint(s.Width / 2, s.Height - 65); AddChild(menu, 1); CCLabelTtf infoLabel = new CCLabelTtf("0 nodes", "Marker Felt", 30); infoLabel.Color = new CCColor3B(0, 200, 20); infoLabel.Position = new CCPoint(s.Width / 2, s.Height - 90); AddChild(infoLabel, 1, PerformanceSpriteTest.kTagInfoLayer); // add menu SpriteMenuLayer pMenu = new SpriteMenuLayer(true, PerformanceSpriteTest.TEST_COUNT, PerformanceSpriteTest.s_nSpriteCurCase); AddChild(pMenu, 1, PerformanceSpriteTest.kTagMenuLayer); // Sub Tests CCMenuItemFont.FontSize = 32; CCMenuItemFont.FontName = "arial"; CCMenu pSubMenu = new CCMenu(null); for (int i = 1; i <= 9; ++i) { //char str[10] = {0}; var str = string.Format("{0}", i); CCMenuItemFont itemFont = new CCMenuItemFont(str, testNCallback); itemFont.Tag = i; pSubMenu.AddChild(itemFont, 10); if (i <= 3) itemFont.Color = new CCColor3B(200, 20, 20); else if (i <= 6) itemFont.Color = new CCColor3B(0, 200, 20); else itemFont.Color = new CCColor3B(0, 20, 200); } pSubMenu.AlignItemsHorizontally(); pSubMenu.Position = new CCPoint(s.Width / 2, 80); AddChild(pSubMenu, 2); // add title label CCLabelTtf label = new CCLabelTtf(title(), "arial", 38); AddChild(label, 1); label.Position = new CCPoint(s.Width / 2, s.Height - 32); label.Color = new CCColor3B(255, 255, 40); while (quantityNodes < nNodes) onIncrease(this); }
protected override void AddedToScene() { base.AddedToScene(); // ask director the the window size var size = VisibleBoundsWorldspace.Size; // create and initialize a Label label = new CCLabel(LongSentencesExample, "fonts/markerFelt.fnt", new CCSize(size.Width / 3f, 0), CCTextAlignment.Center); //label.LineBreakWithoutSpace = true; arrowsBar = new CCSprite("Images/arrowsBar"); arrows = new CCSprite("Images/arrows"); CCMenuItemFont.FontSize = 20; CCMenuItemFont.FontName = "arial"; var longSentences = new CCMenuItemFont("Long Flowing Sentences", stringChanged); var lineBreaks = new CCMenuItemFont("Short Sentences With Intentional Line Breaks", stringChanged); var mixed = new CCMenuItemFont("Long Sentences Mixed With Intentional Line Breaks", stringChanged); var stringMenu = new CCMenu(longSentences, lineBreaks, mixed); stringMenu.AlignItemsVertically(); longSentences.Color = CCColor3B.Red; lastSentenceItem = longSentences; longSentences.Tag = LongSentences; lineBreaks.Tag = LineBreaks; mixed.Tag = Mixed; CCMenuItemFont.FontSize = 30; var left = new CCMenuItemFont("Left", alignmentChanged); var center = new CCMenuItemFont("Center", alignmentChanged); var right = new CCMenuItemFont("Right", alignmentChanged); var alignmentMenu = new CCMenu(left, center, right); alignmentMenu.AlignItemsHorizontally(alignmentItemPadding); center.Color = CCColor3B.Red; lastAlignmentItem = center; left.Tag = LeftAlign; center.Tag = CenterAlign; right.Tag = RightAlign; // position the label on the center of the screen label.Position = size.Center; arrowsBar.Visible = false; float arrowsWidth = (ArrowsMax - ArrowsMin) * size.Width; arrowsBar.ScaleX = (arrowsWidth / arrowsBar.ContentSize.Width); arrowsBar.Position = new CCPoint(((ArrowsMax + ArrowsMin) / 2) * size.Width, label.Position.Y); snapArrowsToEdge(); stringMenu.Position = new CCPoint(size.Width / 2, size.Height - menuItemPaddingCenter); alignmentMenu.Position = new CCPoint(size.Width / 2, menuItemPaddingCenter + 15); AddChild(label); AddChild(arrowsBar); AddChild(arrows); AddChild(stringMenu); AddChild(alignmentMenu); }
private void alignmentChanged(object sender) { var item = (CCMenuItemFont) sender; item.Color = CCColor3B.Red; lastAlignmentItem.Color = CCColor3B.White; lastAlignmentItem = item; switch (item.Tag) { case LeftAlign: label.HorizontalAlignment = CCTextAlignment.Left; break; case CenterAlign: label.HorizontalAlignment = CCTextAlignment.Center; break; case RightAlign: label.HorizontalAlignment = CCTextAlignment.Right; break; default: break; } snapArrowsToEdge(); }
private void stringChanged(object sender) { var item = (CCMenuItemFont) sender; item.Color = CCColor3B.Red; lastAlignmentItem.Color = CCColor3B.White; lastAlignmentItem = item; switch (item.Tag) { case LongSentences: label.Text = LongSentencesExample; break; case LineBreaks: label.Text = LineBreaksExample; break; case Mixed: label.Text = MixedExample; break; default: break; } snapArrowsToEdge(); }
public override void OnEnter () { CCRect visibleBounds = Layer.VisibleBoundsWorldspace; base.OnEnter (); var item1 = new CCMenuItemFont("Click Me 1", (sender) => { var listener = new CCEventListenerTouchOneByOne(); listener.OnTouchBegan = (touch, touchEvent) => { Debug.Assert(false, "Should not come here!"); return true; }; AddEventListener(listener, -1); RemoveEventListener(listener); }); item1.Position = visibleBounds.Center + new CCPoint(0, 80); var addNextButton = new Action( () => { var next = new CCMenuItemFont("Please Click Me To Reset!", (sender) => { RestartCallback(null); }); next.Position = visibleBounds.Center + new CCPoint(0, -40); var menuNext = new CCMenu(next); menuNext.Position = visibleBounds.Origin; menuNext.AnchorPoint = CCPoint.Zero; AddChild(menuNext); }); var item2 = new CCMenuItemFont ("Click Me 2", (sender) => { var listener = new CCEventListenerTouchOneByOne (); listener.OnTouchBegan = (touch, touchEvent) => { Debug.Assert (false, "Should not come here!"); return true; }; AddEventListener(listener, -1); RemoveEventListeners(CCEventListenerType.TOUCH_ONE_BY_ONE); addNextButton (); }); item2.Position = visibleBounds.Center + new CCPoint(0, 40); var item3 = new CCMenuItemFont("Click Me 3", (sender) => { var listener = new CCEventListenerTouchOneByOne (); listener.OnTouchBegan = (touch, touchEvent) => { Debug.Assert (false, "Should not come here!"); return true; }; AddEventListener(listener, -1); RemoveEventListeners(CCEventListenerType.TOUCH_ONE_BY_ONE); addNextButton(); }); item3.Position = visibleBounds.Center; var menu = new CCMenu(item1, item2, item3); menu.Position = visibleBounds.Origin; menu.AnchorPoint = CCPoint.Zero; AddChild(menu); }
public override void OnEnter () { base.OnEnter (); var origin = Layer.VisibleBoundsWorldspace.Origin; var size = Layer.VisibleBoundsWorldspace.Size; //MenuItemFont::setFontSize(20); var statusLabel = new CCLabelTtf("No custom event 1 received!", "", 20); statusLabel.Position = origin + new CCPoint(size.Width/2, size.Height-90); AddChild(statusLabel); listener = new CCEventListenerCustom("game_custom_event1", (customEvent) => { var str = "Custom event 1 received, "; var buf = customEvent.UserData; str += buf; str += " times"; statusLabel.Text = str; }); AddEventListener(listener, 1); var count = 0; var sendItem = new CCMenuItemFont("Send Custom Event 1", (sender) => { ++count; var userData = string.Format("{0}", count); DispatchEvent("game_custom_event1",userData); }); sendItem.Position = origin + size.Center; var statusLabel2 = new CCLabelTtf("No custom event 2 received!", "", 20); statusLabel2.Position = origin + new CCPoint(size.Width/2, size.Height-120); AddChild(statusLabel2); listener2 = new CCEventListenerCustom("game_custom_event2", (customEvent) => { statusLabel2.Text = string.Format("Custom event 2 received, {0} times", customEvent.UserData); }); AddEventListener(listener2, 1); var count2 = 0; var sendItem2 = new CCMenuItemFont("Send Custom Event 2", (sender) => { var customEvent = new CCEventCustom("game_custom_event2"); customEvent.UserData = ++count2; DispatchEvent(customEvent); }); sendItem2.Position = origin + new CCPoint(size.Width / 2, size.Height / 2 - 40); var menu = new CCMenu(sendItem, sendItem2); menu.Position = CCPoint.Zero; menu.AnchorPoint = CCPoint.AnchorUpperLeft; AddChild(menu, -1); }
public override void OnEnter () { base.OnEnter (); CCRect visibleBounds = Layer.VisibleBoundsWorldspace; var origin = Layer.VisibleBoundsWorldspace.Origin; var size = Layer.VisibleBoundsWorldspace.Size; var sprite1 = new CCSprite("Images/CyanSquare.png"); sprite1.Position = origin + new CCPoint (size.Width / 2, size.Height / 2) + new CCPoint (-80, 80); AddChild(sprite1, 10); var sprite2 = new CCSprite("Images/MagentaSquare.png"); sprite2.Position = origin + new CCPoint (size.Width / 2, size.Height / 2); AddChild(sprite2, 20); var sprite3 = new CCSprite("Images/YellowSquare.png"); sprite3.Position = CCPoint.Zero; sprite2.AddChild(sprite3, 1); // Make sprite1 touchable var listener1 = new CCEventListenerTouchOneByOne (); listener1.IsSwallowTouches = true; listener1.OnTouchBegan = (touch, touchEvent) => { var target = (CCSprite)touchEvent.CurrentTarget; var locationInNode = target.Layer.ScreenToWorldspace(touch.LocationOnScreen); var s = target.ContentSize; CCRect rect = target.BoundingBoxTransformedToWorld; if (rect.ContainsPoint(locationInNode)) { CCLog.Log("sprite began... x = {0}, y = {1}", locationInNode.X, locationInNode.Y); target.Opacity = 180; return true; } return false; }; listener1.OnTouchMoved = (touch, touchEvent) => { var target = (CCSprite)touchEvent.CurrentTarget; CCPoint pt = touch.PreviousLocationOnScreen + touch.Delta; target.Position = target.WorldToParentspace(Layer.ScreenToWorldspace(pt)); }; listener1.OnTouchEnded = (touch, touchEvent) => { var target = (CCSprite)touchEvent.CurrentTarget; CCLog.Log("sprite onTouchesEnded.."); target.Opacity = 255; if (target == sprite2) { sprite1.LocalZOrder = 100; } else if(target == sprite1) { sprite1.LocalZOrder = 0; } }; sprite1.AddEventListener(listener1); sprite2.AddEventListener(listener1.Copy()); sprite3.AddEventListener(listener1.Copy()); var removeAllTouchItem = new CCMenuItemFont("Remove All Touch Listeners", (sender) => { var senderItem = (CCMenuItemFont)sender; senderItem.LabelTTF.Text = "Only Next item could be clicked"; RemoveEventListeners(CCEventListenerType.TOUCH_ONE_BY_ONE); var nextItem = new CCMenuItemFont("Next", (senderNext) => NextCallback(senderNext)); CCMenuItemFont.FontSize = 16; nextItem.Position = new CCPoint(visibleBounds.Origin.X + visibleBounds.Size.Width -100, 100); var menu2 = new CCMenu(nextItem); menu2.Position = CCPoint.Zero; menu2.AnchorPoint = CCPoint.AnchorLowerLeft; this.AddChild(menu2); }); CCMenuItemFont.FontSize = 16; removeAllTouchItem.Position = new CCPoint(visibleBounds.Origin.X + visibleBounds.Size.Width -100, 80); var menu = new CCMenu(removeAllTouchItem); menu.Position = CCPoint.Zero; menu.AnchorPoint = CCPoint.AnchorLowerLeft; AddChild(menu); }
public RemoveAllTest () { CCRect visibleBounds = Layer.VisibleBoundsWorldspace; CCMenuItemFont.FontSize = 16; removeAllTouchItem = new CCMenuItemFont("Remove all listeners", (sender) => { var senderItem = (CCMenuItemFont) sender; senderItem.LabelTTF.Text = "Only 'Reset' item could be clicked"; RemoveAllListeners(); var nextItem = new CCMenuItemFont("Reset", (resetSender) => { Debug.Assert(bugFixed, "This issue was not fixed"); RestartCallback(null); } ); CCMenuItemFont.FontSize = 16; nextItem.Position = new CCPoint(visibleBounds.Origin.X + visibleBounds.Size.Width, visibleBounds.Origin.Y + visibleBounds.Size.Height / 2) + new CCPoint(-100, -30); var menu2 = new CCMenu(nextItem); menu2.AnchorPoint = CCPoint.AnchorLowerLeft; menu2.Position = visibleBounds.Center; AddChild(menu2); DispatchEvent(CCEvent.EVENT_COME_TO_BACKGROUND); }); menu = new CCMenu(removeAllTouchItem); menu.AnchorPoint = CCPoint.AnchorLowerLeft; AddChild(menu); }
public override void OnEnter () { base.OnEnter (); CCRect visibleBounds = VisibleBoundsWorldspace; var origin = Layer.VisibleBoundsWorldspace.Origin; var size = Layer.VisibleBoundsWorldspace.Size; var sprite1 = new TouchableSprite (); var texture = CCTextureCache.SharedTextureCache.AddImage("Images/CyanSquare.png"); sprite1.Texture = texture; sprite1.Position = origin + new CCPoint (size.Width / 2, size.Height / 2) + new CCPoint (-80, 80); AddChild(sprite1, -10); var sprite2 = new TouchableSprite (); texture = CCTextureCache.SharedTextureCache.AddImage("Images/MagentaSquare.png"); sprite2.Texture = texture; sprite2.Position = origin + new CCPoint (size.Width / 2, size.Height / 2); AddChild(sprite2, -20); var sprite3 = new TouchableSprite (); texture = CCTextureCache.SharedTextureCache.AddImage("Images/YellowSquare.png"); sprite3.Texture = texture; sprite3.Position = CCPoint.Zero; sprite2.AddChild(sprite3, -1); CCMenuItemFont.FontSize = 20; CCMenuItemFont.FontName = "arial"; var popup = new CCMenuItemFont("Popup", (sender) => { this.PauseListeners(true); var colorLayer = new CCLayerColor(new CCColor4B(0, 0, 255, 100)); AddChild(colorLayer, 99999); var closeItem = new CCMenuItemFont("close", (closeSender) => { colorLayer.RemoveFromParent(); this.ResumeListeners(true); }); closeItem.Position = visibleBounds.Center; var closeMenu = new CCMenu(closeItem); closeMenu.AnchorPoint = CCPoint.AnchorLowerLeft; closeMenu.Position = CCPoint.Zero; colorLayer.AddChild(closeMenu); }); popup.AnchorPoint = CCPoint.AnchorMiddleRight; popup.Position = new CCPoint(visibleBounds.Origin.X + visibleBounds.Size.Width, visibleBounds.Origin.Y + visibleBounds.Size.Height / 2); var menu = new CCMenu(popup); menu.AnchorPoint = CCPoint.AnchorLowerLeft; menu.Position = CCPoint.Zero; AddChild(menu); }
public override void OnEnter() { base.OnEnter(); Scene.PhysicsWorld.Gravity = CCPoint.Zero; CCDrawNode node = new CCDrawNode(); node.PhysicsBody = CCPhysicsBody.CreateEdgeSegment( new CCPoint(0, 50), new CCPoint(Window.WindowSizeInPixels.Width, 0) + new CCPoint(0, 50) ); node.DrawSegment(new CCPoint(0, 50), new CCPoint(Window.WindowSizeInPixels.Width, 0) + new CCPoint(0, 50), 1, STATIC_COLOR); AddChild(node); var item = new CCMenuItemFont("Change Mode(any)", ChangeModeCallback); var menu = new CCMenu(item); AddChild(menu); menu.Position = new CCPoint(100, 100); Schedule(); }