コード例 #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;
 }
コード例 #2
0
ファイル: TileDemo.cs プロジェクト: Ratel13/cocos2d-x-for-xna
        public TileDemo()
        {
            base.isTouchEnabled = true;

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

            m_label = CCLabelTTF.labelWithString("not", "Arial", 28);
            addChild(m_label, 1);
            m_label.position = new CCPoint(s.width / 2, s.height - 50);

            string strSubtitle = subtitle();
            if (strSubtitle == null)
            {
                CCLabelTTF l = CCLabelTTF.labelWithString(strSubtitle, "Arial", 16);
                addChild(l, 1);
                l.position = new CCPoint(s.width / 2, s.height - 80);

                m_subtitle = l;
            }

            CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage(s_pPathB1, s_pPathB2, this, backCallback);
            CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage(s_pPathR1, s_pPathR2, this, restartCallback);
            CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage(s_pPathF1, s_pPathF2, this, 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);

            CCMenu menu = CCMenu.menuWithItems(item1, item2, item3);
            menu.position = new CCPoint(0, 0);
            addChild(menu, 1);
        }
コード例 #3
0
 public GameOverScene(bool isWin)
 {
     CCLayerColor colorLayer = CCLayerColor.layerWithColor(new ccColor4B(255, 255, 255, 255));
     this.addChild(colorLayer);
     CCSize winSize = CCDirector.sharedDirector().getWinSize();
     string msg;
     if (isWin)
         msg = "YOU WIN";
     else
         msg = "YOU LOSE";
     label = CCLabelTTF.labelWithString(msg, "Arial", 32);
     label.Color = new ccColor3B(0, 0, 0);
     label.position = new CCPoint(winSize.width / 2, winSize.height / 2 + 100);
     this.addChild(label);
     //this.runAction(CCSequence.actions(CCDelayTime.actionWithDuration(3), CCCallFunc.actionWithTarget(this, gameOverDone)));
     var itemReplay = CCMenuItemImage.itemFromNormalImage(@"images/reload", @"images/reload", this, replay);
     var itemMainMenu = CCMenuItemImage.itemFromNormalImage(@"images/mainmenu", @"images/mainmenu", this, mainmenu);
     var itemNextLevel = CCMenuItemImage.itemFromNormalImage(@"images/nextlevel", @"images/nextlevel", this, nextlevel);
     if (!isWin)
         itemNextLevel.visible = false;
     var menu = CCMenu.menuWithItems(itemReplay, itemMainMenu, itemNextLevel);
     menu.alignItemsHorizontally();
     menu.position = new CCPoint(winSize.width / 2, winSize.height / 2 - 100);
     this.addChild(menu);
 }
コード例 #4
0
ファイル: PauseTest.cs プロジェクト: homocury/cocos2d-xna
        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);
        }
コード例 #5
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize s = CCDirector.SharedDirector.WinSize;

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

            string strSubtitle = subtitle();
            if (!string.IsNullOrEmpty(strSubtitle))
            {
                CCLabelTTF l = new CCLabelTTF(strSubtitle, "arial", 16);
                //CCLabelTTF l = CCLabelTTF.labelWithString(strSubtitle, "Thonburi", 16);
                AddChild(l, 1);
                l.Position = new CCPoint(s.Width / 2, s.Height - 80);
            }

            CCMenuItemImage item1 = new CCMenuItemImage("Images/b1", "Images/b2", backCallback);
            CCMenuItemImage item2 = new CCMenuItemImage("Images/r1", "Images/r2", restartCallback);
            CCMenuItemImage item3 = new CCMenuItemImage("Images/f1", "Images/f2", nextCallback);

            CCMenu menu = CCMenu.Create(item1, item2, item3);

            menu.Position = new CCPoint();
            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);
        }
コード例 #6
0
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize s = CCDirector.SharedDirector.WinSize;

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

            string strSubtitle = subtitle();
            if (!string.IsNullOrEmpty(strSubtitle))
            {
                CCLabelTTF l = new CCLabelTTF(strSubtitle, "arial", 16);
                AddChild(l, 1);
                l.Position = (new CCPoint(s.Width / 2, s.Height - 80));
            }

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

            CCMenu menu = CCMenu.Create(item1, item2, item3);

            menu.Position = new CCPoint(0, 0);
            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);
        }
