Example #1
0
 /** Creates a switch with a mask sprite, on/off sprites for on/off states, a thumb sprite and an on/off labels. */
 public static CCControlSwitch Create(CCSprite maskSprite, CCSprite onSprite, CCSprite offSprite, CCSprite thumbSprite, CCLabelTTF onLabel,
                                      CCLabelTTF offLabel)
 {
     var pRet = new CCControlSwitch();
     pRet.InitWithMaskSprite(maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel);
     return pRet;
 }
Example #2
0
        public NodeToWorld()
        {
            //
            // This code tests that nodeToParent works OK:
            //  - It tests different anchor Points
            //  - It tests different children anchor points

            CCSprite back = new CCSprite(TestResource.s_back3);
            AddChild(back, -10);
            back.AnchorPoint = (new CCPoint(0, 0));
            CCSize backSize = back.ContentSize;

            CCMenuItem item = new CCMenuItemImage(TestResource.s_PlayNormal, TestResource.s_PlaySelect);
            CCMenu menu = new CCMenu(item);
            menu.AlignItemsVertically();
            menu.Position = (new CCPoint(backSize.Width / 2, backSize.Height / 2));
            back.AddChild(menu);

            CCActionInterval rot = new CCRotateBy (5, 360);
            CCAction fe = new CCRepeatForever (rot);
            item.RunAction(fe);

            CCActionInterval move = new CCMoveBy (3, new CCPoint(200, 0));
            var move_back = (CCActionInterval) move.Reverse();
            CCFiniteTimeAction seq = CCSequence.FromActions(move, move_back);
            CCAction fe2 = new CCRepeatForever ((CCActionInterval) seq);
            back.RunAction(fe2);
        }
Example #3
0
        public override void OnEnter()
        {
            //
            // This test MUST be done in 'onEnter' and not on 'init'
            // otherwise the paused action will be resumed at 'onEnter' time
            //
            base.OnEnter();

            CCSize s = CCDirector.SharedDirector.WinSize;

            CCLabelTTF l = new CCLabelTTF("After 5 seconds grossini should move", "arial", 16);
            AddChild(l);
            l.Position = (new CCPoint(s.Width / 2, 245));

            //
            // Also, this test MUST be done, after [super onEnter]
            //
            CCSprite grossini = new CCSprite(s_pPathGrossini);
            AddChild(grossini, 0, kTagGrossini);
            grossini.Position = (new CCPoint(200, 200));

            CCAction action = new CCMoveBy (1, new CCPoint(150, 0));

            CCDirector.SharedDirector.ActionManager.AddAction(action, grossini, true);

            Schedule(unpause, 3);
        }
        void InitWithOurOwnProperties(string theFileNameToAnimate,
		                              int theFrameToStartWith,
		                              int theNumberOfFramesToAnimate,
		                              int theX,
		                              int theY,
		                              bool flipOnX,
		                              bool flipOnY,
		                              bool doesItLoop,
		                              bool doesItUseRandomFrameToLoop)
        {
            this.fileNameToAnimate = theFileNameToAnimate;

            this.frameToStartWith = theFrameToStartWith;
            this.currentFrame = frameToStartWith;

            this.framesToAnimate = theNumberOfFramesToAnimate;

            this.animationFlippedX = flipOnX;
            this.animationFlippedY = flipOnY;

            this.doesTheAnimationLoop = doesItLoop;
            this.useRandomFrameToLoop = doesItUseRandomFrameToLoop;

            this.someSprite = new CCSprite(String.Format("{0}_000{1}.png", fileNameToAnimate, currentFrame));
            AddChild(someSprite);
            someSprite.PositionX = theX;
            someSprite.PositionY = theY;

            someSprite.FlipX = animationFlippedX;
            someSprite.FlipY = animationFlippedY;

            Schedule(RunMyAnimation, 1.0f / 60.0f);
        }
Example #5
0
        public SpriteZOrder()
        {
            m_dir = 1;

            CCSize s = CCDirector.SharedDirector.WinSize;

            float step = s.Width / 11;
            for (int i = 0; i < 5; i++)
            {
                CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 0, 121 * 1, 85, 121));
                sprite.Position = (new CCPoint((i + 1) * step, s.Height / 2));
                AddChild(sprite, i);
            }

            for (int i = 5; i < 10; i++)
            {
                CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 0, 85, 121));
                sprite.Position = new CCPoint((i + 1) * step, s.Height / 2);
                AddChild(sprite, 14 - i);
            }

            CCSprite sprite1 = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 3, 121 * 0, 85, 121));
            AddChild(sprite1, -1, (int)kTagSprite.kTagSprite1);
            sprite1.Position = (new CCPoint(s.Width / 2, s.Height / 2 - 20));
            sprite1.Scale = 6;
            sprite1.Color = new CCColor3B(Color.Red);

            Schedule(reorderSprite, 1);
        }
        public RenderTextureSave()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // create a render texture, this is what we are going to draw into
            m_pTarget = CCRenderTexture.Create((int) s.Width, (int) s.Height, SurfaceFormat.Color, DepthFormat.None, RenderTargetUsage.PreserveContents);
            m_pTarget.Position = new CCPoint(s.Width / 2, s.Height / 2);

            // It's possible to modify the RenderTexture blending function by
            //CCBlendFunc tbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);
            //m_pTarget.Sprite.BlendFunc = tbf;

            // 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
            AddChild(m_pTarget, -1);

            // create a brush image to draw into the texture with
            m_pBrush = new CCSprite("Images/fire");
            // It's possible to modify the Brushes blending function by
            CCBlendFunc bbf = new CCBlendFunc (OGLES.GL_ONE, OGLES.GL_ONE_MINUS_SRC_ALPHA);
            m_pBrush.BlendFunc = bbf;

            m_pBrush.Color = new CCColor3B (Color.Red);
            m_pBrush.Opacity = 20;
            TouchEnabled = true;

            // Save Image menu
            CCMenuItemFont.FontSize = 16;
            CCMenuItem item1 = CCMenuItemFont.Create("Save Image", saveImage);
            CCMenuItem item2 = CCMenuItemFont.Create("Clear", clearImage);
            var menu = new CCMenu(item1, item2);
            AddChild(menu);
            menu.AlignItemsVertically();
            menu.Position = new CCPoint(s.Width - 80, s.Height - 30);
        }
