Пример #1
0
        /** Creates and returns a new ControlStepper. */

        public CCControlStepper MakeControlStepper()
        {
            var minusSprite = new CCSprite("extensions/stepper-minus.png");
            var plusSprite = new CCSprite("extensions/stepper-plus.png");

            return new CCControlStepper(minusSprite, plusSprite);
        }
Пример #2
0
        protected override void AddedToScene()
        {
            base.AddedToScene();

            CCSize s = Layer.VisibleBoundsWorldspace.Size;

			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;

			Schedule ();
		}
Пример #3
0
 private void performanceRotationScale(CCSprite pSprite)
 {
     CCSize size = Layer.VisibleBoundsWorldspace.Size;
     pSprite.Position = new CCPoint((CCRandom.Next() % (int)size.Width), (CCRandom.Next() % (int)size.Height));
     pSprite.Rotation = CCRandom.Float_0_1() * 360;
     pSprite.Scale = CCRandom.Float_0_1() * 2;
 }
Пример #4
0
        public SpriteFrameTest()
        {
            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");
            cache.AddSpriteFrames("animations/grossini_blue.plist", "animations/grossini_blue");

            var animFrames = new List<CCSpriteFrame>(15);

            string str = "";
            for (int i = 1; i < 15; i++)
            {
                str = string.Format("grossini_dance_{0:00}.png", i);
                CCSpriteFrame frame = cache[str];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.3f);

            var moreFrames = new List<CCSpriteFrame>(20);
            for (int i = 1; i < 15; i++)
            {
                string temp;
                str = string.Format("grossini_dance_gray_{0:00}.png", i);
                CCSpriteFrame frame = cache[str];
                moreFrames.Add(frame);
            }


            for (int i = 1; i < 5; i++)
            {
                str = string.Format("grossini_blue_{0:00}.png", i);
                CCSpriteFrame frame = cache[str];
                moreFrames.Add(frame);
            }

            // append frames from another batch
            moreFrames.AddRange(animFrames);

            animMixed = new CCAnimation(moreFrames, 0.3f);


            CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini");
            AddChild(spritebatch);

            sprite1 = new CCSprite("grossini_dance_01.png");
            spritebatch.AddChild(sprite1);

            // to test issue #732, uncomment the following line
            sprite1.FlipX = false;
            sprite1.FlipY = false;

            // Animation using standard Sprite
            sprite2 = new CCSprite("grossini_dance_01.png");
            AddChild(sprite2);

            // to test issue #732, uncomment the following line
            sprite2.FlipX = false;
            sprite2.FlipY = false;
        }
Пример #5
0
        public override void OnEnter()
        {
            base.OnEnter();

            float x, y;

            CCSize size = Layer.VisibleBoundsWorldspace.Size;
            x = size.Width;
            y = size.Height;

            CCSprite sprite = new CCSprite(grossini);
            CCSprite spriteSister1 = new CCSprite(sister1);
            CCSprite spriteSister2 = new CCSprite(sister2);

            sprite.Scale = 1.5f;
            spriteSister1.Scale = 1.5f;
            spriteSister2.Scale = 1.5f;

            sprite.Position = size.Center;
            spriteSister1.Position = (new CCPoint(40, y / 2));
            spriteSister2.Position = (new CCPoint(x - 40, y / 2));

            AddChild(sprite);
            AddChild(spriteSister1);
            AddChild(spriteSister2);

            sprite.RunAction(rot);

			spriteSister1.Repeat (5, jump2, jump1);
			spriteSister2.Repeat (5, jump1, jump2);

			spriteSister1.Repeat (5, rot1, rot2);
			spriteSister2.Repeat (5, rot2, rot1);
        }
Пример #6
0
        public SpriteBatchNodeZVertex()
        {
            //
            // This test tests z-order
            // If you are going to use it is better to use a 3D projection
            //
            // WARNING:
            // The developer is resposible for ordering it's sprites according to it's Z if the sprite has
            // transparent parts.
            //

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

            sprites = new CCSprite[numOfSprites];

            for (int i = 0; i < 5; i++)
            {
                sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
                sprites[i].VertexZ = (10 + i * 40);
                batch.AddChild(sprites[i], 0);
            }

            for (int i = 5; i < 11; i++)
            {
                sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121));
                sprites[i].VertexZ = 10 + (10 - i) * 40;
                batch.AddChild(sprites[i], 0);
            }

        }
Пример #7
0
		public override void OnEnter()
		{
			base.OnEnter();

			var s = Layer.VisibleBoundsWorldspace.Size;

			var sprite = new CCSprite("Images/grossinis_sister1.png");
			sprite.Position = VisibleBoundsWorldspace.Center;
			AddChild(sprite);
			sprite.RepeatForever(rotateBy);

			// Add a menu item to resume the Scheduled actions.

			CCMenuItemFont.FontSize = 32;
			CCMenuItemFont.FontName = "MarkerFelt";
			var menu = new CCMenu(
				new CCMenuItemFont("Resume", resume)
			);

			menu.AlignItemsVertically(4);
			menu.Position = new CCPoint(s.Width / 2, s.Height / 4);
			AddChild(menu);


			Schedule ();
			Schedule (tick1, 0.5f);
			Schedule (tick2, 1.0f);
			Schedule (pause, 3.0f, 0, 0);
		}
Пример #8
0
        void AddNewSpriteWithCoords(CCPoint p)
        {
            CCSpriteBatchNode BatchNode = (CCSpriteBatchNode)this[(int)kTags.kTagSpriteBatchNode];

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


            CCSprite sprite = new CCSprite(BatchNode.Texture, new CCRect(x, y, 85, 121));
            sprite.Position = (new CCPoint(p.X, p.Y));
            BatchNode.AddChild(sprite);


            CCFiniteTimeAction action = null;
            var random = (float)CCRandom.NextDouble();

            if (random < 0.20)
                action = scaleBy;
            else if (random < 0.40)
                action = rotateBy;
            else if (random < 0.60)
                action = blink;
            else if (random < 0.8)
                action = tintBy;
            else
                action = fadeOut;

            sprite.RepeatForever(action, action.Reverse());

        }
Пример #9
0
        public PopUpLayer(CCSprite background, CCLabel title)
        {
            mBackgroundImage = background;
            mTitle = title;

            CreateLayer ();
        }
Пример #10
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));

            CCFiniteTimeAction rot = new CCRotateBy (2, 360);
            var rot_back = rot.Reverse();
			var forever1 = new CCRepeatForever (rot, rot_back);

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

            sp1.RunAction(forever1);
            sp11.RunAction(forever1);
			sp2.RunAction(forever1);
            sp21.RunAction(forever1);

            Schedule(addAndRemove, 2.0f);
        }