コード例 #7
0
ファイル: ParallaxDemo.cs プロジェクト: HarkDev/cocos2d-xna
        public override void OnEnter()
        {
            base.OnEnter();

            CCApplication.SharedApplication.GamePadButtonUpdate += _GamePadButtonDelegate;
            CCApplication.SharedApplication.GamePadDPadUpdate += _GamePadDPadDelegate;
            CCApplication.SharedApplication.GamePadStickUpdate += _GamePadStickDelegate;
            CCApplication.SharedApplication.GamePadTriggerUpdate += _GamePadTriggerDelegate;

            CCSize s = CCDirector.SharedDirector.WinSize;

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

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

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

            menu.Position = new CCPoint(0, 0);
            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);
        }
コード例 #8
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;
        }
コード例 #9
0
 public LabelTTFChinese()
 {
     CCSize size = CCDirector.SharedDirector.WinSize;
     CCLabelTTF pLable = new CCLabelTTF("中国", "Marker Felt", 30);
     pLable.Position = new CCPoint(size.Width / 2, size.Height / 2);
     AddChild(pLable);
 }
コード例 #10
0
ファイル: SpriteDemo.cs プロジェクト: HarkDev/cocos2d-xna
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize s = CCDirector.SharedDirector.WinSize;

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

            string strSubtitle = subtitle();
            if (strSubtitle != null)
            {
                CCLabelTTF l = new CCLabelTTF(strSubtitle, "arial", 22);
                AddChild(l, 1);
                l.Position = new CCPoint(s.Width / 2, s.Height - 80);
            }

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

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

            menu.Position = new CCPoint(0, 0);
            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);

            CCLayerColor background = new CCLayerColor(new CCColor4B(255,0,0,255));
            AddChild(background, -10);
        }
コード例 #11
0
ファイル: Layertest.cs プロジェクト: HarkDev/cocos2d-xna
        public override void OnEnter()
        {
            base.OnEnter();

            CCSize s = CCDirector.SharedDirector.WinSize;

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

            string subtitle_ = subtitle();
            if (subtitle_.Length > 0)
            {
                CCLabelTTF l = new CCLabelTTF(subtitle_, "arial", 16);
                AddChild(l, 1);
                l.Position = (new CCPoint(s.Width / 2, s.Height - 80));
            }

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

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

            menu.Position = new CCPoint(0, 0);
            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);
        }
コード例 #12
0
ファイル: Box2DTest.cs プロジェクト: eickegao/cocos2d-xna
        public Box2DTestLayer()
        {
            TouchEnabled = true;
            AccelerometerEnabled = true;
            CCSize s = CCDirector.SharedDirector.WinSize;
            // init physics
            initPhysics();
            // create reset button
            createResetButton();

            //Set up sprite
            // Use batch node. Faster
            _batch = CCSpriteBatchNode.Create("Images/blocks", 100);
            m_pSpriteTexture = _batch.Texture;
            AddChild(_batch, 0, kTagParentNode);

            addNewSpriteAtPosition(new CCPoint(s.Width / 2, s.Height / 2));

            CCLabelTTF label = new CCLabelTTF("Tap screen", "Marker Felt", 32);
            AddChild(label, 0);
            label.Color = new CCColor3B(0, 0, 255);
            label.Position = new CCPoint(s.Width / 2, s.Height - 50);

            ScheduleUpdate();
        }
コード例 #13
0
ファイル: GitHubIssue5.cs プロジェクト: homocury/cocos2d-xna
 public GitHubIssue5()
 {
     CCSize s = CCDirector.SharedDirector.WinSize;
     _TestLabel = new CCLabelTTF("", "Arial", 10);
     AddChild(_TestLabel);
     _TestLabel.Position = new CCPoint(s.Width / 2, s.Height / 4 * 2);
 }
コード例 #14
0
 public virtual void setDisplayValueLabel(CCLabelTTF var)
 {
     if (m_pDisplayValueLabel != var)
     {
         m_pDisplayValueLabel = var;
     }
 }
コード例 #15
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);
        }
コード例 #16
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;
        }
コード例 #17
0
        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;
        }