Example #7
0
        public override void OnEnter()
        {
            base.OnEnter();
            m_grossini = new CCSprite(TestResource.s_pPathGrossini);
            m_tamara = new CCSprite(TestResource.s_pPathSister1);
            m_kathia = new CCSprite(TestResource.s_pPathSister2);

            AddChild(m_grossini, 3);
            AddChild(m_kathia, 2);
            AddChild(m_tamara, 1);

            var s = CCDirector.SharedDirector.WinSize;

            m_grossini.Position = new CCPoint(60, 50);
            m_kathia.Position = new CCPoint(60, 150);
            m_tamara.Position = new CCPoint(60, 250);

            var label = new CCLabelTTF(title(), "arial", 32);
            AddChild(label);
            label.Position = new CCPoint(s.Width / 2, s.Height - 50);

            var item1 = new CCMenuItemImage(TestResource.s_pPathB1, TestResource.s_pPathB2, backCallback);
            var item2 = new CCMenuItemImage(TestResource.s_pPathR1, TestResource.s_pPathR2, restartCallback);
            var item3 = new CCMenuItemImage(TestResource.s_pPathF1, TestResource.s_pPathF2, nextCallback);

            var menu = new CCMenu(item1, item2, item3);
            menu.Position = CCPoint.Zero;
            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);

            AddChild(menu, 1);
        }