Пример #11
0
        public StressTest1()
        {
			var sp1 = new CCSprite(TestResource.s_pPathSister1);
            AddChild(sp1, 0, CocosNodeTestStaticLibrary.kTagSprite1);

            Schedule(shouldNotCrash, 1.0f);
        }
Пример #12
0
        public SpriteZVertex()
        {
            //
            // This test tests z-order
            // If you are going to use it is better to use a 3D projection
            //
            // WARNING:
            // The developer is resposible for ordering it's sprites according to it's Z if the sprite has
            // transparent parts.
            //

            dir = 1;
            time = 0;
            sprites = new CCSprite[numOfSprites];

            node = new CCNode();
            AddChild(node, 0);

            for (int i = 0; i < 5; i++)
            {
                CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 0, 121 * 1, 85, 121));
                node.AddChild(sprite, 0);
                sprites[i] = sprite;
            }

            for (int i = 5; i < 11; i++)
            {
                CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 0, 85, 121));
                node.AddChild(sprite, 0);
                sprites[i] = sprite;
            }
        }
Пример #13
0
        public TextLayer() : base()
        {

            Color = new CCColor3B(32, 128, 32);
            Opacity = 255;

            BaseNode = new CCNodeGrid();
            var effect = CurrentAction;
            BaseNode.RunAction(effect);
            AddChild(BaseNode, 0, EffectTestScene.kTagBackground);

            var bg = new CCSprite(TestResource.s_back3);
            BaseNode.AddChild(bg, 0);

            var Kathia = new CCSprite(TestResource.s_pPathSister2);
            BaseNode.AddChild(Kathia, 1, EffectTestScene.kTagKathia);

            var sc = new CCScaleBy(2, 5);
            var sc_back = sc.Reverse();
            Kathia.RunAction(new CCRepeatForever(sc, sc_back));


            var Tamara = new CCSprite(TestResource.s_pPathSister1);
            BaseNode.AddChild(Tamara, 1, EffectTestScene.kTagTamara);

            var sc2 = new CCScaleBy(2, 5);
            var sc2_back = sc2.Reverse();
            Tamara.RunAction(new CCRepeatForever(sc2, sc2_back));

        }
Пример #14
0
		public TextLayer() : base()
		{

            contentLayer = new CCLayer();
            CCCamera contentCamera = Camera;
            contentLayer.Camera = contentCamera;

            var bg = new CCSprite(TestResource.s_back3);
            BaseNode = bg;
            contentLayer.AddChild(bg, 0, EffectTestScene.kTagBackground);

            var Kathia = new CCSprite(TestResource.s_pPathSister2);
            BaseNode.AddChild(Kathia, 1, EffectTestScene.kTagKathia);

            var sc = new CCScaleBy(2, 5);
            var sc_back = sc.Reverse();
            Kathia.RunAction(new CCRepeatForever(sc, sc_back));


            var Tamara = new CCSprite(TestResource.s_pPathSister1);
            BaseNode.AddChild(Tamara, 1, EffectTestScene.kTagTamara);

            var sc2 = new CCScaleBy(2, 5);
            var sc2_back = sc2.Reverse();
            Tamara.RunAction(new CCRepeatForever(sc2, sc2_back));

            var colorBackground = new CCLayerColor(new CCColor4B(32, 128, 32, 255));
            contentLayer.AddChild(colorBackground, -1);
		}
Пример #15
0
        public IntroLayer()
            : base(CCColor4B.Gray)
        {
            titleLabel = new CCLabel("CocosJuce", "fonts/Roboto-Light-72.fnt");
            frequencyLabel = new CCLabel("", "fonts/Roboto-Light-72.fnt");

            onOffSwitchSpriteFrameCache = CCSpriteFrameCache.SharedSpriteFrameCache;
            onOffSwitchSpriteFrameCache.AddSpriteFrames("images/onoffswitch.plist");

            switchOnSprite = new CCSprite("switch_on.png");
            switchOffSprite = new CCSprite("switch_off.png");
            onOffSwitch = new CCMenuItemToggle(SwitchToggle, new CCMenuItem[]
                                                         {
                                                             new CCMenuItemImage(switchOffSprite) { },
                                                             new CCMenuItemImage(switchOnSprite) { },
                                                         });

            menu = new CCMenu(onOffSwitch);

            freqKnobSpriteFrameCache = CCSpriteFrameCache.SharedSpriteFrameCache;
            freqKnobSpriteFrameCache.AddSpriteFrames("images/frequencyknob.plist");

            frequencyKnob = new CCSprite("frequencyknob00.png");

            AddChild(titleLabel);
            AddChild(menu);
            AddChild(frequencyLabel);
            AddChild(frequencyKnob);
        }
Пример #16
0
        public Wall(int x, int y) : base(x, y)
        {
            HasTower = false;
            sprite   = new CocosSharp.CCSprite("wall.png");

            GameEventHandler.Self.TouchScreen += OnTouch;
        }
Пример #17
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 = Layer.VisibleBoundsWorldspace.Size;

            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));

            grossini.AddAction(action, true);

            Schedule(unpause, 3);
        }
Пример #18
0
        public Test5()
        {
            CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1);
            sp2 = new CCSprite(TestResource.s_pPathSister2);

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

			var rot = new CCRotateBy (2, 360);
            var rot_back = rot.Reverse();

			var forever = new CCRepeatForever (rot, rot_back) { Tag = 101 };

			// Since Actions are immutable to set the tag differently we need to 
			// create a new action.  Notice that the same actions can be used in
			// this case instead of copying them as well.
			forever2 = new CCRepeatForever (rot, rot_back) { Tag = 102 };
            
            AddChild(sp1, 0, CocosNodeTestStaticLibrary.kTagSprite1);
            AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2);

            RemoveChild(sp2, true);
            AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2);

            // Sprite 1 should run and run
            // Sprite 2 should stop
            sp1.RunAction(forever);
            sp2.RunAction(forever2);

            // Experiment with removing sp2 and re-adding it after cleanup to reproduce an error in child management
			//ScheduleOnce(Stage2OfTest, 2.0f);
			Schedule(addAndRemove, 2.0f);
        }
Пример #19
0
        public GameLayer()
        {
            // "paddle" refers to the paddle.png image.
            paddleSprite = new CCSprite ("paddle");
            paddleSprite.PositionX = 180;
            paddleSprite.PositionY = 100;
            AddChild (paddleSprite);

            ballSprite = new CCSprite ("ball");
            ballSprite.PositionX = 180;
            ballSprite.PositionY = 600;
            AddChild (ballSprite);

            scoreLabel = new CCLabel ("Score: 0", "arial", 28, CCLabelFormat.SystemFont);
            scoreLabel.PositionX = 50;
            scoreLabel.PositionY = 480;
            scoreLabel.AnchorPoint = CCPoint.AnchorUpperLeft;
            AddChild (scoreLabel);

            highestScoreLabel = new CCLabel ("Highest Score: 0", "arial", 28, CCLabelFormat.SystemFont);
            highestScoreLabel.PositionX = 50;
            highestScoreLabel.PositionY = 500;
            highestScoreLabel.AnchorPoint = CCPoint.AnchorUpperLeft;
            AddChild (highestScoreLabel);

            Schedule (RunGameLogic);
        }