コード例 #18
0
ファイル: TextLayer.cs プロジェクト: KogleDK/cocos2d-xna-1
        public TextLayer()
        {
            InitWithColor(CCTypes.CreateColor(32, 32, 32, 255));

            float x, y;

            CCSize size = CCDirector.SharedDirector.WinSize;
            x = size.Width;
            y = size.Height;

            CCNode node = new CCNode ();
            CCActionInterval effect = getAction();
            node.RunAction(effect);
            AddChild(node, 0, EffectTestScene.kTagBackground);

            CCSprite bg = new CCSprite(TestResource.s_back3);
            node.AddChild(bg, 0);
            bg.AnchorPoint = new CCPoint(0.5f, 0.5f);
            bg.Position = new CCPoint(size.Width / 2, size.Height / 2);

            CCSprite grossini = new CCSprite(TestResource.s_pPathSister2);
            node.AddChild(grossini, 1);
            grossini.Position = new CCPoint(x / 3, y / 2);
            CCActionInterval sc = new CCScaleBy(2, 5);
            CCFiniteTimeAction sc_back = sc.Reverse();
            grossini.RunAction(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(sc, sc_back))));
            //grossini.runAction(effect);

            CCSprite tamara = new CCSprite(TestResource.s_pPathSister1);
            node.AddChild(tamara, 1);
            tamara.Position = new CCPoint(2 * x / 3, y / 2);
            CCActionInterval sc2 = new CCScaleBy(2, 5);
            CCFiniteTimeAction sc2_back = sc2.Reverse();
            tamara.RunAction(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(sc2, sc2_back))));

            CCLabelTTF label = new CCLabelTTF(EffectTestScene.effectsList[EffectTestScene.actionIdx], "arial", 32);

            label.Position = new CCPoint(x / 2, y - 80);
            AddChild(label);
            label.Tag = EffectTestScene.kTagLabel;

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

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

            menu.Position = new CCPoint(0, 0);
            item1.Position = new CCPoint(size.Width / 2 - 100, 30);
            item2.Position = new CCPoint(size.Width / 2, 30);
            item3.Position = new CCPoint(size.Width / 2 + 100, 30);

            AddChild(menu, 1);

            Schedule(checkAnim);
        }
コード例 #19
0
        /// <summary>
        /// creates a CCLabelTTF from a fontname, alignment, dimension and font size
        /// </summary>
        public static CCLabelTTF labelWithString(string label, CCSize dimensions, CCTextAlignment alignment, string fontName, float fontSize)
        {
            CCLabelTTF pRet = new CCLabelTTF();
            if (pRet != null && pRet.initWithString(label, dimensions, alignment, fontName, fontSize))
            {
                return pRet;
            }

            return null;
        }
コード例 #20
0
        /// <summary>
        /// creates a CCLabelTTF from a fontname and font size
        /// </summary>
        public static CCLabelTTF labelWithString(string label, string fontName, float fontSize)
        {
            CCLabelTTF pRet = new CCLabelTTF();
            if (pRet.initWithString(label, fontName, fontSize))
            {
                return pRet;
            }

            return null;
        }