Example #8
0
        public Test6()
        {
            CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1);
            CCSprite sp11 = new CCSprite(TestResource.s_pPathSister1);

            CCSprite sp2 = new CCSprite(TestResource.s_pPathSister2);
            CCSprite sp21 = new CCSprite(TestResource.s_pPathSister2);

            sp1.Position = (new CCPoint(100, 160));
            sp2.Position = (new CCPoint(380, 160));

            CCActionInterval rot = new CCRotateBy (2, 360);
            var rot_back = rot.Reverse() as CCActionInterval;
            CCAction forever1 = new CCRepeatForever ((CCActionInterval)CCSequence.FromActions(rot, rot_back));
            var forever11 = (CCAction) (forever1.Copy());

            var forever2 = (CCAction) (forever1.Copy());
            var forever21 = (CCAction) (forever1.Copy());

            AddChild(sp1, 0, CocosNodeTestStaticLibrary.kTagSprite1);
            sp1.AddChild(sp11);
            AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2);
            sp2.AddChild(sp21);

            sp1.RunAction(forever1);
            sp11.RunAction(forever11);
            sp2.RunAction(forever2);
            sp21.RunAction(forever21);

            Schedule(addAndRemove, 2.0f);
        }
        public SpriteBatchNodeZOrder()
        {
            m_dir = 1;

            // small capacity. Testing resizing.
            // Don't use capacity=1 in your real game. It is expensive to resize the capacity
            CCSpriteBatchNode batch = CCSpriteBatchNode.Create("Images/grossini_dance_atlas", 1);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.SharedDirector.WinSize;

            float step = s.Width / 11;
            for (int i = 0; i < 5; i++)
            {
                CCSprite sprite = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
                sprite.Position = (new CCPoint((i + 1) * step, s.Height / 2));
                batch.AddChild(sprite, i);
            }

            for (int i = 5; i < 10; i++)
            {
                CCSprite sprite = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121));
                sprite.Position = new CCPoint((i + 1) * step, s.Height / 2);
                batch.AddChild(sprite, 14 - i);
            }

            CCSprite sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 0, 85, 121));
            batch.AddChild(sprite1, -1, (int)kTagSprite.kTagSprite1);
            sprite1.Position = (new CCPoint(s.Width / 2, s.Height / 2 - 20));
            sprite1.Scale = 6;
            sprite1.Color = new CCColor3B(Color.Red);

            Schedule(reorderSprite, 1);
        }
        public SpriteBatchNodeAliased()
        {
            CCSpriteBatchNode batch = CCSpriteBatchNode.Create("Images/grossini_dance_atlas", 10);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.SharedDirector.WinSize;

            CCSprite sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));
            sprite1.Position = (new CCPoint(s.Width / 2 - 100, s.Height / 2));
            batch.AddChild(sprite1, 0, (int)kTagSprite.kTagSprite1);

            CCSprite sprite2 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));
            sprite2.Position = (new CCPoint(s.Width / 2 + 100, s.Height / 2));
            batch.AddChild(sprite2, 0, (int)kTagSprite.kTagSprite2);

            CCActionInterval scale = new CCScaleBy(2, 5);
            CCActionInterval scale_back = (CCActionInterval)scale.Reverse();
            CCActionInterval seq = (CCActionInterval)(CCSequence.FromActions(scale, scale_back));
            CCAction repeat = new CCRepeatForever (seq);

            CCAction repeat2 = (CCAction)(repeat.Copy());

            sprite1.RunAction(repeat);
            sprite2.RunAction(repeat2);
        }
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize s = CCDirector.SharedDirector.WinSize;

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("zwoptex/grossini.plist");
            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("zwoptex/grossini-generic.plist");

            CCLayerColor layer1 = CCLayerColor.Create(new CCColor4B(255, 0, 0, 255), 85, 121);
            layer1.Position = new CCPoint(s.Width / 2 - 80 - (85.0f * 0.5f), s.Height / 2 - (121.0f * 0.5f));
            AddChild(layer1);

            sprite1 = new CCSprite(CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName("grossini_dance_01.png"));
            sprite1.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2));
            AddChild(sprite1);

            sprite1.FlipX = false;
            sprite1.FlipY = false;

            CCLayerColor layer2 = CCLayerColor.Create(new CCColor4B(255, 0, 0, 255), 85, 121);
            layer2.Position = new CCPoint(s.Width / 2 + 80 - (85.0f * 0.5f), s.Height / 2 - (121.0f * 0.5f));
            AddChild(layer2);

            sprite2 = new CCSprite(CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName("grossini_dance_generic_01.png"));
            sprite2.Position = (new CCPoint(s.Width / 2 + 80, s.Height / 2));
            AddChild(sprite2);

            sprite2.FlipX = false;
            sprite2.FlipY = false;

            Schedule(startIn05Secs, 1.0f);

            counter = 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);
        }
        public SpriteBatchNodeColorOpacity()
        {
            // small capacity. Testing resizing.
            // Don't use capacity=1 in your real game. It is expensive to resize the capacity
            CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 1);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSprite sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
            CCSprite sprite2 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));
            CCSprite sprite3 = new CCSprite(batch.Texture, new CCRect(85 * 2, 121 * 1, 85, 121));
            CCSprite sprite4 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 1, 85, 121));

            CCSprite sprite5 = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
            CCSprite sprite6 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121));
            CCSprite sprite7 = new CCSprite(batch.Texture, new CCRect(85 * 2, 121 * 1, 85, 121));
            CCSprite sprite8 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 1, 85, 121));

            CCSize s = CCDirector.SharedDirector.WinSize;
            sprite1.Position = new CCPoint((s.Width / 5) * 1, (s.Height / 3) * 1);
            sprite2.Position = new CCPoint((s.Width / 5) * 2, (s.Height / 3) * 1);
            sprite3.Position = new CCPoint((s.Width / 5) * 3, (s.Height / 3) * 1);
            sprite4.Position = new CCPoint((s.Width / 5) * 4, (s.Height / 3) * 1);
            sprite5.Position = new CCPoint((s.Width / 5) * 1, (s.Height / 3) * 2);
            sprite6.Position = new CCPoint((s.Width / 5) * 2, (s.Height / 3) * 2);
            sprite7.Position = new CCPoint((s.Width / 5) * 3, (s.Height / 3) * 2);
            sprite8.Position = new CCPoint((s.Width / 5) * 4, (s.Height / 3) * 2);

            CCActionInterval action = new CCFadeIn  (2);
            CCActionInterval action_back = (CCActionInterval)action.Reverse();
            CCAction fade = new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(action, action_back)));

            CCActionInterval tintred = new CCTintBy (2, 0, -255, -255);
            CCActionInterval tintred_back = (CCActionInterval)tintred.Reverse();
            CCAction red = new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(tintred, tintred_back)));

            CCActionInterval tintgreen = new CCTintBy (2, -255, 0, -255);
            CCActionInterval tintgreen_back = (CCActionInterval)tintgreen.Reverse();
            CCAction green = new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(tintgreen, tintgreen_back)));

            CCActionInterval tintblue = new CCTintBy (2, -255, -255, 0);
            CCActionInterval tintblue_back = (CCActionInterval)tintblue.Reverse();
            CCAction blue = new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(tintblue, tintblue_back)));

            sprite5.RunAction(red);
            sprite6.RunAction(green);
            sprite7.RunAction(blue);
            sprite8.RunAction(fade);

            // late add: test dirtyColor and dirtyPosition
            batch.AddChild(sprite1, 0, (int)kTagSprite.kTagSprite1);
            batch.AddChild(sprite2, 0, (int)kTagSprite.kTagSprite2);
            batch.AddChild(sprite3, 0, (int)kTagSprite.kTagSprite3);
            batch.AddChild(sprite4, 0, (int)kTagSprite.kTagSprite4);
            batch.AddChild(sprite5, 0, (int)kTagSprite.kTagSprite5);
            batch.AddChild(sprite6, 0, (int)kTagSprite.kTagSprite6);
            batch.AddChild(sprite7, 0, (int)kTagSprite.kTagSprite7);
            batch.AddChild(sprite8, 0, (int)kTagSprite.kTagSprite8);

            Schedule(removeAndAddSprite, 2);
        }
Example #14
0
 private void performanceRotationScale(CCSprite pSprite)
 {
     CCSize size = CCDirector.SharedDirector.WinSize;
     pSprite.Position = new CCPoint((Random.Next() % (int)size.Width), (Random.Next() % (int)size.Height));
     pSprite.Rotation = Random.Float_0_1() * 360;
     pSprite.Scale = Random.Float_0_1() * 2;
 }