Пример #20
0
        public GameLayer()
            : base(CCColor4B.Blue, CCColor4B.AliceBlue)
        {
            // Set the layer gradient direction
            this.Vector = new CCPoint(0.5f, 0.5f);

            // Create and add sprites
            monkeySprite1 = new CCSprite("monkey");
            AddChild(monkeySprite1, 1);

            monkeySprite2 = new CCSprite("monkey");
            AddChild(monkeySprite2, 1);

            // Define actions
            var moveUp = new CCMoveBy(1.0f, new CCPoint(0.0f, 50.0f));
            var moveDown = moveUp.Reverse();

            // A CCSequence action runs the list of actions in ... sequence!
            CCSequence moveSeq = new CCSequence(new CCEaseBackInOut(moveUp), new CCEaseBackInOut(moveDown));

            repeatedAction = new CCRepeatForever(moveSeq);

            // A CCSpawn action runs the list of actions concurrently
            dreamAction = new CCSpawn(new CCFadeIn(5.0f), new CCWaves(5.0f, new CCGridSize(10, 20), 4, 4));

            // Schedule for method to be called every 0.1s
            Schedule(UpdateLayerGradient, 0.1f);
        }
Пример #21
0
        void AddNewSpriteWithCoords(CCPoint p)
        {
            CCSpriteBatchNode BatchNode = (CCSpriteBatchNode)GetChildByTag((int)kTags.kTagSpriteBatchNode);

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


            CCSprite sprite = new CCSprite(BatchNode.Texture, new CCRect(x, y, 85, 121));
            sprite.Position = (new CCPoint(p.X, p.Y));
            BatchNode.AddChild(sprite);


            CCFiniteTimeAction action = null;
            float random = (float)CCRandom.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);

            CCFiniteTimeAction action_back = (CCFiniteTimeAction)action.Reverse();
            CCFiniteTimeAction seq = (CCFiniteTimeAction)(new CCSequence(action, action_back));

            sprite.RunAction(new CCRepeatForever (seq));
        }
Пример #22
0
		public TextLayer() : base()
		{

            Camera = AppDelegate.SharedCamera;
            contentLayer = new CCLayer();
            CCCamera contentCamera = new CCCamera(Camera.OrthographicViewSizeWorldspace, Camera.CenterInWorldspace, Camera.TargetInWorldspace);
            contentLayer.Camera = contentCamera;

            var bg = new CCSprite(TestResource.s_back3);
            BaseNode = bg;
            contentLayer.AddChild(bg, 0, EffectTestScene.kTagBackground);

            var Kathia = new CCSprite(TestResource.s_pPathSister2);
            BaseNode.AddChild(Kathia, 1, EffectTestScene.kTagKathia);

            var sc = new CCScaleBy(2, 5);
            var sc_back = sc.Reverse();
            Kathia.RunAction(new CCRepeatForever(sc, sc_back));


            var Tamara = new CCSprite(TestResource.s_pPathSister1);
            BaseNode.AddChild(Tamara, 1, EffectTestScene.kTagTamara);

            var sc2 = new CCScaleBy(2, 5);
            var sc2_back = sc2.Reverse();
            Tamara.RunAction(new CCRepeatForever(sc2, sc2_back));

            var colorBackground = new CCLayerColor(new CCColor4B(32, 128, 32, 255));
            contentLayer.AddChild(colorBackground, -1);
		}
Пример #23
0
		public GameLayer ()
        {
            var touchListener = new CCEventListenerTouchAllAtOnce();
            touchListener.OnTouchesEnded = OnTouchesEnded;

            EventDispatcher.AddEventListener(touchListener, this);
            Color = new CCColor3B (CCColor4B.White);
			Opacity = 255;

			visibleBananas = new List<CCSprite> ();
			hitBananas = new List<CCSprite> ();
	
			monkey = new CCSprite ("Monkey");
			monkey.Position = CCDirector.SharedDirector.WinSize.Center;
			AddChild (monkey);

			Schedule ((t) => {
				visibleBananas.Add (AddBanana ());
				dt += t;
				if(ShouldEndGame ()){
					var gameOverScene = GameOverLayer.SceneWithScore(hitBananas.Count);
					CCTransitionFadeDown transitionToGameOver = new CCTransitionFadeDown(1.0f, gameOverScene);
					CCDirector.SharedDirector.ReplaceScene (transitionToGameOver);
				}
			}, 1.0f);

			Schedule ((t) => {
				CheckCollision ();
			});
		}
Пример #24
0
        public override void OnEnter()
        {
            base.OnEnter();

			var effect = new CCSequence(new CCDelayTime (2.0f), new CCShaky3D(5.0f, new CCGridSize(5, 5), 16, false));

            // cleanup
			RemoveChild(bgNode, true);

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

            // foreground
			var layer2Node = new CCNode ();
			var layer2 = new CCLayerColor(new CCColor4B(0, 255, 0, 255));
			var fog = new CCSprite("Images/Fog");

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

			layer2Node.RepeatForever(effect);
        }
        public SpriteChildrenVisibilityIssue665()
        {
            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("animations/grossini.plist");


            aParent = new CCSpriteBatchNode("animations/grossini", 50);
            AddChild(aParent, 0);

            sprite1 = new CCSprite("grossini_dance_01.png");
            sprite2 = new CCSprite("grossini_dance_02.png");
            sprite3 = new CCSprite("grossini_dance_03.png");

            // test issue #665
            sprite1.Visible = false;

            aParent.AddChild(sprite1);
            sprite1.AddChild(sprite2, -2);
            sprite1.AddChild(sprite3, 2);

            aParent2 = new CCNode();
            AddChild(aParent2, 0);

            sprite4 = new CCSprite("grossini_dance_01.png");
            sprite5 = new CCSprite("grossini_dance_02.png");
            sprite6 = new CCSprite("grossini_dance_03.png");

            // test issue #665
            sprite4.Visible = false;

            aParent2.AddChild(sprite4);
            sprite4.AddChild(sprite5, -2);
            sprite4.AddChild(sprite6, 2);
        }