コード例 #21
0
ファイル: FontTest.cs プロジェクト: HarkDev/cocos2d-xna
        public void showFont(string pFont)
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            var blockSize = new CCSize(s.Width / 3, 200);
            float fontSize = 26;

            RemoveChildByTag(kTagLabel1, true);
            RemoveChildByTag(kTagLabel2, true);
            RemoveChildByTag(kTagLabel3, true);
            RemoveChildByTag(kTagLabel4, true);

            CCLabelTTF top = new CCLabelTTF(pFont, pFont, 24);
            CCLabelTTF left = new CCLabelTTF("alignment left", pFont, fontSize,
                                                blockSize, CCTextAlignment.CCTextAlignmentLeft,
                                                FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]);
            CCLabelTTF center = new CCLabelTTF("alignment center", pFont, fontSize,
                                                  blockSize, CCTextAlignment.CCTextAlignmentCenter,
                                                  FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]);
            CCLabelTTF right = new CCLabelTTF("alignment right", pFont, fontSize,
                                                 blockSize, CCTextAlignment.CCTextAlignmentRight,
                                                 FontTestScene.verticalAlignment[FontTestScene.vAlignIdx]);

            CCLayerColor leftColor = new CCLayerColor(new CCColor4B(100, 100, 100, 255), blockSize.Width, blockSize.Height);
            CCLayerColor centerColor = new CCLayerColor(new CCColor4B(200, 100, 100, 255), blockSize.Width, blockSize.Height);
            CCLayerColor rightColor = new CCLayerColor(new CCColor4B(100, 100, 200, 255), blockSize.Width, blockSize.Height);

            leftColor.IgnoreAnchorPointForPosition = false;
            centerColor.IgnoreAnchorPointForPosition = false;
            rightColor.IgnoreAnchorPointForPosition = false;

            top.AnchorPoint = new CCPoint(0.5f, 1);
            left.AnchorPoint = new CCPoint(0, 0.5f);
            leftColor.AnchorPoint = new CCPoint(0, 0.5f);
            center.AnchorPoint = new CCPoint(0, 0.5f);
            centerColor.AnchorPoint = new CCPoint(0, 0.5f);
            right.AnchorPoint = new CCPoint(0, 0.5f);
            rightColor.AnchorPoint = new CCPoint(0, 0.5f);

            top.Position = new CCPoint(s.Width / 2, s.Height - 20);
            left.Position = new CCPoint(0, s.Height / 2);
            leftColor.Position = left.Position;
            center.Position = new CCPoint(blockSize.Width, s.Height / 2);
            centerColor.Position = center.Position;
            right.Position = new CCPoint(blockSize.Width * 2, s.Height / 2);
            rightColor.Position = right.Position;

            AddChild(leftColor, -1);
            AddChild(left, 0, kTagLabel1);
            AddChild(rightColor, -1);
            AddChild(right, 0, kTagLabel2);
            AddChild(centerColor, -1);
            AddChild(center, 0, kTagLabel3);
            AddChild(top, 0, kTagLabel4);
        }
コード例 #22
0
        public override void OnEnter()
        {
            base.OnEnter();

            float x, y;

            CCSize size = CCDirector.SharedDirector.WinSize;
            x = size.Width;
            y = size.Height;

            CCSprite bg = new CCSprite("Images/background3");
            AddChild(bg, 0, EffectAdvanceScene.kTagBackground);
            bg.Position = new CCPoint(x / 2, y / 2);

            grossini = new CCSprite("Images/grossinis_sister2");
            bg.AddChild(grossini, 1, EffectAdvanceScene.kTagSprite1);
            grossini.Position = new CCPoint(x / 3.0f, 200);
            CCActionInterval sc = new CCScaleBy(2, 5);
            CCFiniteTimeAction sc_back = sc.Reverse();
            grossini.RunAction(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(sc, sc_back))));

            tamara = new CCSprite("Images/grossinis_sister1");
            bg.AddChild(tamara, 1, EffectAdvanceScene.kTagSprite2);
            tamara.Position = new CCPoint(2 * x / 3.0f, 200);
            CCActionInterval sc2 = new CCScaleBy(2, 5);
            CCFiniteTimeAction sc2_back = sc2.Reverse();
            tamara.RunAction(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(sc2, sc2_back))));

            CCLabelTTF label = new CCLabelTTF(title(), "arial", 28);

            label.Position = new CCPoint(x / 2, y - 80);
            AddChild(label);
            label.Tag = EffectAdvanceScene.kTagLabel;

            string strSubtitle = subtitle();
            if (strSubtitle != null)
            {
                CCLabelTTF l = new CCLabelTTF(strSubtitle, "arial", 16);
                AddChild(l, 101);
                l.Position = new CCPoint(size.Width / 2, size.Height - 80);
            }

            CCMenuItemImage item1 = new CCMenuItemImage("Images/b1", "Images/b2", backCallback);
            CCMenuItemImage item2 = new CCMenuItemImage("Images/r1", "Images/r2", restartCallback);
            CCMenuItemImage item3 = new CCMenuItemImage("Images/f1", "Images/f2", nextCallback);

            CCMenu menu = CCMenu.Create(item1, item2, item3);

            menu.Position = new CCPoint(0, 0);
            item1.Position = new CCPoint(size.Width / 2 - 100, 30);
            item2.Position = new CCPoint(size.Width / 2, 30);
            item3.Position = new CCPoint(size.Width / 2 + 100, 30);

            AddChild(menu, 1);
        }