Example #15
0
        public StressTest2()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCLayer sublayer = new CCLayer();

            CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1);
            sp1.Position = (new CCPoint(80, s.Height / 2));

            CCActionInterval move = new CCMoveBy (3, new CCPoint(350, 0));
            CCActionInterval move_ease_inout3 = new CCEaseInOut((CCActionInterval) (move.Copy()), 2.0f);
            var move_ease_inout_back3 = (CCActionInterval) move_ease_inout3.Reverse();
            CCFiniteTimeAction seq3 = CCSequence.FromActions(move_ease_inout3, move_ease_inout_back3);
            sp1.RunAction(new CCRepeatForever ((CCActionInterval) seq3));
            sublayer.AddChild(sp1, 1);

            CCParticleFire fire = CCParticleFire.Create();
            fire.Texture = (CCTextureCache.SharedTextureCache.AddImage("Images/fire"));
            fire.Position = (new CCPoint(80, s.Height / 2 - 50));

            var copy_seq3 = (CCActionInterval) (seq3.Copy());

            fire.RunAction(new CCRepeatForever (copy_seq3));
            sublayer.AddChild(fire, 2);

            Schedule((shouldNotLeak), 6.0f);

            AddChild(sublayer, 0, CocosNodeTestStaticLibrary.kTagSprite1);
        }
        public RenderTextureTest()
        {
            //if (CCConfiguration.sharedConfiguration().getGlesVersion() <= GLES_VER_1_0)
            //{
            //    CCMessageBox("The Opengl ES version is lower than 1.1, and the test may not run correctly.", "Cocos2d-x Hint");
            //    return;
            //}

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

            // create a render texture, this is what we're going to draw into
            m_target = CCRenderTexture.renderTextureWithWidthAndHeight((int)s.width, (int)s.height);

            if (null == m_target)
            {
                return;
            }

            m_target.position = new CCPoint(s.width / 2, s.height / 2);

            // note that the render texture is a cocosnode, and contains a sprite of it's texture for convience,
            // so we can just parent it to the scene like any other cocos node
            addChild(m_target, 1);

            // create a brush image to draw into the texture with
            m_brush = CCSprite.spriteWithFile("Images/stars.png");
            //m_brush.retain();

            ccBlendFunc bf = new ccBlendFunc { src = 1, dst = 0x0303 };
            m_brush.BlendFunc = bf;
            m_brush.Opacity = 20;
            isTouchEnabled = true;
        }
Example #17
0
        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);
                }
            }

            // 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;
        }
Example #18
0
        public virtual CCTableViewCell TableCellAtIndex(CCTableView table, int idx)
        {
            string str = idx.ToString();
            var cell = table.DequeueCell();

            if (cell == null) {
                cell = new CustomTableViewCell();
                var sprite = new CCSprite("Images/Icon");
                sprite.AnchorPoint = CCPoint.Zero;
                sprite.Position = new CCPoint(0, 0);
                cell.AddChild(sprite);

                var label = new CCLabelTTF(str, "Helvetica", 20.0f);
                label.Position = CCPoint.Zero;
                label.AnchorPoint = CCPoint.Zero;
                label.Tag = 123;
                cell.AddChild(label);
            }
            else
            {
                var label = (CCLabelTTF)cell.GetChildByTag(123);
                label.Label = (str);
            }

            return cell;
        }
Example #19
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCActionInterval effect = (CCSequence.FromActions(new CCDelayTime (2.0f), CCShaky3D.Create(16, false, new CCGridSize(5, 5), 5.0f)));

            // cleanup
            CCNode bg = GetChildByTag(EffectAdvanceScene.kTagBackground);
            RemoveChild(bg, true);

            // background
            CCLayerColor layer = CCLayerColor.Create(new CCColor4B(255, 0, 0, 255));
            AddChild(layer, -10);
            CCSprite sprite = new CCSprite("Images/grossini");
            sprite.Position = new CCPoint(50, 80);
            layer.AddChild(sprite, 10);

            // foreground
            CCLayerColor layer2 = CCLayerColor.Create(new CCColor4B(0, 255, 0, 255));
            CCSprite fog = new CCSprite("Images/Fog");

            var bf = new CCBlendFunc {Source = OGLES.GL_SRC_ALPHA, Destination = OGLES.GL_ONE_MINUS_SRC_ALPHA};
            fog.BlendFunc = bf;
            layer2.AddChild(fog, 1);
            AddChild(layer2, 1);

            layer2.RunAction(new CCRepeatForever (effect));
        }
        public SpriteBatchNodeChildren()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // parents
            CCSpriteBatchNode batch = CCSpriteBatchNode.Create("animations/grossini", 50);

            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist");

            CCSprite sprite1 = new CCSprite("grossini_dance_01.png");
            sprite1.Position = (new CCPoint(s.Width / 3, s.Height / 2));

            CCSprite sprite2 = new CCSprite("grossini_dance_02.png");
            sprite2.Position = (new CCPoint(50, 50));

            CCSprite sprite3 = new CCSprite("grossini_dance_03.png");
            sprite3.Position = (new CCPoint(-50, -50));

            batch.AddChild(sprite1);
            sprite1.AddChild(sprite2);
            sprite1.AddChild(sprite3);

            // BEGIN NEW CODE
            var animFrames = new List<CCSpriteFrame>();
            string str = "";
            for (int i = 1; i < 15; i++)
            {
                string temp = "";
                if (i<10)
                {
                    temp = "0" + i;
                }
                else
                {
                    temp = i.ToString();
                }
                str = string.Format("grossini_dance_{0}.png", temp);
                CCSpriteFrame frame = CCSpriteFrameCache.SharedSpriteFrameCache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = CCAnimation.Create(animFrames, 0.2f);
            sprite1.RunAction(new CCRepeatForever (new CCAnimate (animation)));
            // END NEW CODE

            CCActionInterval action = new CCMoveBy (2, new CCPoint(200, 0));
            CCActionInterval action_back = (CCActionInterval)action.Reverse();
            CCActionInterval action_rot = new CCRotateBy (2, 360);
            CCActionInterval action_s = new CCScaleBy(2, 2);
            CCActionInterval action_s_back = (CCActionInterval)action_s.Reverse();

            CCActionInterval seq2 = (CCActionInterval)action_rot.Reverse();
            sprite2.RunAction(new CCRepeatForever (seq2));

            sprite1.RunAction((CCAction)(new CCRepeatForever (action_rot)));
            sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(action, action_back)))));
            sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(action_s, action_s_back)))));
        }
        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));
        }