Пример #26
0
        public StartScene(CCWindow mainWindow)
            : base(mainWindow)
        {
            mainLayer = new CCLayer ();
            AddChild (mainLayer);

            PlayButton = new CCSprite ("logo");

            NameLabel = new CCLabel ("Map Knight - Alpha", "arial", 22);
            CreatorLabel = new CCLabel ("Created by tipfom and Exo", "arial", 22);
            VersionLabel = new CCLabel ("Version unspecified", "arial", 22);
            InfoLabel = new CCLabel ("Click to play", "arial", 22);

            PlayButton.ScaleX = mainWindow.WindowSizeInPixels.Width / PlayButton.ContentSize.Width;
            PlayButton.ScaleY = mainWindow.WindowSizeInPixels.Height / PlayButton.ContentSize.Height;
            PlayButton.Position = new CCPoint (PlayButton.ScaledContentSize.Width / 2, PlayButton.ScaledContentSize.Height / 2);

            NameLabel.Position = new CCPoint (mainWindow.WindowSizeInPixels.Width / 4 * 3, mainWindow.WindowSizeInPixels.Height / 2 - NameLabel.ContentSize.Height);
            CreatorLabel.Position = new CCPoint (mainWindow.WindowSizeInPixels.Width / 4 * 3, NameLabel.PositionY - CreatorLabel.ContentSize.Height - 30);
            VersionLabel.Position = new CCPoint (mainWindow.WindowSizeInPixels.Width / 4 * 3, CreatorLabel.PositionY - VersionLabel.ContentSize.Height - 30);
            InfoLabel.Position = new CCPoint (mainWindow.WindowSizeInPixels.Width / 4 * 3, VersionLabel.PositionY - InfoLabel.ContentSize.Height - 30);

            mainLayer.AddChild (PlayButton);
            mainLayer.AddChild (NameLabel);
            mainLayer.AddChild (CreatorLabel);
            mainLayer.AddChild (VersionLabel);
            mainLayer.AddChild (InfoLabel);

            touchListener = new CCEventListenerTouchAllAtOnce ();
            touchListener.OnTouchesEnded = HandleTouchesEnded;
            AddEventListener (touchListener, this);
        }
        public SpriteOffsetAnchorRotation()
        {
            sprites = new CCSprite[numOfSprites];
            pointSprites = new CCSprite[numOfSprites];

            // Create actions

            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFrames("animations/grossini.plist");
            cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray");
            var animFrames = new List<CCSpriteFrame>();
            string tmp = "";
            for (int j = 0; j < 14; j++)
            {
                tmp = string.Format("grossini_dance_{0:00}.png", j + 1);
                CCSpriteFrame frame = cache[tmp];
                animFrames.Add(frame);
            }

            animation = new CCAnimation(animFrames, 0.3f);

            for (int i = 0; i < numOfSprites; i++)
            {
                // Animation using Sprite batch
                sprites[i] = new CCSprite("grossini_dance_01.png");
                AddChild(sprites[i], 0);

                pointSprites[i] = new CCSprite("Images/r1");
                AddChild(pointSprites[i], 1);
            }
        }
        public SpriteWithColor(CCColor4B bgColor, CCSize textureSizeInPixels) : base ()
        {
            // 1: Create new CCRenderTexture
            CCRenderTexture rt = new CCRenderTexture(textureSizeInPixels, textureSizeInPixels);

            // 2: Call CCRenderTexture:begin
            rt.BeginWithClear(bgColor);

            // 3: Draw into the texture
            // You'll add this later
            GenerateGradient(textureSizeInPixels);


            var noise = new CCSprite("images/Noise.png");
            noise.AnchorPoint = CCPoint.AnchorLowerLeft;
            noise.Position = CCPoint.Zero;
            noise.BlendFunc = new CCBlendFunc(CCOGLES.GL_DST_COLOR, CCOGLES.GL_ZERO);
            noise.Texture.SamplerState = Microsoft.Xna.Framework.Graphics.SamplerState.LinearWrap;

            // To get the linear wrap to work correctly we have to set the TextureRectInPixels as well as ContentSize
            noise.TextureRectInPixels = new CCRect(0, 0, textureSizeInPixels.Width, textureSizeInPixels.Height);
            noise.ContentSize = noise.TextureRectInPixels.Size;
            noise.Visit();

            // 4: Call CCRenderTexture:end
            rt.End();

            this.Texture = rt.Texture;

        }
		public GameScene(CCWindow mainWindow) : base(mainWindow)
		{
			mainLayer = new CCLayer ();
			AddChild (mainLayer);

			paddleSprite = new CCSprite ("paddle");
			paddleSprite.PositionX = 100;
			paddleSprite.PositionY = 100;
			mainLayer.AddChild (paddleSprite);

			ballSprite = new CCSprite ("ball");
			ballSprite.PositionX = 320;
			ballSprite.PositionY = 600;
			mainLayer.AddChild (ballSprite);

			scoreLabel = new CCLabel ("Score: 0", "arial", 22);
			scoreLabel.PositionX = mainLayer.VisibleBoundsWorldspace.MinX + 20;
			scoreLabel.PositionY = mainLayer.VisibleBoundsWorldspace.MaxY - 20;
			scoreLabel.AnchorPoint = CCPoint.AnchorUpperLeft;

			mainLayer.AddChild (scoreLabel);

			Schedule (RunGameLogic);

			touchListener = new CCEventListenerTouchAllAtOnce ();
			touchListener.OnTouchesMoved = HandleTouchesMoved;
			AddEventListener (touchListener, this);
		}
Пример #30
0
        public override void updateQuantityOfNodes()
        {
            CCSize s = Layer.VisibleBoundsWorldspace.Size;

            // increase nodes
            if (currentQuantityOfNodes < quantityOfNodes)
            {
                StartTimer();
                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(CCRandom.Next() * s.Width, CCRandom.Next() * s.Height);
                    sprite.Visible = false;
                }
                EndTimer("Current Quantity: add");
            }
            // decrease nodes
            else if (currentQuantityOfNodes > quantityOfNodes)
            {
                StartTimer();
                for (int i = 0; i < (currentQuantityOfNodes - quantityOfNodes); i++)
                {
                    int index = currentQuantityOfNodes - i - 1;
                    batchNode.RemoveChildAtIndex(index, true);
                }
                EndTimer("Current Quantity: add");
            }

            currentQuantityOfNodes = quantityOfNodes;
        }
Пример #31
0
        public SpriteBatchNodeZOrder()
        {
            dir = 1;

            // 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);

            sprites = new CCSprite[numOfSprites];

            for (int i = 0; i < 5; i++)
            {
                sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121));
                batch.AddChild(sprites[i], i);
            }

            for (int i = 5; i < 10; i++)
            {
                sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121));
                batch.AddChild(sprites[i], 14 - i);
            }

            sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 0, 85, 121));
            batch.AddChild(sprite1, -1, (int)kTagSprite.kTagSprite1);
            sprite1.Scale = 6;
            sprite1.Color = CCColor3B.Red;

        }
