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 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;
        }
예제 #3
0
        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];
        }
예제 #4
0
        public void altertime(float dt)
        {
            var action1 = (CCSpeed)(m_grossini.GetActionByTag(EaseTest.kTagAction1));
            var action2 = (CCSpeed)(m_tamara.GetActionByTag(EaseTest.kTagAction1));
            var action3 = (CCSpeed)(m_kathia.GetActionByTag(EaseTest.kTagAction1));

            action1.Speed = Random.Float_0_1() * 2;
            action2.Speed = Random.Float_0_1() * 2;
            action3.Speed = Random.Float_0_1() * 2;
        }
예제 #5
0
        public SpriteHybrid()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // parents
            CCNode            parent1 = new CCNode();
            CCSpriteBatchNode parent2 = new CCSpriteBatchNode("animations/grossini", 50);

            AddChild(parent1, 0, (int)kTags.kTagNode);
            AddChild(parent2, 0, (int)kTags.kTagSpriteBatchNode);


            // IMPORTANT:
            // The sprite frames will be cached AND RETAINED, and they won't be released unless you call
            //     CCSpriteFrameCache::sharedSpriteFrameCache()->removeUnusedSpriteFrames);
            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist");


            // create 250 sprites
            // only show 80% of them
            for (int i = 0; i < 250; i++)
            {
                int    spriteIdx = (int)(Random.NextDouble() * 14);
                string str       = "";
                string temp      = "";
                if (spriteIdx + 1 < 10)
                {
                    temp = "0" + (spriteIdx + 1);
                }
                else
                {
                    temp = (spriteIdx + 1).ToString();
                }
                str = string.Format("grossini_dance_{0}.png", temp);
                CCSpriteFrame frame  = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str);
                CCSprite      sprite = new CCSprite(frame);
                parent1.AddChild(sprite, i, i);

                float x = -1000;
                float y = -1000;
                if (Random.NextDouble() < 0.2f)
                {
                    x = (float)(Random.NextDouble() * s.Width);
                    y = (float)(Random.NextDouble() * s.Height);
                }
                sprite.Position = (new CCPoint(x, y));

                CCActionInterval action = new CCRotateBy(4, 360);
                sprite.RunAction(new CCRepeatForever(action));
            }

            m_usingSpriteBatchNode = false;

            Schedule(reparentSprite, 2);
        }
        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);
            }
        }
예제 #7
0
        public void addNewSprite()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCPoint p = new CCPoint((float)(Random.NextDouble() * s.Width), (float)(Random.NextDouble() * s.Height));

            CCSpriteBatchNode batch = (CCSpriteBatchNode)GetChildByTag((int)kTags.kTagSpriteBatchNode);

            int idx = (int)(Random.NextDouble() * 1400 / 100);
            int x   = (idx % 5) * 85;
            int y   = (idx / 5) * 121;


            CCSprite sprite = new CCSprite(batch.Texture, new CCRect(x, y, 85, 121));

            batch.AddChild(sprite);

            sprite.Position = (new CCPoint(p.X, p.Y));

            CCActionInterval action;
            float            random = (float)Random.NextDouble();

            if (random < 0.20)
            {
                action = new CCScaleBy(3, 2);
            }
            else if (random < 0.40)
            {
                action = new CCRotateBy(3, 360);
            }
            else if (random < 0.60)
            {
                action = new CCBlink(1, 3);
            }
            else if (random < 0.8)
            {
                action = new CCTintBy(2, 0, -255, -255);
            }
            else
            {
                action = new CCFadeOut(2);
            }
            CCActionInterval action_back = (CCActionInterval)action.Reverse();
            CCActionInterval seq         = (CCActionInterval)(CCSequence.FromActions(action, action_back));

            sprite.RunAction(new CCRepeatForever(seq));
        }
        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);
        }
예제 #9
0
        public void addNewSpriteAtPosition(CCPoint p)
        {
            CCLog.Log("Add sprite #{2} : {0} x {1}", p.X, p.Y, _batch.ChildrenCount + 1);

            //We have a 64x64 sprite sheet with 4 different 32x32 images.  The following code is
            //just randomly picking one of the images
            int idx    = (Random.Float_0_1() > .5 ? 0 : 1);
            int idy    = (Random.Float_0_1() > .5 ? 0 : 1);
            var sprite = new CCPhysicsSprite(m_pSpriteTexture, new CCRect(32 * idx, 32 * idy, 32, 32));

            _batch.AddChild(sprite, 0, kTagForPhysicsSprite);

            sprite.Position = new CCPoint(p.X, p.Y);

            // Define the dynamic body.
            //Set up a 1m squared box in the physics world
            b2BodyDef def = b2BodyDef.Create();

            def.position = new b2Vec2(p.X / PTM_RATIO, p.Y / PTM_RATIO);
            def.type     = b2BodyType.b2_dynamicBody;
            b2Body body = _world.CreateBody(def);
            // Define another box shape for our dynamic body.
            var dynamicBox = new b2PolygonShape();

            dynamicBox.SetAsBox(.5f, .5f); //These are mid points for our 1m box

            // Define the dynamic body fixture.
            b2FixtureDef fd = b2FixtureDef.Create();

            fd.shape    = dynamicBox;
            fd.density  = 1f;
            fd.friction = 0.3f;
            b2Fixture fixture = body.CreateFixture(fd);

            sprite.PhysicsBody = body;
            //_world.SetContactListener(new Myb2Listener());

            // _world.Dump();
        }
예제 #10
0
        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);
        }
예제 #11
0
        private void performancePosition(CCSprite pSprite)
        {
            CCSize size = CCDirector.SharedDirector.WinSize;

            pSprite.Position = new CCPoint((Random.Next() % (int)size.Width), (Random.Next() % (int)size.Height));
        }