Example #22
0
        public override bool Init()
        {
            InitWithColor(new CCColor4B(0, 0, 255, 255));

            CCMenuItemFont item1 = CCMenuItemFont.Create("(3) Touch to pushScene (self)", item0Clicked);
            CCMenuItemFont item2 = CCMenuItemFont.Create("(3) Touch to popScene", item1Clicked);
            CCMenuItemFont item3 = CCMenuItemFont.Create("(3) Touch to popToRootScene", item2Clicked);

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

            AddChild(menu);

            CCSize s = CCDirector.SharedDirector.WinSize;
            CCSprite sprite = new CCSprite(s_pPathGrossini);
            AddChild(sprite);

            sprite.Position = new CCPoint(s.Width /2, 40);
            CCActionInterval rotate = new CCRotateBy (2, 360);
            CCAction repeat = new CCRepeatForever (rotate);
            sprite.RunAction(repeat);

            Schedule(testDealloc);

            return true;
        }
 private void performanceScale(CCSprite pSprite)
 {
     Random random = new Random();
     CCSize size = CCDirector.sharedDirector().getWinSize();
     pSprite.position = new CCPoint((random.Next() % (int)size.width), (random.Next() % (int)size.height));
     pSprite.scale = random.Next() * 100 / 50;
 }
Example #24
0
        public CameraZoomTest()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCSprite sprite;
            CCCamera cam;

            // LEFT
            sprite = new CCSprite(TestResource.s_pPathGrossini);
            AddChild(sprite, 0);
            sprite.Position = (new CCPoint(s.Width / 4 * 1, s.Height / 2));
            cam = sprite.Camera;
            cam.SetEyeXyz(0, 0, 415 / 2);
            cam.SetCenterXyz(0, 0, 0);

            // CENTER
            sprite = new CCSprite(TestResource.s_pPathGrossini);
            AddChild(sprite, 0, 40);
            sprite.Position = (new CCPoint(s.Width / 4 * 2, s.Height / 2));

            // RIGHT
            sprite = new CCSprite(TestResource.s_pPathGrossini);
            AddChild(sprite, 0, 20);
            sprite.Position = (new CCPoint(s.Width / 4 * 3, s.Height / 2));

            m_z = 0;

            ScheduleUpdate();
        }
Example #25
0
        public void addNewSpriteWithCoords(CCPoint p)
        {
            int idx = (int)(CCMacros.CCRandomBetween0And1() * 1400.0f / 100.0f);
            int x = (idx % 5) * 85;
            int y = (idx / 5) * 121;

            CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(x, y, 85, 121));
            AddChild(sprite);

            sprite.Position = p;

            CCActionInterval action;
            float random = CCMacros.CCRandomBetween0And1();

            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);
            object obj = action.Reverse();
            CCActionInterval action_back = (CCActionInterval)action.Reverse();
            CCActionInterval seq = (CCActionInterval)(CCSequence.FromActions(action, action_back));

            sprite.RunAction(new CCRepeatForever (seq));
        }
        public override void onEnter()
        {
            base.onEnter();
            m_grossini = CCSprite.spriteWithFile(TestResource.s_pPathGrossini);
            m_tamara = CCSprite.spriteWithFile(TestResource.s_pPathSister1);
            m_kathia = CCSprite.spriteWithFile(TestResource.s_pPathSister2);

            addChild(m_grossini, 3);
            addChild(m_kathia, 2);
            addChild(m_tamara, 1);

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

            m_grossini.position = new CCPoint(60, 50);
            m_kathia.position = new CCPoint(60, 150);
            m_tamara.position = new CCPoint(60, 250);

            CCLabelTTF label = CCLabelTTF.labelWithString(title(), "Arial", 32);
            addChild(label);
            label.position = new CCPoint(s.width / 2, s.height - 50);

            CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathB1, TestResource.s_pPathB2, this, backCallback);
            CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathR1, TestResource.s_pPathR2, this, restartCallback);
            CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathF1, TestResource.s_pPathF2, this, nextCallback);

            CCMenu menu = CCMenu.menuWithItems(item1, item2, item3);
            menu.position = CCPoint.Zero;
            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);

            addChild(menu, 1);
        }
Example #27
0
        public override bool init()
        {
            if (!base.init())
                return false;
            if (!base.init())
            {
                return false;
            }

            CCSize winSize = CCDirector.sharedDirector().getWinSize();
            title = CCLabelTTF.labelWithString("FootBall", "Arial", 24);
            title.position = new CCPoint(winSize.width / 2, winSize.height - 50);
            this.addChild(title, 1);
            ball = CCSprite.spriteWithFile(@"images/ball");
            ball.position = new CCPoint(100, 300);
            this.addChild(ball);
            Vector2 gravity = new Vector2(0.0f, -30.0f);
            bool doSleep = true;
            world = new World(gravity, doSleep);
            /////////////////////////
            BodyDef groundBodyDef = new BodyDef();
            groundBodyDef.position = new Vector2(0, 0);
            Body groundBody = world.CreateBody(groundBodyDef);
            PolygonShape groundBox = new PolygonShape();
            FixtureDef boxShapeDef = new FixtureDef();
            boxShapeDef.shape = groundBox;

            groundBox.SetAsEdge(new Vector2(0, 0), new Vector2((float)(winSize.width / PTM_RATIO), 0));
            groundBody.CreateFixture(boxShapeDef);
            groundBox.SetAsEdge(new Vector2(0, 0), new Vector2(0, (float)(winSize.height / PTM_RATIO)));
            groundBody.CreateFixture(boxShapeDef);
            groundBox.SetAsEdge(new Vector2(0, (float)(winSize.height / PTM_RATIO)),
                new Vector2((float)(winSize.width / PTM_RATIO), (float)(winSize.height / PTM_RATIO)));
            groundBody.CreateFixture(boxShapeDef);
            groundBox.SetAsEdge(new Vector2((float)(winSize.width / PTM_RATIO), (float)(winSize.height / PTM_RATIO)),
                new Vector2((float)(winSize.width / PTM_RATIO), 0));
            groundBody.CreateFixture(boxShapeDef);

            BodyDef ballBodyDef = new BodyDef();
            ballBodyDef.type = BodyType.Dynamic;
            ballBodyDef.position = new Vector2(
                (float)(100 / PTM_RATIO),
                (float)(300 / PTM_RATIO));
            ballBodyDef.userData = ball;
            body = world.CreateBody(ballBodyDef);

            CircleShape circle = new CircleShape();
            circle._radius = (float)(26.0 / PTM_RATIO);

            FixtureDef ballShapeDef = new FixtureDef();
            ballShapeDef.shape = circle;
            ballShapeDef.density = 1.0f;
            ballShapeDef.friction = 0.0f;
            ballShapeDef.restitution = 1.0f;
            body.CreateFixture(ballShapeDef);

            this.schedule(tick);
            return true;
        }