Пример #32
0
 private float GetLetterPosXRight(CCSprite sp)
 {
     return((sp.Position.X + sp.ContentSize.Width) * ScaleX);
 }
Пример #33
0
 private float GetLetterPosXLeft(CCSprite sp)
 {
     return(sp.Position.X * ScaleX);
 }
Пример #34
0
        public void CreateFontChars()
        {
            int  nextFontPositionX = 0;
            int  nextFontPositionY = 0;
            char prev          = (char)255;
            int  kerningAmount = 0;

            CCSize tmpSize = CCSize.Zero;

            int longestLine = 0;
            int totalHeight = 0;

            int quantityOfLines = 1;

            if (String.IsNullOrEmpty(labelText))
            {
                return;
            }

            int stringLen = labelText.Length;

            var charSet = FontConfiguration.CharacterSet;

            if (charSet.Count == 0)
            {
                throw (new InvalidOperationException(
                           "Can not compute the size of the font because the character set is empty."));
            }

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

            LineHeight = FontConfiguration.CommonHeight;

            totalHeight       = LineHeight * quantityOfLines;
            nextFontPositionY = 0 -
                                (LineHeight - LineHeight * quantityOfLines);

            CCBMFontConfiguration.CCBMGlyphDef fontDef = null;
            CCRect fontCharTextureRect;
            CCSize fontCharContentSize;

            for (int i = 0; i < stringLen; i++)
            {
                char c = labelText[i];

                if (c == '\n')
                {
                    nextFontPositionX  = 0;
                    nextFontPositionY -= LineHeight;
                    continue;
                }

                if (charSet.IndexOf(c) == -1)
                {
                    CCLog.Log("CocosSharp: CCLabelBMFont: Attempted to use character not defined in this bitmap: {0}",
                              (int)c);
                    continue;
                }

                kerningAmount = this.KerningAmountForFirst(prev, c);

                // unichar is a short, and an int is needed on HASH_FIND_INT
                if (!FontConfiguration.Glyphs.TryGetValue(c, out fontDef))
                {
                    CCLog.Log("CocosSharp: CCLabelBMFont: characer not found {0}", (int)c);
                    continue;
                }

                fontCharTextureRect           = fontDef.Subrect;
                fontCharTextureRect.Origin.X += ImageOffset.X;
                fontCharTextureRect.Origin.Y += ImageOffset.Y;

                fontCharContentSize = fontCharTextureRect.Size / DefaultTexelToContentSizeRatios;

                CCSprite fontChar;

                //bool hasSprite = true;
                fontChar = (CCSprite)(this[i]);
                if (fontChar != null)
                {
                    // Reusing previous Sprite
                    fontChar.Visible = true;

                    // updating previous sprite
                    fontChar.IsTextureRectRotated = false;
                    fontChar.ContentSize          = fontCharContentSize;
                    fontChar.TextureRectInPixels  = fontCharTextureRect;
                }
                else
                {
                    // New Sprite ? Set correct color, opacity, etc...
                    //if( false )
                    //{
                    //    /* WIP: Doesn't support many features yet.
                    //     But this code is super fast. It doesn't create any sprite.
                    //     Ideal for big labels.
                    //     */
                    //    fontChar = m_pReusedChar;
                    //    fontChar.BatchNode = null;
                    //    hasSprite = false;
                    //}
                    //else
                    {
                        fontChar             = new CCSprite(TextureAtlas.Texture, fontCharTextureRect);
                        fontChar.ContentSize = fontCharContentSize;
                        AddChild(fontChar, i, i);
                    }

                    // Apply label properties
                    fontChar.IsColorModifiedByOpacity = IsColorModifiedByOpacity;

                    // Color MUST be set before opacity, since opacity might change color if OpacityModifyRGB is on
                    fontChar.UpdateDisplayedColor(DisplayedColor);
                    fontChar.UpdateDisplayedOpacity(DisplayedOpacity);
                }

                // See issue 1343. cast( signed short + unsigned integer ) == unsigned integer (sign is lost!)
                int yOffset = FontConfiguration.CommonHeight - fontDef.YOffset;

                var fontPos =
                    new CCPoint(
                        (float)nextFontPositionX + fontDef.XOffset + fontDef.Subrect.Size.Width * 0.5f + kerningAmount,
                        (float)nextFontPositionY + yOffset - fontCharTextureRect.Size.Height * 0.5f);

                fontChar.Position = fontPos;

                // update kerning
                nextFontPositionX += fontDef.XAdvance + kerningAmount;
                prev = c;

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

            // If the last character processed has an xAdvance which is less that the width of the characters image, then we need
            // to adjust the width of the string to take this into account, or the character will overlap the end of the bounding
            // box
            if (fontDef.XAdvance < fontDef.Subrect.Size.Width)
            {
                tmpSize.Width = longestLine + fontDef.Subrect.Size.Width - fontDef.XAdvance;
            }
            else
            {
                tmpSize.Width = longestLine;
            }

            tmpSize.Height = totalHeight;
            var tmpDimensions = labelDimensions;

            labelDimensions = new CCSize(
                labelDimensions.Width > 0 ? labelDimensions.Width : tmpSize.Width,
                labelDimensions.Height > 0 ? labelDimensions.Height : tmpSize.Height
                );

            ContentSize     = labelDimensions;
            labelDimensions = tmpDimensions;
        }
Пример #35
0
        public CCControlSwitchSprite(CCSprite maskSprite, CCSprite onSprite, CCSprite offSprite, CCSprite thumbSprite,
                                     CCLabelTtf onLabel, CCLabelTtf offLabel)
            : base((CCTexture2D)null, new CCRect(0.0f, 0.0f, maskSprite.TextureRectInPixels.Size.Width, maskSprite.TextureRectInPixels.Size.Height))
        {
            OnPosition      = 0;
            OffPosition     = -onSprite.ContentSize.Width + thumbSprite.ContentSize.Width / 2;
            sliderXPosition = OnPosition;

            OnSprite    = onSprite;
            OffSprite   = offSprite;
            ThumbSprite = thumbSprite;
            OnLabel     = onLabel;
            OffLabel    = offLabel;
            MaskSprite  = maskSprite;

            AddChild(ThumbSprite);

            NeedsLayout();
        }
Пример #36
0
 public void AppendChild(CCSprite sprite)
 {
     AddChild(sprite);
 }
Пример #37
0
 public Field(int x, int y) : base(x, y)
 {
     sprite = new CocosSharp.CCSprite("field.png");
 }
Пример #38
0
        protected CCSpriteBatchNode AddSpriteWithoutQuad(CCSprite child, int z, int aTag)
        {
            base.AddChild(child, z, aTag);

            return(this);
        }
Пример #39
0
 public void RemoveSpriteFromAtlas(CCSprite sprite)
 {
     RemoveChild(sprite);
 }
Пример #40
0
        public CCSprite ExtractTile(int column, int row, bool addToTileMapLayer = true)
        {
            if (!AreValidTileCoordinates(column, row))
            {
                return(null);
            }

            CCTileGidAndFlags gidAndFlags = TileGIDAndFlags(column, row);
            int flattendedIndex           = FlattenedTileIndex(column, row);

            CCTileSetInfo tileSetInfo = GetDrawBufferManagerByGid(gidAndFlags.Gid).TileSetInfo;
            CCRect        texRect     = tileSetInfo.TextureRectForGID(gidAndFlags.Gid);
            CCSprite      tileSprite  = new CCSprite(tileSetInfo.Texture, texRect);

            tileSprite.ContentSize = texRect.Size * CCTileMapLayer.DefaultTexelToContentSizeRatios;
            tileSprite.Position    = TilePosition(column, row);
            tileSprite.VertexZ     = TileVertexZ(column, row);
            tileSprite.AnchorPoint = CCPoint.Zero;
            tileSprite.Opacity     = Opacity;
            tileSprite.FlipX       = false;
            tileSprite.FlipY       = false;
            tileSprite.Rotation    = 0.0f;

            if ((gidAndFlags.Flags & CCTileFlags.TileDiagonal) != 0)
            {
                CCSize halfContentSize = tileSprite.ContentSize * 0.5f;

                tileSprite.AnchorPoint = CCPoint.AnchorMiddle;
                tileSprite.Position   += new CCPoint(halfContentSize.Width, halfContentSize.Height);

                CCTileFlags horAndVertFlag = gidAndFlags.Flags & (CCTileFlags.Horizontal | CCTileFlags.Vertical);

                // Handle the 4 diagonally flipped states.
                if (horAndVertFlag == CCTileFlags.Horizontal)
                {
                    tileSprite.Rotation = 90.0f;
                }
                else if (horAndVertFlag == CCTileFlags.Vertical)
                {
                    tileSprite.Rotation = 270.0f;
                }
                else if (horAndVertFlag == (CCTileFlags.Vertical | CCTileFlags.Horizontal))
                {
                    tileSprite.Rotation = 90.0f;
                    tileSprite.FlipX    = true;
                }
                else
                {
                    tileSprite.Rotation = 270.0f;
                    tileSprite.FlipX    = true;
                }
            }
            else
            {
                if ((gidAndFlags.Flags & CCTileFlags.Horizontal) != 0)
                {
                    tileSprite.FlipX = true;
                }

                if ((gidAndFlags.Flags & CCTileFlags.Vertical) != 0)
                {
                    tileSprite.FlipY = true;
                }
            }

            if (addToTileMapLayer)
            {
                AddChild(tileSprite, flattendedIndex, flattendedIndex);
            }

            RemoveTile(column, row);

            return(tileSprite);
        }
Пример #41
0
        public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets)
        {
            var opacity = Opacity;
            var color   = Color;

            // Release old sprites
            RemoveAllChildren(true);

            scale9Image = batchnode;
            scale9Image.RemoveAllChildren(true);

            this.capInsets     = capInsets;
            spriteFrameRotated = rotated;

            // If there is no given rect
            if (rect.Equals(CCRect.Zero))
            {
                // Get the texture size as original
                CCSize textureSize = scale9Image.TextureAtlas.Texture.ContentSizeInPixels;

                rect = new CCRect(0, 0, textureSize.Width, textureSize.Height);
            }

            // Set the given rect's size as original size
            spriteRect        = rect;
            originalSize      = rect.Size;
            preferredSize     = originalSize;
            capInsetsInternal = capInsets;

            float h = rect.Size.Height;
            float w = rect.Size.Width;

            // If there is no specified center region
            if (capInsetsInternal.Equals(CCRect.Zero))
            {
                capInsetsInternal = new CCRect(w / 3, h / 3, w / 3, h / 3);
            }

            float left_w   = capInsetsInternal.Origin.X;
            float center_w = capInsetsInternal.Size.Width;
            float right_w  = rect.Size.Width - (left_w + center_w);

            float top_h    = capInsetsInternal.Origin.Y;
            float center_h = capInsetsInternal.Size.Height;
            float bottom_h = rect.Size.Height - (top_h + center_h);

            // calculate rects

            // ... top row
            float x = 0.0f;
            float y = 0.0f;

            // top left
            CCRect lefttopbounds = new CCRect(x, y, left_w, top_h);

            // top center
            x += left_w;
            CCRect centertopbounds = new CCRect(x, y, center_w, top_h);

            // top right
            x += center_w;
            CCRect righttopbounds = new CCRect(x, y, right_w, top_h);

            // ... center row
            x  = 0.0f;
            y  = 0.0f;
            y += top_h;

            // center left
            CCRect leftcenterbounds = new CCRect(x, y, left_w, center_h);

            // center center
            x += left_w;
            CCRect centerbounds = new CCRect(x, y, center_w, center_h);

            // center right
            x += center_w;
            CCRect rightcenterbounds = new CCRect(x, y, right_w, center_h);

            // ... bottom row
            x  = 0.0f;
            y  = 0.0f;
            y += top_h;
            y += center_h;

            // bottom left
            CCRect leftbottombounds = new CCRect(x, y, left_w, bottom_h);

            // bottom center
            x += left_w;
            CCRect centerbottombounds = new CCRect(x, y, center_w, bottom_h);

            // bottom right
            x += center_w;
            CCRect rightbottombounds = new CCRect(x, y, right_w, bottom_h);

            if (!rotated)
            {
                CCAffineTransform t = CCAffineTransform.Identity;
                t = CCAffineTransform.Translate(t, rect.Origin.X, rect.Origin.Y);

                centerbounds       = CCAffineTransform.Transform(centerbounds, t);
                rightbottombounds  = CCAffineTransform.Transform(rightbottombounds, t);
                leftbottombounds   = CCAffineTransform.Transform(leftbottombounds, t);
                righttopbounds     = CCAffineTransform.Transform(righttopbounds, t);
                lefttopbounds      = CCAffineTransform.Transform(lefttopbounds, t);
                rightcenterbounds  = CCAffineTransform.Transform(rightcenterbounds, t);
                leftcenterbounds   = CCAffineTransform.Transform(leftcenterbounds, t);
                centerbottombounds = CCAffineTransform.Transform(centerbottombounds, t);
                centertopbounds    = CCAffineTransform.Transform(centertopbounds, t);

                // Centre
                centre = new CCSprite(scale9Image.Texture, centerbounds);
                scale9Image.AddChild(centre, 0, (int)Positions.Centre);

                // Top
                top = new CCSprite(scale9Image.Texture, centertopbounds);
                scale9Image.AddChild(top, 1, (int)Positions.Top);

                // Bottom
                bottom = new CCSprite(scale9Image.Texture, centerbottombounds);
                scale9Image.AddChild(bottom, 1, (int)Positions.Bottom);

                // Left
                left = new CCSprite(scale9Image.Texture, leftcenterbounds);
                scale9Image.AddChild(left, 1, (int)Positions.Left);

                // Right
                right = new CCSprite(scale9Image.Texture, rightcenterbounds);
                scale9Image.AddChild(right, 1, (int)Positions.Right);

                // Top left
                topLeft = new CCSprite(scale9Image.Texture, lefttopbounds);
                scale9Image.AddChild(topLeft, 2, (int)Positions.TopLeft);

                // Top right
                topRight = new CCSprite(scale9Image.Texture, righttopbounds);
                scale9Image.AddChild(topRight, 2, (int)Positions.TopRight);

                // Bottom left
                bottomLeft = new CCSprite(scale9Image.Texture, leftbottombounds);
                scale9Image.AddChild(bottomLeft, 2, (int)Positions.BottomLeft);

                // Bottom right
                bottomRight = new CCSprite(scale9Image.Texture, rightbottombounds);
                scale9Image.AddChild(bottomRight, 2, (int)Positions.BottomRight);
            }
            else
            {
                // set up transformation of coordinates
                // to handle the case where the sprite is stored rotated
                // in the spritesheet
                // CCLog("rotated");

                CCAffineTransform t = CCAffineTransform.Identity;

                CCRect rotatedcenterbounds       = centerbounds;
                CCRect rotatedrightbottombounds  = rightbottombounds;
                CCRect rotatedleftbottombounds   = leftbottombounds;
                CCRect rotatedrighttopbounds     = righttopbounds;
                CCRect rotatedlefttopbounds      = lefttopbounds;
                CCRect rotatedrightcenterbounds  = rightcenterbounds;
                CCRect rotatedleftcenterbounds   = leftcenterbounds;
                CCRect rotatedcenterbottombounds = centerbottombounds;
                CCRect rotatedcentertopbounds    = centertopbounds;

                t = CCAffineTransform.Translate(t, rect.Size.Height + rect.Origin.X, rect.Origin.Y);
                t = CCAffineTransform.Rotate(t, 1.57079633f);

                centerbounds       = CCAffineTransform.Transform(centerbounds, t);
                rightbottombounds  = CCAffineTransform.Transform(rightbottombounds, t);
                leftbottombounds   = CCAffineTransform.Transform(leftbottombounds, t);
                righttopbounds     = CCAffineTransform.Transform(righttopbounds, t);
                lefttopbounds      = CCAffineTransform.Transform(lefttopbounds, t);
                rightcenterbounds  = CCAffineTransform.Transform(rightcenterbounds, t);
                leftcenterbounds   = CCAffineTransform.Transform(leftcenterbounds, t);
                centerbottombounds = CCAffineTransform.Transform(centerbottombounds, t);
                centertopbounds    = CCAffineTransform.Transform(centertopbounds, t);

                rotatedcenterbounds.Origin       = centerbounds.Origin;
                rotatedrightbottombounds.Origin  = rightbottombounds.Origin;
                rotatedleftbottombounds.Origin   = leftbottombounds.Origin;
                rotatedrighttopbounds.Origin     = righttopbounds.Origin;
                rotatedlefttopbounds.Origin      = lefttopbounds.Origin;
                rotatedrightcenterbounds.Origin  = rightcenterbounds.Origin;
                rotatedleftcenterbounds.Origin   = leftcenterbounds.Origin;
                rotatedcenterbottombounds.Origin = centerbottombounds.Origin;
                rotatedcentertopbounds.Origin    = centertopbounds.Origin;

                // Centre
                centre = new CCSprite(scale9Image.Texture, rotatedcenterbounds, true);
                //centre.InitWithTexture(scale9Image.Texture, rotatedcenterbounds, true);
                scale9Image.AddChild(centre, 0, (int)Positions.Centre);

                // Top
                top = new CCSprite(scale9Image.Texture, rotatedcentertopbounds, true);
                //top.InitWithTexture(scale9Image.Texture, rotatedcentertopbounds, true);
                scale9Image.AddChild(top, 1, (int)Positions.Top);

                // Bottom
                bottom = new CCSprite(scale9Image.Texture, rotatedcenterbottombounds, true);
                //bottom.InitWithTexture(scale9Image.Texture, rotatedcenterbottombounds, true);
                scale9Image.AddChild(bottom, 1, (int)Positions.Bottom);

                // Left
                left = new CCSprite(scale9Image.Texture, rotatedleftcenterbounds, true);
                //left.InitWithTexture(scale9Image.Texture, rotatedleftcenterbounds, true);
                scale9Image.AddChild(left, 1, (int)Positions.Left);

                // Right
                right = new CCSprite(scale9Image.Texture, rotatedrightcenterbounds, true);
                //right.InitWithTexture(scale9Image.Texture, rotatedrightcenterbounds, true);
                scale9Image.AddChild(right, 1, (int)Positions.Right);

                // Top left
                topLeft = new CCSprite(scale9Image.Texture, rotatedlefttopbounds, true);
                //topLeft.InitWithTexture(scale9Image.Texture, rotatedlefttopbounds, true);
                scale9Image.AddChild(topLeft, 2, (int)Positions.TopLeft);

                // Top right
                topRight = new CCSprite(scale9Image.Texture, rotatedrighttopbounds, true);
                //topRight.InitWithTexture(scale9Image.Texture, rotatedrighttopbounds, true);
                scale9Image.AddChild(topRight, 2, (int)Positions.TopRight);

                // Bottom left
                bottomLeft = new CCSprite(scale9Image.Texture, rotatedleftbottombounds, true);
                //bottomLeft.InitWithTexture(scale9Image.Texture, rotatedleftbottombounds, true);
                scale9Image.AddChild(bottomLeft, 2, (int)Positions.BottomLeft);

                // Bottom right
                bottomRight = new CCSprite(scale9Image.Texture, rotatedrightbottombounds, true);
                //bottomRight.InitWithTexture(scale9Image.Texture, rotatedrightbottombounds, true);
                scale9Image.AddChild(bottomRight, 2, (int)Positions.BottomRight);
            }

            ContentSize = rect.Size / CCSprite.DefaultTexelToContentSizeRatios;
            AddChild(scale9Image);

            if (spritesGenerated)
            {
                // Restore color and opacity
                Opacity = opacity;
                Color   = color;
            }
            spritesGenerated = true;

            return(true);
        }
