private void performanceScale(CCSprite pSprite) { CCSize size = CCDirector.SharedDirector.WinSize; pSprite.Position = new CCPoint((Random.Next() % (int)size.Width), (Random.Next() % (int)size.Height)); pSprite.Scale = Random.Float_0_1() * 100 / 50; }
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 = Random.Next() * 50; float y = Random.Next() * 50; menu.Position = menu.Position + new CCPoint(x, y); AddChild(menu, 0, localtag); //[self check:self]; }
public override void updateQuantityOfNodes() { CCSize s = CCDirector.SharedDirector.WinSize; // increase nodes if (currentQuantityOfNodes < quantityOfNodes) { for (int i = 0; i < (quantityOfNodes - currentQuantityOfNodes); i++) { CCSprite sprite = new CCSprite(batchNode.Texture, new CCRect(0, 0, 32, 32)); batchNode.AddChild(sprite); sprite.Position = new CCPoint(Random.Next() * s.Width, Random.Next() * s.Height); sprite.Visible = false; } } // decrease nodes else if (currentQuantityOfNodes > quantityOfNodes) { for (int i = 0; i < (currentQuantityOfNodes - quantityOfNodes); i++) { int index = currentQuantityOfNodes - i - 1; batchNode.RemoveChildAtIndex(index, true); } } currentQuantityOfNodes = quantityOfNodes; }
private void performanceout20(CCSprite pSprite) { CCSize size = CCDirector.SharedDirector.WinSize; if (Random.Float_0_1() < 0.2f) { pSprite.Position = new CCPoint((Random.Next() % (int)size.Width), (Random.Next() % (int)size.Height)); } else { pSprite.Position = new CCPoint(-1000, -1000); } }
public override bool Init() { if (base.Init()) { CCSize screenSize = CCDirector.SharedDirector.WinSize; var layer = new CCNode(); AddChild(layer, 1); int space = 10; // px float max_w = 0, max_h = 0; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { // Add the buttons var button = standardButtonWithTitle(Random.Next(30).ToString()); button.SetAdjustBackgroundImage(false); // Tells the button that the background image must not be adjust // It'll use the prefered size of the background image button.Position = new CCPoint(button.ContentSize.Width / 2 + (button.ContentSize.Width + space) * i, button.ContentSize.Height / 2 + (button.ContentSize.Height + space) * j); layer.AddChild(button); max_w = Math.Max(button.ContentSize.Width * (i + 1) + space * i, max_w); max_h = Math.Max(button.ContentSize.Height * (j + 1) + space * j, max_h); } } layer.AnchorPoint = new CCPoint(0.5f, 0.5f); layer.ContentSize = new CCSize(max_w, max_h); layer.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f); // Add the black background var backgroundButton = new CCScale9SpriteFile("extensions/buttonBackground"); backgroundButton.ContentSize = new CCSize(max_w + 14, max_h + 14); backgroundButton.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f); AddChild(backgroundButton); return(true); } return(false); }
public override bool Init() { if (base.Init()) { // // seed // srand(0); CCPoint A, B, C, D, p1, p2, p3, p4; float s, t; int err = 0; int ok = 0; // // Test 1. // CCLog.Log("Test1 - Start"); for (int i = 0; i < 10000; i++) { // A | b // ----- // c | d float ax = Random.Next() * -5000; float ay = Random.Next() * 5000; // a | b // ----- // c | D float dx = Random.Next() * 5000; float dy = Random.Next() * -5000; // a | B // ----- // c | d float bx = Random.Next() * 5000; float by = Random.Next() * 5000; // a | b // ----- // C | d float cx = Random.Next() * -5000; float cy = Random.Next() * -5000; A = new CCPoint(ax, ay); B = new CCPoint(bx, by); C = new CCPoint(cx, cy); D = new CCPoint(dx, dy); //if (CCPoint.ccpLineIntersect(A, D, B, C, ref s, ref t)) //{ // if (check_for_error(A, D, B, C, s, t) != 0) // err++; // else // ok++; //} } CCLog.Log("Test1 - End. OK=%i, Err=%i", ok, err); // // Test 2. // CCLog.Log("Test2 - Start"); p1 = new CCPoint(220, 480); p2 = new CCPoint(304, 325); p3 = new CCPoint(264, 416); p4 = new CCPoint(186, 416); s = 0.0f; t = 0.0f; if (CCPoint.LineIntersect(p1, p2, p3, p4, ref s, ref t)) { check_for_error(p1, p2, p3, p4, s, t); } CCLog.Log("Test2 - End"); // // Test 3 // CCLog.Log("Test3 - Start"); ok = 0; err = 0; for (int i = 0; i < 10000; i++) { // A | b // ----- // c | d float ax = Random.Next() * -500; float ay = Random.Next() * 500; p1 = new CCPoint(ax, ay); // a | b // ----- // c | D float dx = Random.Next() * 500; float dy = Random.Next() * -500; p2 = new CCPoint(dx, dy); ////// float y = ay - ((ay - dy) / 2.0f); // a | b // ----- // C | d float cx = Random.Next() * -500; p3 = new CCPoint(cx, y); // a | B // ----- // c | d float bx = Random.Next() * 500; p4 = new CCPoint(bx, y); s = 0.0f; t = 0.0f; if (CCPoint.LineIntersect(p1, p2, p3, p4, ref s, ref t)) { if (check_for_error(p1, p2, p3, p4, s, t) != 0) { err++; } else { ok++; } } } CCLog.Log("Test3 - End. OK=%i, err=%i", ok, err); return(true); } return(false); }
private void performancePosition(CCSprite pSprite) { CCSize size = CCDirector.SharedDirector.WinSize; pSprite.Position = new CCPoint((Random.Next() % (int)size.Width), (Random.Next() % (int)size.Height)); }