Example #28
0
        public IntervalLayer()
        {
            m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f;

            CCSize s = CCDirector.SharedDirector.WinSize;

            // sun
            CCParticleSystem sun = CCParticleSun.Create();
            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 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt");
            m_label1 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt");
            m_label2 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt");
            m_label3 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt");
            m_label4 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt");

            ScheduleUpdate();

            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 (
                (CCActionInterval) (CCSequence.FromActions(jump, jump.Reverse())))
                );

            // pause button
            CCMenuItem item1 = CCMenuItemFont.Create("Pause", onPause);
            CCMenu menu = new CCMenu(item1);
            menu.Position = new CCPoint(s.Width / 2, s.Height - 50);

            AddChild(menu);
        }
        public RenderTextureZbuffer()
        {
            //this->setIsTouchEnabled(true);
            TouchEnabled = true;
            CCSize size = CCDirector.SharedDirector.WinSize;
            CCLabelTTF label = new CCLabelTTF("vertexZ = 50", "Marker Felt", 32);
            label.Position = new CCPoint(size.Width / 2, size.Height * 0.25f);
            AddChild(label);

            CCLabelTTF label2 = new CCLabelTTF("vertexZ = 0", "Marker Felt", 32);
            label2.Position = new CCPoint(size.Width / 2, size.Height * 0.5f);
            AddChild(label2);

            CCLabelTTF label3 = new CCLabelTTF("vertexZ = -50", "Marker Felt", 32);
            label3.Position = new CCPoint(size.Width / 2, size.Height * 0.75f);
            AddChild(label3);

            label.VertexZ = 50;
            label2.VertexZ = 0;
            label3.VertexZ = -50;

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("Images/bugs/circle.plist");

            mgr = CCSpriteBatchNode.Create("Images/bugs/circle", 9);
            AddChild(mgr);

            sp1 = new CCSprite("Images/bugs/circle");
            sp2 = new CCSprite("Images/bugs/circle");
            sp3 = new CCSprite("Images/bugs/circle");
            sp4 = new CCSprite("Images/bugs/circle");
            sp5 = new CCSprite("Images/bugs/circle");
            sp6 = new CCSprite("Images/bugs/circle");
            sp7 = new CCSprite("Images/bugs/circle");
            sp8 = new CCSprite("Images/bugs/circle");
            sp9 = new CCSprite("Images/bugs/circle");

            mgr.AddChild(sp1, 9);
            mgr.AddChild(sp2, 8);
            mgr.AddChild(sp3, 7);
            mgr.AddChild(sp4, 6);
            mgr.AddChild(sp5, 5);
            mgr.AddChild(sp6, 4);
            mgr.AddChild(sp7, 3);
            mgr.AddChild(sp8, 2);
            mgr.AddChild(sp9, 1);

            sp1.VertexZ = 400;
            sp2.VertexZ = 300;
            sp3.VertexZ = 200;
            sp4.VertexZ = 100;
            sp5.VertexZ = 0;
            sp6.VertexZ = -100;
            sp7.VertexZ = -200;
            sp8.VertexZ = -300;
            sp9.VertexZ = -400;

            sp9.Scale = 2;
            sp9.Color = CCTypes.CCYellow;
        }
        public SpriteBatchNodeReorderIssue767()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            string scope = CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/ghosts.plist", "animations/ghosts");
            CCNode aParent;
            CCSprite l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2;

            //
            // SpriteBatchNode: 3 levels of children
            //
            aParent = new CCSpriteBatchNode("animations/ghosts");
            AddChild(aParent, 0, (int) kTagSprite.kTagSprite1);

            // parent
            l1 = new CCSprite(scope + "father.gif");
            l1.Position = (new CCPoint(s.Width / 2, s.Height / 2));
            aParent.AddChild(l1, 0, (int) kTagSprite.kTagSprite2);
            CCSize l1Size = l1.ContentSize;

            // child left
            l2a = new CCSprite(scope + "sister1.gif");
            l2a.Position = (new CCPoint(-25 + l1Size.Width / 2, 0 + l1Size.Height / 2));
            l1.AddChild(l2a, -1, (int) kTags.kTagSpriteLeft);
            CCSize l2aSize = l2a.ContentSize;

            // child right
            l2b = new CCSprite(scope + "sister2.gif");
            l2b.Position = (new CCPoint(+25 + l1Size.Width / 2, 0 + l1Size.Height / 2));
            l1.AddChild(l2b, 1, (int) kTags.kTagSpriteRight);
            CCSize l2bSize = l2a.ContentSize;

            // child left bottom
            l3a1 = new CCSprite(scope + "child1.gif");
            l3a1.Scale = (0.65f);
            l3a1.Position = (new CCPoint(0 + l2aSize.Width / 2, -50 + l2aSize.Height / 2));
            l2a.AddChild(l3a1, -1);

            // child left top
            l3a2 = new CCSprite(scope + "child1.gif");
            l3a2.Scale = (0.65f);
            l3a2.Position = (new CCPoint(0 + l2aSize.Width / 2, +50 + l2aSize.Height / 2));
            l2a.AddChild(l3a2, 1);

            // child right bottom
            l3b1 = new CCSprite(scope + "child1.gif");
            l3b1.Scale = (0.65f);
            l3b1.Position = (new CCPoint(0 + l2bSize.Width / 2, -50 + l2bSize.Height / 2));
            l2b.AddChild(l3b1, -1);

            // child right top
            l3b2 = new CCSprite(scope + "child1.gif");
            l3b2.Scale = (0.65f);
            l3b2.Position = (new CCPoint(0 + l2bSize.Width / 2, +50 + l2bSize.Height / 2));
            l2b.AddChild(l3b2, 1);

            Schedule(reorderSprites, 1);
        }
        /// <summary>
        /// updates the font chars based on the string to render
        /// </summary>
        public void createFontChars()
        {
            int nextFontPositionX = 0;
            int nextFontPositionY = 0;
            int prev          = -1;
            int kerningAmount = 0;

            CCSize tmpSize = new CCSize(0, 0);

            int longestLine = 0;
            int totalHeight = 0;

            int quantityOfLines = 1;

            int stringLen = m_sString.Length;

            if (0 == stringLen)
            {
                return;
            }

            for (int i = 0; i < stringLen - 1; ++i)
            {
                ushort c = m_sString[i];
                if (c == '\n')
                {
                    quantityOfLines++;
                }
            }

            totalHeight       = m_pConfiguration.m_uCommonHeight * quantityOfLines;
            nextFontPositionY = -(m_pConfiguration.m_uCommonHeight - m_pConfiguration.m_uCommonHeight * quantityOfLines);

            for (int i = 0; i < stringLen; i++)
            {
                int c = m_sString[i];
                if (c >= kCCBMFontMaxChars)
                {
                    throw (new ArgumentException("LabelBMFont: character " + m_sString[i] + " outside of max font characters, which is " + kCCBMFontMaxChars));
                }
                if (c == '\n')
                {
                    nextFontPositionX  = 0;
                    nextFontPositionY -= (int)m_pConfiguration.m_uCommonHeight;
                    continue;
                }

                kerningAmount = this.kerningAmountForFirst(prev, c);

                if (!m_pConfiguration.m_pBitmapFontArray.ContainsKey(c))
                {
                    throw(new ArgumentException("Character " + c + " in LabelBMFont is not in the font definition."));
                }
                ccBMFontDef fontDef = m_pConfiguration.m_pBitmapFontArray[c];

                CCRect rect = fontDef.rect;

                CCSprite fontChar = (CCSprite)(this.getChildByTag(i));
                if (fontChar == null)
                {
                    fontChar = new CCSprite();
                    fontChar.initWithBatchNodeRectInPixels(this, rect);
                    this.addChild(fontChar, 0, i);
                }
                else
                {
                    // reusing fonts
                    //fontChar = new CCSprite();
                    fontChar.setTextureRectInPixels(rect, false, rect.size);

                    // restore to default in case they were modified
                    fontChar.visible = true;
                    fontChar.Opacity = 255;
                }

                float yOffset = (float)(m_pConfiguration.m_uCommonHeight - fontDef.yOffset);
                fontChar.positionInPixels = (new CCPoint(nextFontPositionX + fontDef.xOffset + fontDef.rect.size.width / 2.0f + kerningAmount,
                                                         (float)nextFontPositionY + yOffset - rect.size.height / 2.0f));

                //		NSLog(@"position.y: %f", fontChar.position.y);

                // update kerning
                nextFontPositionX += m_pConfiguration.m_pBitmapFontArray[c].xAdvance + kerningAmount;
                prev = c;

                // Apply label properties
                fontChar.IsOpacityModifyRGB = m_bIsOpacityModifyRGB;
                // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on
                fontChar.Color = m_tColor;

                // only apply opaccity if it is different than 255 )
                // to prevent modifying the color too (issue #610)
                if (m_cOpacity != 255)
                {
                    fontChar.Opacity = m_cOpacity;
                }

                if (longestLine < nextFontPositionX)
                {
                    longestLine = nextFontPositionX;
                }
            }

            tmpSize.width  = (float)longestLine;
            tmpSize.height = (float)totalHeight;

            this.contentSizeInPixels = tmpSize;
        }