Пример #42
0
        void UpdateAtlasIndex(CCSprite sprite, ref int curIndex)
        {
            int count = 0;
            CCRawList <CCNode> pArray = sprite.Children;

            if (pArray != null)
            {
                count = pArray.Count;
            }

            int oldIndex = 0;

            if (count == 0)
            {
                oldIndex              = sprite.AtlasIndex;
                sprite.AtlasIndex     = curIndex;
                sprite.OrderOfArrival = 0;
                if (oldIndex != curIndex)
                {
                    Swap(oldIndex, curIndex);
                }
                curIndex++;
            }
            else
            {
                bool needNewIndex = true;

                if (pArray.Elements[0].ZOrder >= 0)
                {
                    //all children are in front of the parent
                    oldIndex              = sprite.AtlasIndex;
                    sprite.AtlasIndex     = curIndex;
                    sprite.OrderOfArrival = 0;
                    if (oldIndex != curIndex)
                    {
                        Swap(oldIndex, curIndex);
                    }
                    curIndex++;

                    needNewIndex = false;
                }

                for (int i = 0; i < count; i++)
                {
                    var child = (CCSprite)pArray.Elements[i];
                    if (needNewIndex && child.ZOrder >= 0)
                    {
                        oldIndex              = sprite.AtlasIndex;
                        sprite.AtlasIndex     = curIndex;
                        sprite.OrderOfArrival = 0;
                        if (oldIndex != curIndex)
                        {
                            Swap(oldIndex, curIndex);
                        }
                        curIndex++;
                        needNewIndex = false;
                    }

                    UpdateAtlasIndex(child, ref curIndex);
                }

                if (needNewIndex)
                {
                    //all children have a zOrder < 0)
                    oldIndex              = sprite.AtlasIndex;
                    sprite.AtlasIndex     = curIndex;
                    sprite.OrderOfArrival = 0;
                    if (oldIndex != curIndex)
                    {
                        Swap(oldIndex, curIndex);
                    }
                    curIndex++;
                }
            }
        }