コード例 #23
0
        public LabelTTFMultiline()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // CCLabelBMFont
            CCLabelTTF center = new CCLabelTTF("word wrap \"testing\" (bla0) bla1 'bla2' [bla3] (bla4) {bla5} {bla6} [bla7] (bla8) [bla9] 'bla0' \"bla1\"",
                "Paint Boy", 32,
                new CCSize(s.Width / 2, 200),
                CCTextAlignment.CCTextAlignmentCenter);
            center.Position = new CCPoint(s.Width / 2, 150);

            AddChild(center);
        }
コード例 #24
0
        public CocosDenshionTest()
        {
            m_pItmeMenu = null;
            m_tBeginPos = new CCPoint(0,0);
            m_nSoundId = 0;

            string[] testItems = {
                "play background music",
                "stop background music",
                "pause background music",
                "resume background music",
                "rewind background music",
                "is background music playing",
                "play effect",
                "play effect repeatly",
                "stop effect",
                "unload effect",
                "add background music volume",
                "sub background music volume",
                "add effects volume",
                "sub effects volume"
            };

            // add menu items for tests
            m_pItmeMenu = new CCMenu(null);
            CCSize s = CCDirector.SharedDirector.WinSize;
            m_nTestCount = testItems.Count<string>();

            for (int i = 0; i < m_nTestCount; ++i)
            {
                CCLabelTTF label = new CCLabelTTF(testItems[i], "arial", 24);
                CCMenuItemLabel pMenuItem = CCMenuItemLabel.Create(label, new SEL_MenuHandler(menuCallback));

                m_pItmeMenu.AddChild(pMenuItem, i + 10000);
                pMenuItem.Position = new CCPoint( s.Width / 2, (s.Height - (i + 1) * LINE_SPACE) );
            }

            m_pItmeMenu.ContentSize = new CCSize(s.Width, (m_nTestCount + 1) * LINE_SPACE);
            m_pItmeMenu.Position = new CCPoint(0,0);
            AddChild(m_pItmeMenu);

            this.TouchEnabled = true;

            // preload background music and effect
            SimpleAudioEngine.SharedEngine.PreloadBackgroundMusic(CCFileUtils.FullPathFromRelativePath(MUSIC_FILE));
            SimpleAudioEngine.SharedEngine.PreloadEffect(CCFileUtils.FullPathFromRelativePath(EFFECT_FILE));

            // set default volume
            SimpleAudioEngine.SharedEngine.EffectsVolume = 0.5f;
            SimpleAudioEngine.SharedEngine.BackgroundMusicVolume = 0.5f;
        }
コード例 #25
0
ファイル: TestLayer.cs プロジェクト: HarkDev/cocos2d-xna
 public override void OnEnter()
 {
     base.OnEnter();
     float x, y;
     CCSize size = CCDirector.SharedDirector.WinSize;
     x = size.Width;
     y = size.Height;
     //CCMutableArray *array = [UIFont familyNames];
     //for( CCString *s in array )
     //	NSLog( s );
     CCLabelTTF label = new CCLabelTTF("cocos2d", "arial", 64);
     label.Position = new CCPoint(x / 2, y / 2);
     AddChild(label);
 }