Example #32
0
        public void createFontChars()
        {
            int    item            = 0;
            int    mUCommonHeight  = 0;
            int    num             = -1;
            int    num1            = 0;
            CCSize cCSize          = new CCSize(0f, 0f);
            int    num2            = 0;
            int    mUCommonHeight1 = 0;
            int    num3            = 1;
            int    length          = this.m_sString.Length;

            if (length == 0)
            {
                return;
            }
            for (int i = 0; i < length - 1; i++)
            {
                if (this.m_sString[i] == 10)
                {
                    num3++;
                }
            }
            mUCommonHeight1 = this.m_pConfiguration.m_uCommonHeight * num3;
            mUCommonHeight  = -(this.m_pConfiguration.m_uCommonHeight - this.m_pConfiguration.m_uCommonHeight * num3);
            for (int j = 0; j < length; j++)
            {
                int mSString = this.m_sString[j];
                if ((long)mSString >= (long)2048)
                {
                    object[] objArray = new object[] { "LabelBMFont: character ", this.m_sString[j], " outside of max font characters, which is ", (uint)2048 };
                    throw new ArgumentException(string.Concat(objArray));
                }
                if (mSString != 10)
                {
                    num1 = this.kerningAmountForFirst(num, mSString);
                    if (!this.m_pConfiguration.m_pBitmapFontArray.ContainsKey(mSString))
                    {
                        throw new ArgumentException(string.Concat("Character ", mSString, " in LabelBMFont is not in the font definition."));
                    }
                    ccBMFontDef _ccBMFontDef = this.m_pConfiguration.m_pBitmapFontArray[mSString];
                    CCRect      cCRect       = _ccBMFontDef.rect;
                    CCSprite    childByTag   = (CCSprite)base.getChildByTag(j);
                    if (childByTag != null)
                    {
                        childByTag.setTextureRectInPixels(cCRect, false, cCRect.size);
                        childByTag.visible = true;
                        childByTag.Opacity = 255;
                    }
                    else
                    {
                        childByTag = new CCSprite();
                        childByTag.initWithBatchNodeRectInPixels(this, cCRect);
                        this.addChild(childByTag, 0, j);
                    }
                    float single = (float)(this.m_pConfiguration.m_uCommonHeight - _ccBMFontDef.yOffset);
                    childByTag.positionInPixels = new CCPoint((float)(item + _ccBMFontDef.xOffset) + _ccBMFontDef.rect.size.width / 2f + (float)num1, (float)mUCommonHeight + single - cCRect.size.height / 2f);
                    item = item + this.m_pConfiguration.m_pBitmapFontArray[mSString].xAdvance + num1;
                    num  = mSString;
                    childByTag.IsOpacityModifyRGB = this.m_bIsOpacityModifyRGB;
                    childByTag.Color = this.m_tColor;
                    if (this.m_cOpacity != 255)
                    {
                        childByTag.Opacity = this.m_cOpacity;
                    }
                    if (num2 < item)
                    {
                        num2 = item;
                    }
                }
                else
                {
                    item           = 0;
                    mUCommonHeight = mUCommonHeight - this.m_pConfiguration.m_uCommonHeight;
                }
            }
            cCSize.width             = (float)num2;
            cCSize.height            = (float)mUCommonHeight1;
            base.contentSizeInPixels = cCSize;
        }