Пример #43
0
 public CCControlSwitch(CCSprite maskSprite, CCSprite onSprite, CCSprite offSprite, CCSprite thumbSprite)
     : this(maskSprite, onSprite, offSprite, thumbSprite, null, null)
 {
 }
Пример #44
0
        public CCControlSwitch(CCSprite maskSprite, CCSprite onSprite, CCSprite offSprite, CCSprite thumbSprite, CCLabelTtf onLabel,
                               CCLabelTtf offLabel)
        {
            Debug.Assert(maskSprite != null, "Mask must not be nil.");
            Debug.Assert(onSprite != null, "onSprite must not be nil.");
            Debug.Assert(offSprite != null, "offSprite must not be nil.");
            Debug.Assert(thumbSprite != null, "thumbSprite must not be nil.");

            on = true;

            switchSprite          = new CCControlSwitchSprite(maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel);
            switchSprite.Position = new CCPoint(switchSprite.ContentSize.Width / 2, switchSprite.ContentSize.Height / 2);
            AddChild(switchSprite);

            IgnoreAnchorPointForPosition = false;
            AnchorPoint = new CCPoint(0.5f, 0.5f);
            ContentSize = switchSprite.ContentSize;

            // Register Touch Event
            var touchListener = new CCEventListenerTouchOneByOne();

            touchListener.IsSwallowTouches = true;

            touchListener.OnTouchBegan     = OnTouchBegan;
            touchListener.OnTouchMoved     = OnTouchMoved;
            touchListener.OnTouchEnded     = OnTouchEnded;
            touchListener.OnTouchCancelled = OnTouchCancelled;

            AddEventListener(touchListener);
        }