コード例 #26
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                CCNode layer = new CCNode ();
                layer.Position = new CCPoint(screenSize.Width / 2, screenSize.Height / 2);
                AddChild(layer, 1);

                float layer_width = 0.0f;

                // Add the black background for the text
                CCScale9Sprite background = CCScale9Sprite.Create("extensions/buttonBackground");
                background.ContentSize = new CCSize(80, 50);
                background.Position = new CCPoint(layer_width + background.ContentSize.Width / 2.0f, 0);
                layer.AddChild(background);

                layer_width += background.ContentSize.Width;

                m_pDisplayValueLabel = new CCLabelTTF("#color", "Marker Felt", 30);

                m_pDisplayValueLabel.Position = background.Position;
                layer.AddChild(m_pDisplayValueLabel);

                // Create the switch
                CCControlSwitch switchControl = CCControlSwitch.Create
                    (
                        new CCSprite("extensions/switch-mask"),
                        new CCSprite("extensions/switch-on"),
                        new CCSprite("extensions/switch-off"),
                        new CCSprite("extensions/switch-thumb"),
                        new CCLabelTTF("On", "Arial-BoldMT", 16),
                        new CCLabelTTF("Off", "Arial-BoldMT", 16)
                    );
                switchControl.Position = new CCPoint(layer_width + 10 + switchControl.ContentSize.Width / 2, 0);
                layer.AddChild(switchControl);

                switchControl.AddTargetWithActionForControlEvents(this, valueChanged, CCControlEvent.ValueChanged);

                // Set the layer size
                layer.ContentSize = new CCSize(layer_width, 0);
                layer.AnchorPoint = new CCPoint(0.5f, 0.5f);

                // Update the value label
                valueChanged(switchControl, CCControlEvent.ValueChanged);
                return true;
            }
            return false;
        }
コード例 #27
0
        /** initializes a menu item from a string with a target/selector */
        public bool initFromString(string value, SelectorProtocol target, SEL_MenuHandler selector)
        {
            //CCAssert( value != NULL && strlen(value) != 0, "Value length must be greater than 0");

            m_strFontName = _fontName;
            m_uFontSize   = _fontSize;

            CCLabelTTF label = CCLabelTTF.labelWithString(value, m_strFontName, (float)m_uFontSize);

            if (base.initWithLabel(label, target, selector))
            {
                // do something ?
            }

            return(true);
        }
コード例 #28
0
        public override void OnEnter()
        {
            base.OnEnter();

            AccelerometerEnabled = true;

            CCSize s = CCDirector.SharedDirector.WinSize;

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

            m_pBall = new CCSprite("Images/ball");
            m_pBall.Position = new CCPoint(s.Width / 2, s.Height / 2);
            AddChild(m_pBall);
        }
コード例 #29
0
        public override bool Init()
        {
            if (base.Init())
            {
                CCSize screenSize = CCDirector.SharedDirector.WinSize;

                // Add a label in which the button events will be displayed
                setDisplayValueLabel(new CCLabelTTF("No Event", "Marker Felt", 32));
                m_pDisplayValueLabel.AnchorPoint = new CCPoint(0.5f, -1);
                m_pDisplayValueLabel.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(m_pDisplayValueLabel, 1);

                // Add the button
                var backgroundButton = CCScale9Sprite.Create("extensions/button");
                var backgroundHighlightedButton = CCScale9Sprite.Create("extensions/buttonHighlighted");

                var titleButton = new CCLabelTTF("Touch Me!", "Marker Felt", 30);

                titleButton.Color = new CCColor3B(159, 168, 176);

                var controlButton = CCControlButton.Create(titleButton, backgroundButton);
                controlButton.SetBackgroundSpriteForState(backgroundHighlightedButton, CCControlState.Highlighted);
                controlButton.SetTitleColorForState(CCTypes.CCWhite, CCControlState.Highlighted);

                controlButton.AnchorPoint = new CCPoint(0.5f, 1);
                controlButton.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(controlButton, 1);

                // Add the black background
                var background = CCScale9Sprite.Create("extensions/buttonBackground");
                background.ContentSize = new CCSize(300, 170);
                background.Position = new CCPoint(screenSize.Width / 2.0f, screenSize.Height / 2.0f);
                AddChild(background);

                // Sets up event handlers
                controlButton.AddTargetWithActionForControlEvent(this, touchDownAction, CCControlEvent.TouchDown);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragInsideAction, CCControlEvent.TouchDragInside);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragOutsideAction, CCControlEvent.TouchDragOutside);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragEnterAction, CCControlEvent.TouchDragEnter);
                controlButton.AddTargetWithActionForControlEvent(this, touchDragExitAction, CCControlEvent.TouchDragExit);
                controlButton.AddTargetWithActionForControlEvent(this, touchUpInsideAction, CCControlEvent.TouchUpInside);
                controlButton.AddTargetWithActionForControlEvent(this, touchUpOutsideAction, CCControlEvent.TouchUpOutside);
                controlButton.AddTargetWithActionForControlEvent(this, touchCancelAction, CCControlEvent.TouchCancel);
                return true;
            }
            return false;
        }