Example #33
0
        public int atlasIndexForChild(CCSprite pobSprite, int nZ)
        {
            List <Node> pBrothers = pobSprite.Parent.Children;

            uint uChildIndex = (uint)pBrothers.IndexOf(pobSprite);

            // ignore parent Z if parent is spriteSheet
            bool bIgnoreParent = pobSprite.Parent is CCSpriteBatchNode;

            CCSprite pPrevious = null;

            if (uChildIndex > 0 &&
                uChildIndex < 0xffffffff)
            {
                pPrevious = pBrothers[(int)(uChildIndex - 1)] as CCSprite;
            }

            // first child of the sprite sheet
            if (bIgnoreParent)
            {
                if (uChildIndex == 0)
                {
                    return(0);
                }

                return(highestAtlasIndexInChild(pPrevious) + 1);
            }

            // parent is a CCSprite, so, it must be taken into account

            // first child of an CCSprite ?
            if (uChildIndex == 0)
            {
                CCSprite p = pobSprite.Parent as CCSprite;

                if (p == null)
                {
                    return(0);
                }

                // less than parent and siblings
                if (nZ < 0)
                {
                    return(p.atlasIndex);
                }
                else
                {
                    return(p.atlasIndex + 1);
                }
            }
            else
            {
                // previous & sprite belong to the same branch
                if ((pPrevious.ZOrder < 0 && nZ < 0) || (pPrevious.ZOrder >= 0 && nZ >= 0))
                {
                    return(highestAtlasIndexInChild(pPrevious) + 1);
                }

                // else (previous < 0 and sprite >= 0 )
                CCSprite p = pobSprite.Parent as CCSprite;
                return(p.atlasIndex + 1);
            }

            // Should not happen. Error  calculating Z on SpriteSheet
            Debug.Assert(false);
            return(0);
        }
        /// <summary>
        ///  initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid
        /// </summary>
        public bool initWithWidthAndHeight(int w, int h, CCTexture2DPixelFormat eFormat)
        {
            // If the gles version is lower than GLES_VER_1_0,
            // some extended gles functions can't be implemented, so return false directly.
            if (CCConfiguration.sharedConfiguration().getGlesVersion() <= CCGlesVersion.GLES_VER_1_0)
            {
                return(false);
            }

            bool bRet = false;

            do
            {
                w *= (int)CCDirector.sharedDirector().ContentScaleFactor;
                h *= (int)CCDirector.sharedDirector().ContentScaleFactor;

                //glGetIntegerv(0x8CA6, m_nOldFBO);

                // textures must be power of two squared
                uint powW = (uint)ccUtils.ccNextPOT(w);
                uint powH = (uint)ccUtils.ccNextPOT(h);

                m_pTexture = new CCTexture2D();

                CCApplication app = CCApplication.sharedApplication();
                m_RenderTarget2D = new RenderTarget2D(app.GraphicsDevice, (int)w, (int)h);
                app.GraphicsDevice.SetRenderTarget(m_RenderTarget2D);
                app.GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(0, 0, 0, 0));


                m_pTexture.initWithTexture(m_RenderTarget2D);

                // generate FBO
                //ccglGenFramebuffers(1, &m_uFBO);
                //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_uFBO);

                // associate texture with FBO
                //ccglFramebufferTexture2D(CC_GL_FRAMEBUFFER, CC_GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_pTexture->getName(), 0);

                // check if it worked (probably worth doing :) )
                //GLuint status = ccglCheckFramebufferStatus(CC_GL_FRAMEBUFFER);
                //if (status != CC_GL_FRAMEBUFFER_COMPLETE)
                //{
                //    CCAssert(0, "Render Texture : Could not attach texture to framebuffer");
                //    CC_SAFE_DELETE(m_pTexture);
                //    break;
                //}

                //m_pTexture.setAliasTexParameters();

                m_pSprite = CCSprite.spriteWithTexture(m_pTexture);

                //m_pTexture->release();
                //m_pSprite.scaleY = -1;
                this.addChild(m_pSprite);

                ccBlendFunc tBlendFunc = new ccBlendFunc {
                    src = 1, dst = 0x0303
                };
                m_pSprite.BlendFunc = tBlendFunc;

                //ccglBindFramebuffer(CC_GL_FRAMEBUFFER, m_nOldFBO);
                bRet = true;
            } while (false);

            return(bRet);
        }