Пример #45
0
 public CCMenuItemImage(CCSprite normalSprite, Action <object> selector = null)
     : this(normalSprite, new CCSprite())
 {
 }
Пример #46
0
 private float GetLetterPosXRight(CCSprite sp)
 {
     return(sp.Position.X * ScaleX + (sp.ContentSize.Width * ScaleX * sp.AnchorPoint.X));
 }
Пример #47
0
 public CCMenuItemImage(CCSprite normalSprite, CCSprite selectedSprite, Action <object> target = null)
     : this(normalSprite, selectedSprite, new CCSprite(), target)
 {
 }
Пример #48
0
        protected void InitCCLabelBMFont(string theString, string fntFile, CCSize dimensions, CCTextAlignment hAlignment, CCVerticalTextAlignment vAlignment,
                                         CCPoint imageOffset, CCTexture2D texture)
        {
            Debug.Assert(FontConfiguration == null, "re-init is no longer supported");
            Debug.Assert((theString == null && fntFile == null) || (theString != null && fntFile != null),
                         "Invalid params for CCLabelBMFont");

            if (!String.IsNullOrEmpty(fntFile))
            {
                CCBMFontConfiguration newConf = FNTConfigLoadFile(fntFile);
                if (newConf == null)
                {
                    CCLog.Log("CCLabelBMFont: Impossible to create font. Please check file: '{0}'", fntFile);
                    return;
                }

                FontConfiguration = newConf;

                fntConfigFile = fntFile;

                if (texture == null)
                {
                    try
                    {
                        texture = CCTextureCache.SharedTextureCache.AddImage(FontConfiguration.AtlasName);
                    }
                    catch (Exception)
                    {
                        // Try the 'images' ref location just in case.
                        try
                        {
                            texture =
                                CCTextureCache.SharedTextureCache.AddImage(System.IO.Path.Combine("images",
                                                                                                  FontConfiguration
                                                                                                  .AtlasName));
                        }
                        catch (Exception)
                        {
                            // Lastly, try <font_path>/images/<font_name>
                            string dir     = System.IO.Path.GetDirectoryName(FontConfiguration.AtlasName);
                            string fname   = System.IO.Path.GetFileName(FontConfiguration.AtlasName);
                            string newName = System.IO.Path.Combine(System.IO.Path.Combine(dir, "images"), fname);
                            texture = CCTextureCache.SharedTextureCache.AddImage(newName);
                        }
                    }
                }
            }
            else
            {
                texture = new CCTexture2D();
            }

            if (String.IsNullOrEmpty(theString))
            {
                theString = String.Empty;
            }

            base.InitCCSpriteBatchNode(texture, theString.Length);

            this.labelDimensions = dimensions;

            horzAlignment = hAlignment;
            vertAlignment = vAlignment;

            IsOpacityCascaded = true;

            ContentSize = CCSize.Zero;

            IsColorModifiedByOpacity = TextureAtlas.Texture.HasPremultipliedAlpha;
            AnchorPoint = new CCPoint(0.5f, 0.5f);

            ImageOffset = imageOffset;

            reusedChar             = new CCSprite(TextureAtlas.Texture);
            reusedChar.ContentSize = dimensions;
            reusedChar.BatchNode   = this;

            SetString(theString, true);
        }