コード例 #30
0
ファイル: testBasic.cs プロジェクト: homocury/cocos2d-xna
        public override void OnEnter()
        {
            base.OnEnter();

            //add the menu item for back to main menu
            CCLabelTTF label = new CCLabelTTF("MainMenu", "arial", 20);
            CCMenuItemLabel pMenuItem = CCMenuItemLabel.Create(label, MainMenuCallback);

            CCMenu pMenu = CCMenu.Create(pMenuItem);
            CCSize s = CCDirector.SharedDirector.WinSize;
            pMenu.Position = CCPoint.Zero;
            pMenuItem.Position = new CCPoint(s.Width - 50, 25);

            AddChild(pMenu, 1);
            CCApplication.SharedApplication.GamePadDPadUpdate += _GamePadDPadDelegate;
            CCApplication.SharedApplication.GamePadButtonUpdate += _GamePadButtonDelegate;
        }
コード例 #31
0
        public virtual void initWithQuantityOfNodes(int nNodes)
        {
            //srand(time());
            CCSize s = CCDirector.SharedDirector.WinSize;

            // Title
            CCLabelTTF label = new CCLabelTTF(title(), "arial", 32);
            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)
            {
                CCLabelTTF l = new CCLabelTTF(strSubTitle, "arial", 16);
                AddChild(l, 1);
                l.Position = new CCPoint(s.Width / 2, s.Height - 80);
            }

            lastRenderedCount = 0;
            currentQuantityOfNodes = 0;
            quantityOfNodes = nNodes;

            CCMenuItemFont.FontSize = 64;
            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);

            CCLabelTTF infoLabel = new CCLabelTTF("0 nodes", "arial", 30);
            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();
        }
コード例 #32
0
        public void updateStrings(float dt)
        {
            CCLabelBMFont label1 = (CCLabelBMFont)getChildByTag((int)TagSprite.kTagBitmapAtlas1);
            CCLabelTTF    label2 = (CCLabelTTF)getChildByTag((int)TagSprite.kTagBitmapAtlas2);
            CCLabelAtlas  label3 = (CCLabelAtlas)getChildByTag((int)TagSprite.kTagBitmapAtlas3);

            if (!setEmpty)
            {
                label1.setString("not empty");
                label2.setString("not empty");
                label3.setString("hi");

                setEmpty = true;
            }
            else
            {
                label1.setString("");
                label2.setString("");
                label3.setString("");

                setEmpty = false;
            }
        }
コード例 #33
0
        public virtual bool onTextFieldDeleteBackward(CCTextFieldTTF pSender, string delText, int nLen)
        {
            // create a delete text sprite and do some action
            CCLabelTTF label = CCLabelTTF.labelWithString(delText, TextInputTestScene.FONT_NAME, TextInputTestScene.FONT_SIZE);

            this.addChild(label);

            // move the sprite to fly out
            CCPoint beginPos      = pSender.position;
            CCSize  textfieldSize = pSender.contentSize;
            CCSize  labelSize     = label.contentSize;

            beginPos.x += (textfieldSize.width - labelSize.width) / 2.0f;

            int    RAND_MAX = 32767;
            Random rand     = new Random();

            CCSize  winSize        = CCDirector.sharedDirector().getWinSize();
            CCPoint endPos         = new CCPoint(-winSize.width / 4.0f, winSize.height * (0.5f + (float)rand.Next() / (2.0f * RAND_MAX)));
            float   duration       = 1;
            float   rotateDuration = 0.2f;
            int     repeatTime     = 5;

            label.position = beginPos;

            CCAction seq = CCSequence.actions(
                CCSpawn.actions(
                    CCMoveTo.actionWithDuration(duration, endPos),
                    CCRepeat.actionWithAction(
                        CCRotateBy.actionWithDuration(rotateDuration, (rand.Next() % 2 > 0) ? 360 : -360),
                        (uint)repeatTime),
                    CCFadeOut.actionWithDuration(duration)),
                CCCallFuncN.actionWithTarget(this, callbackRemoveNodeWhenDidAction));

            label.runAction(seq);
            return(false);
        }