public SpriteBatchNodeReorderIssue767()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

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

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

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

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


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


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

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

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

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

            Schedule(reorderSprites, 1);
        }
예제 #2
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize winSize = CCDirector.SharedDirector.WinSize;
            float x = winSize.Width / 2;
            float y = 0 + (winSize.Height / 2);

            CCLog.Log("S9BatchNodeBasic ...");

            var batchNode = new CCSpriteBatchNode("Images/blocks9.png");
            //batchNode.AnchorPoint = new CCPoint(0.5f, 0.5f);
            CCLog.Log("batchNode created with : Images/blocks9.png");

            var blocks = new CCScale9Sprite();
            CCLog.Log("... created");

            blocks.UpdateWithBatchNode(batchNode, new CCRect(0, 0, 96, 96), false, new CCRect(0, 0, 96, 96));
            CCLog.Log("... updateWithBatchNode");

            blocks.Position = new CCPoint(x, y);
            CCLog.Log("... setPosition");

            AddChild(blocks);
            CCLog.Log("AddChild");

            CCLog.Log("... S9BatchNodeBasic done.");
        }
        public SpriteBatchNodeAliased()
        {
            CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 10);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.SharedDirector.WinSize;

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

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

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

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

            sprite1.RunAction(repeat);
            sprite2.RunAction(repeat2);
        }
예제 #4
0
 public CCParallaxScrollNode(CCSpriteSheet sheet)
 {
     m_SpriteSheet = sheet;
     m_ScrollOffsets = new List<CCParallaxScrollOffset>();
     m_Batch = new CCSpriteBatchNode(sheet.Frames[0].Texture);
     PTMRatio = kDefaultPTMRatio;
 }
예제 #5
0
 public CCParallaxScrollNode(CCSpriteSheet sheet)
 {
     m_SpriteSheet   = sheet;
     m_ScrollOffsets = new List <CCParallaxScrollOffset>();
     m_Batch         = new CCSpriteBatchNode(sheet.Frames[0].Texture);
     PTMRatio        = kDefaultPTMRatio;
 }
예제 #6
0
        public SpriteBatchNodeZOrder()
        {
            m_dir = 1;

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

            CCSize s = CCDirector.SharedDirector.WinSize;

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

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

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

            Schedule(reorderSprite, 1);
        }
예제 #7
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 = new CCSpriteBatchNode("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;
        }
예제 #8
0
        public override void initWithQuantityOfNodes(int nNodes)
        {
            batchNode = new CCSpriteBatchNode("Images/spritesheet1");
            AddChild(batchNode);

            base.initWithQuantityOfNodes(nNodes);

            ScheduleUpdate();
        }
        internal virtual bool InitWithFile(string file, CCRect rect, CCRect capInsets)
        {
            Debug.Assert(!string.IsNullOrEmpty(file), "Invalid file for sprite");

            CCSpriteBatchNode batchnode = new CCSpriteBatchNode(file, 9);
            bool pReturn = InitWithBatchNode(batchnode, rect, capInsets);

            return(pReturn);
        }
예제 #10
0
		public MainLayer ()
		{
			var batchnode = new CCSpriteBatchNode("Images/sprites",10);
			AddChild (batchnode, -1, (int)Tags.SpriteManager);

			var background = new CCSprite(batchnode.Texture, new CCRect(0,0,320,480));
            background.Position = new CCPoint (160,240);
			batchnode.AddChild (background);
		}
        internal virtual bool InitWithSpriteFrame(CCSpriteFrame spriteFrame, CCRect capInsets)
        {
            Debug.Assert(spriteFrame != null, "Sprite frame must be not nil");

            CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9);
            bool pReturn = InitWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, capInsets);

            return(pReturn);
        }
예제 #12
0
        public SpriteBatchNode1()
        {
            TouchEnabled = true;

            CCSpriteBatchNode BatchNode = new CCSpriteBatchNode("Images/grossini_dance_atlas", 50);
            AddChild(BatchNode, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.SharedDirector.WinSize;
            addNewSpriteWithCoords(new CCPoint(s.Width / 2, s.Height / 2));
        }
        public SpriteChildrenVisibilityIssue665()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

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

            CCNode aParent;
            CCSprite sprite1, sprite2, sprite3;
            //
            // SpriteBatchNode
            //
            // parents
            aParent = new CCSpriteBatchNode("animations/grossini", 50);
            aParent.Position = (new CCPoint(s.Width / 3, s.Height / 2));
            AddChild(aParent, 0);

            sprite1 = new CCSprite("grossini_dance_01.png");
            sprite1.Position = (new CCPoint(0, 0));

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

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

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

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

            //
            // Sprite
            //
            aParent = new CCNode ();
            aParent.Position = (new CCPoint(2 * s.Width / 3, s.Height / 2));
            AddChild(aParent, 0);

            sprite1 = new CCSprite("grossini_dance_01.png");
            sprite1.Position = (new CCPoint(0, 0));

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

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

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

            aParent.AddChild(sprite1);
            sprite1.AddChild(sprite2, -2);
            sprite1.AddChild(sprite3, 2);
        }
예제 #14
0
        public SpriteHybrid()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

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

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


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


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

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

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

            m_usingSpriteBatchNode = false;

            Schedule(reparentSprite, 2);
        }
예제 #15
0
        public bool InitWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets)
        {
            if (batchnode != null)
            {
                UpdateWithBatchNode(batchnode, rect, rotated, capInsets);
                AnchorPoint = new CCPoint(0.5f, 0.5f);
            }
            m_positionsAreDirty = true;

            return(true);
        }
        public void SetSpriteFrame(CCSpriteFrame spriteFrame)
        {
            CCSpriteBatchNode batchnode = new CCSpriteBatchNode(spriteFrame.Texture, 9);

            UpdateWithBatchNode(batchnode, spriteFrame.Rect, spriteFrame.IsRotated, CCRect.Zero);

            // Reset insets
            m_insetLeft   = 0;
            m_insetTop    = 0;
            m_insetRight  = 0;
            m_insetBottom = 0;
        }
        public SpriteBatchNodeNewTexture()
        {
            TouchEnabled = true;

            CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 50);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            m_texture1 = batch.Texture;
            m_texture2 = CCTextureCache.SharedTextureCache.AddImage("Images/grossini_dance_atlas-mono");

            for (int i = 0; i < 30; i++)
                addNewSprite();
        }
예제 #18
0
        public override void OnEnter()
        {
            base.OnEnter();
            CCSize s = CCDirector.SharedDirector.WinSize;

            // IMPORTANT:
            // The sprite frames will be cached AND RETAINED, and they won't be released unless you call
            //     [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
            //
            // CCSpriteFrameCache is a cache of CCSpriteFrames
            // CCSpriteFrames each contain a texture id and a rect (frame).

            CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
            cache.AddSpriteFramesWithFile("animations/grossini-aliases.plist", "animations/grossini-aliases");

            //
            // Animation using Sprite batch
            //
            // A CCSpriteBatchNode can reference one and only one texture (one .png file)
            // Sprites that are contained in that texture can be instantiatied as CCSprites and then added to the CCSpriteBatchNode
            // All CCSprites added to a CCSpriteBatchNode are drawn in one OpenGL ES draw call
            // If the CCSprites are not added to a CCSpriteBatchNode then an OpenGL ES draw call will be needed for each one, which is less efficient
            //
            // When you animate a sprite, CCAnimation changes the frame of the sprite using setDisplayFrame: (this is why the animation must be in the same texture)
            // When setDisplayFrame: is used in the CCAnimation it changes the frame to one specified by the CCSpriteFrames that were added to the animation,
            // but texture id is still the same and so the sprite is still a child of the CCSpriteBatchNode, 
            // and therefore all the animation sprites are also drawn as part of the CCSpriteBatchNode
            //

            CCSprite sprite = new CCSprite("grossini_dance_01.png");
            sprite.Position = (new CCPoint(s.Width * 0.5f, s.Height * 0.5f));

            CCSpriteBatchNode spriteBatch = new CCSpriteBatchNode("animations/grossini-aliases");
            spriteBatch.AddChild(sprite);
            AddChild(spriteBatch);

            var animFrames = new List<CCSpriteFrame>(15);
            string str = "";
            for (int i = 1; i < 15; i++)
            {
                // Obtain frames by alias name
                str = string.Format("dance_{0:00}", i);
                CCSpriteFrame frame = cache.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = new CCAnimation(animFrames, 0.3f);
            // 14 frames * 1sec = 14 seconds
            sprite.RunAction(new CCRepeatForever (new CCAnimate (animation)));
        }
        public SpriteBatchNodeReorderIssue744()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            // Testing issue #744
            // http://code.google.com/p/cocos2d-iphone/issues/detail?id=744
            CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 15);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSprite sprite = new CCSprite(batch.Texture, new CCRect(0, 0, 85, 121));
            sprite.Position = (new CCPoint(s.Width / 2, s.Height / 2));
            batch.AddChild(sprite, 3);
            batch.ReorderChild(sprite, 1);
        }
예제 #20
0
        public SpriteBatchNodeReorder()
        {
            List<Object> a = new List<Object>(10);
            CCSpriteBatchNode asmtest = new CCSpriteBatchNode("animations/ghosts");

            for (int i = 0; i < 10; i++)
            {
                CCSprite s1 = new CCSprite(asmtest.Texture, new CCRect(0, 0, 50, 50));
                a.Add(s1);
                asmtest.AddChild(s1, 10);
            }

            for (int i = 0; i < 10; i++)
            {
                if (i != 5)
                {
                    asmtest.ReorderChild((CCNode) (a[i]), 9);
                }
            }

            int prev = -1;
            var children = asmtest.Children;
            CCSprite child;
            foreach (var item in children)
            {
                child = (CCSprite)item;
                if (child == null)
                    break;

                int currentIndex = child.AtlasIndex;
                Debug.Assert(prev == currentIndex - 1, "Child order failed");
                ////----UXLOG("children %x - atlasIndex:%d", child, currentIndex);
                prev = currentIndex;
            }

            prev = -1;
            var sChildren = asmtest.Descendants;
            foreach (var item in sChildren)
            {
                child = (CCSprite)item;
                if (child == null)
                    break;

                int currentIndex = child.AtlasIndex;
                Debug.Assert(prev == currentIndex - 1, "Child order failed");
                ////----UXLOG("descendant %x - atlasIndex:%d", child, currentIndex);
                prev = currentIndex;
            }
        }
예제 #21
0
        public bool InitWithTexture(CCTexture2D pTexture, CCRect rect, bool rotated)
        {
            m_pobBatchNode = null;

            // shader program
            //setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));

            m_bRecursiveDirty = false;
            Dirty             = false;

            m_bOpacityModifyRGB = true;
            m_nOpacity          = 255;
            m_sColor            = m_sColorUnmodified = CCTypes.CCWhite;

            m_sBlendFunc.Source      = CCMacros.CCDefaultSourceBlending;
            m_sBlendFunc.Destination = CCMacros.CCDefaultDestinationBlending;

            m_bFlipX = m_bFlipY = false;

            // default transform anchor: center
            AnchorPoint = new CCPoint(0.5f, 0.5f);

            // zwoptex default values
            m_obOffsetPosition = CCPoint.Zero;

            m_bHasChildren = false;

            // clean the Quad
            m_sQuad = new CCV3F_C4B_T2F_Quad();

            // Atlas: Color
            var tmpColor = new CCColor4B(255, 255, 255, 255);

            m_sQuad.BottomLeft.Colors  = tmpColor;
            m_sQuad.BottomRight.Colors = tmpColor;
            m_sQuad.TopLeft.Colors     = tmpColor;
            m_sQuad.TopRight.Colors    = tmpColor;

            // update texture (calls updateBlendFunc)
            Texture = pTexture;
            SetTextureRect(rect, rotated, rect.Size);

            // by default use "Self Render".
            // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
            BatchNode = null;

            return(true);
        }
        public SpriteBatchNodeReorderIssue766()
        {
            batchNode = new CCSpriteBatchNode("Images/piece", 15);
            AddChild(batchNode, 1, 0);

            sprite1 = makeSpriteZ(2);
            sprite1.Position = (new CCPoint(200, 160));

            sprite2 = makeSpriteZ(3);
            sprite2.Position = (new CCPoint(264, 160));

            sprite3 = makeSpriteZ(4);
            sprite3.Position = (new CCPoint(328, 160));

            Schedule(reorderSprite, 2);
        }
예제 #23
0
        public override void RemoveAllChildrenWithCleanup(bool cleanup)
        {
            if (m_pobBatchNode != null)
            {
                CCSpriteBatchNode batch    = m_pobBatchNode;
                CCNode[]          elements = m_pChildren.Elements;
                for (int i = 0, count = m_pChildren.count; i < count; i++)
                {
                    batch.RemoveSpriteFromAtlas((CCSprite)elements[i]);
                }
            }

            base.RemoveAllChildrenWithCleanup(cleanup);

            m_bHasChildren = false;
        }
예제 #24
0
        public SpriteBatchNodeFlip()
        {
            CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 10);
            AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode);

            CCSize s = CCDirector.SharedDirector.WinSize;

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

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

            Schedule(flipSprites, 1);
        }
        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.
            //


            CCSize s = CCDirector.SharedDirector.WinSize;
            float step = s.Width / 12;

            // 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);
            // camera uses the center of the image as the pivoting point
            batch.ContentSize = new CCSize(s.Width, s.Height);
            batch.AnchorPoint = (new CCPoint(0.5f, 0.5f));
            batch.Position = (new CCPoint(s.Width / 2, s.Height / 2));


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

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

            }

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

            batch.RunAction(new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0));
        }
예제 #26
0
        public SpriteSubclass()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/ghosts.plist");
            CCSpriteBatchNode aParent = new CCSpriteBatchNode("animations/ghosts");

            // MySprite1
            MySprite1 sprite = MySprite1.Create("father.gif");
            sprite.Position = (new CCPoint(s.Width / 4 * 1, s.Height / 2));
            aParent.AddChild(sprite);
            AddChild(aParent);

            // MySprite2
            MySprite2 sprite2 = MySprite2.Create("Images/grossini");
            AddChild(sprite2);
            sprite2.Position = (new CCPoint(s.Width / 4 * 3, s.Height / 2));
        }
        public SpriteBatchNodeAnchorPoint()
        {
            // 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);

            CCSize s = CCDirector.SharedDirector.WinSize;


            CCActionInterval rotate = new CCRotateBy (10, 360);
            CCAction action = new CCRepeatForever (rotate);
            for (int i = 0; i < 3; i++)
            {
                CCSprite sprite = new CCSprite(batch.Texture, new CCRect(85 * i, 121 * 1, 85, 121));
                sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2));

                CCSprite point = new CCSprite("Images/r1");
                point.Scale = 0.25f;
                point.Position = sprite.Position;
                AddChild(point, 1);

                switch (i)
                {
                    case 0:
                        sprite.AnchorPoint = new CCPoint(0, 0);
                        break;
                    case 1:
                        sprite.AnchorPoint = (new CCPoint(0.5f, 0.5f));
                        break;
                    case 2:
                        sprite.AnchorPoint = (new CCPoint(1, 1));
                        break;
                }

                point.Position = sprite.Position;

                CCAction copy = (CCAction)(action.Copy());
                sprite.RunAction(copy);
                batch.AddChild(sprite, i);
            }
        }
예제 #28
0
        public Sprite6()
        {
            // 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, kTagSpriteBatchNode);
            batch.IgnoreAnchorPointForPosition = true;

            CCSize s = CCDirector.SharedDirector.WinSize;

            batch.AnchorPoint = new CCPoint(0.5f, 0.5f);
            batch.ContentSize = (new CCSize(s.Width, s.Height));


            // SpriteBatchNode actions
            CCActionInterval rotate = new CCRotateBy (5, 360);
            CCAction action = new CCRepeatForever (rotate);

            // SpriteBatchNode actions
            CCActionInterval rotate_back = (CCActionInterval)rotate.Reverse();
            CCActionInterval rotate_seq = (CCActionInterval)(CCSequence.FromActions(rotate, rotate_back));
            CCAction rotate_forever = new CCRepeatForever (rotate_seq);

            CCActionInterval scale = new CCScaleBy(5, 1.5f);
            CCActionInterval scale_back = (CCActionInterval)scale.Reverse();
            CCActionInterval scale_seq = (CCActionInterval)(CCSequence.FromActions(scale, scale_back));
            CCAction scale_forever = new CCRepeatForever (scale_seq);

            float step = s.Width / 4;

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

                sprite.RunAction((CCAction)(action.Copy()));
                batch.AddChild(sprite, i);
            }

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

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

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


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

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

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

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

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


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

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


            Schedule(removeAndAddSprite, 2);
        }
예제 #30
0
        public SpriteBatchNodeChildren()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

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

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

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

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

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

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

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

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

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

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

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

            sprite1.RunAction((CCAction)(new CCRepeatForever (action_rot)));
            sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(new CCSequence(action, action_back)))));
            sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(new CCSequence(action_s, action_s_back)))));

        }
예제 #31
0
        public void initWithSubTest(int nSubTest, CCNode p)
        {
            subtestNumber = nSubTest;
            parent = p;
            batchNode = null;
            /*
            * Tests:
            * 1: 1 (32-bit) PNG sprite of 52 x 139
            * 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
            * 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
            * 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139

            * 5: 14 (32-bit) PNG sprites of 85 x 121 each
            * 6: 14 (32-bit) PNG Batch Node of 85 x 121 each
            * 7: 14 (16-bit) PNG Batch Node of 85 x 121 each
            * 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each

            * 9: 64 (32-bit) sprites of 32 x 32 each
            *10: 64 (32-bit) PNG Batch Node of 32 x 32 each
            *11: 64 (16-bit) PNG Batch Node of 32 x 32 each
            *12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each
            */

            // purge textures
            CCTextureCache mgr = CCTextureCache.SharedTextureCache;
            //		[mgr removeAllTextures];
            mgr.RemoveTexture(mgr.AddImage("Images/grossinis_sister1"));
            mgr.RemoveTexture(mgr.AddImage("Images/grossini_dance_atlas"));
            mgr.RemoveTexture(mgr.AddImage("Images/spritesheet1"));

            switch (subtestNumber)
            {
                case 1:
                case 4:
                case 7:
                    break;

                case 2:
                    CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA8888;
                    batchNode = new CCSpriteBatchNode("Images/grossinis_sister1", 100);
                    p.AddChild(batchNode, 0);
                    break;
                
                case 3:
                    CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA4444;
                    batchNode = new CCSpriteBatchNode("Images/grossinis_sister1", 100);
                    p.AddChild(batchNode, 0);
                    break;

                case 5:
                    CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA8888;
                    batchNode = new CCSpriteBatchNode("Images/grossini_dance_atlas", 100);
                    p.AddChild(batchNode, 0);
                    break;

                case 6:
                    CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA4444;
                    batchNode = new CCSpriteBatchNode("Images/grossini_dance_atlas", 100);
                    p.AddChild(batchNode, 0);
                    break;

                    ///
                case 8:
                    CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA8888;
                    batchNode = new CCSpriteBatchNode("Images/spritesheet1", 100);
                    p.AddChild(batchNode, 0);
                    break;
                case 9:
                    CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.RGBA4444;
                    batchNode = new CCSpriteBatchNode("Images/spritesheet1", 100);
                    p.AddChild(batchNode, 0);
                    break;

                default:
                    break;
            }

            //if (batchNode != null)
            //{
            //    batchNode.retain();
            //}

            CCTexture2D.DefaultAlphaPixelFormat = CCTexture2DPixelFormat.Default;
        }
예제 #32
0
 public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCSize bounds, bool rotated, CCRect capInsets)
 {
     return(UpdateWithBatchNode(batchnode, bounds.AsRect, rotated, capInsets));
 }
        public override bool Init()
        {
            if (base.Init())
            {
                TouchEnabled = true;
                // Cache the sprites
                CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile(
                    "extensions/CCControlColourPickerSpriteSheet.plist");

                // Create the sprite batch node
                var spriteSheet = new CCSpriteBatchNode("extensions/CCControlColourPickerSpriteSheet.png");
                AddChild(spriteSheet);

                // MIPMAP
//        ccTexParams params  = {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};

                /* Comment next line to avoid something like mosaic in 'ControlExtensionTest',
                 * especially the display of 'huePickerBackground.png' when in 800*480 window size with 480*320 design resolution and hd(960*640) resources.
                 */
//        spriteSheet->getTexture()->setAliasTexParameters();
//         spriteSheet->getTexture()->setTexParameters(&params);
//         spriteSheet->getTexture()->generateMipmap();

                // Init default color
                _hsv.h = 0;
                _hsv.s = 0;
                _hsv.v = 0;

                // Add image
                _background = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png",
                                                                               spriteSheet, CCPoint.Zero,
                                                                               new CCPoint(0.5f, 0.5f));

                CCPoint backgroundPointZero = _background.Position -
                                              new CCPoint(_background.ContentSize.Width / 2,
                                                          _background.ContentSize.Height / 2);

                // Setup panels
                float hueShift    = 8;
                float colourShift = 28;

                _huePicker = new CCControlHuePicker();
                _huePicker.InitWithTargetAndPos(spriteSheet,
                                                new CCPoint(backgroundPointZero.X + hueShift,
                                                            backgroundPointZero.Y + hueShift));
                _colourPicker = new CCControlSaturationBrightnessPicker();
                _colourPicker.InitWithTargetAndPos(spriteSheet,
                                                   new CCPoint(backgroundPointZero.X + colourShift,
                                                               backgroundPointZero.Y + colourShift));

                // Setup events
                _huePicker.AddTargetWithActionForControlEvents(this, HueSliderValueChanged,
                                                               CCControlEvent.ValueChanged);
                _colourPicker.AddTargetWithActionForControlEvents(this, ColourSliderValueChanged,
                                                                  CCControlEvent.ValueChanged);

                // Set defaults
                UpdateHueAndControlPicker();
                AddChild(_huePicker);
                AddChild(_colourPicker);

                // Set content size
                ContentSize = _background.ContentSize;
                return(true);
            }
            return(false);
        }
예제 #34
0
        public override bool Init()
        {
            if (base.Init())
            {
                TouchEnabled = true;
                // Cache the sprites
                CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile(
                    "extensions/CCControlColourPickerSpriteSheet.plist");

                // Create the sprite batch node
                var spriteSheet = new CCSpriteBatchNode("extensions/CCControlColourPickerSpriteSheet.png");
                AddChild(spriteSheet);

                // MIPMAP
//        ccTexParams params  = {GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
                /* Comment next line to avoid something like mosaic in 'ControlExtensionTest',
		   especially the display of 'huePickerBackground.png' when in 800*480 window size with 480*320 design resolution and hd(960*640) resources.
	    */
//        spriteSheet->getTexture()->setAliasTexParameters();
//         spriteSheet->getTexture()->setTexParameters(&params);
//         spriteSheet->getTexture()->generateMipmap();

                // Init default color
                _hsv.h = 0;
                _hsv.s = 0;
                _hsv.v = 0;

                // Add image
                _background = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png",
                                                                               spriteSheet, CCPoint.Zero,
                                                                               new CCPoint(0.5f, 0.5f));

                CCPoint backgroundPointZero = _background.Position -
                                              new CCPoint(_background.ContentSize.Width / 2,
                                                          _background.ContentSize.Height / 2);

                // Setup panels
                float hueShift = 8;
                float colourShift = 28;

                _huePicker = new CCControlHuePicker();
                _huePicker.InitWithTargetAndPos(spriteSheet,
                                                new CCPoint(backgroundPointZero.X + hueShift,
                                                            backgroundPointZero.Y + hueShift));
                _colourPicker = new CCControlSaturationBrightnessPicker();
                _colourPicker.InitWithTargetAndPos(spriteSheet,
                                                   new CCPoint(backgroundPointZero.X + colourShift,
                                                               backgroundPointZero.Y + colourShift));

                // Setup events
                _huePicker.AddTargetWithActionForControlEvents(this, HueSliderValueChanged,
                                                               CCControlEvent.ValueChanged);
                _colourPicker.AddTargetWithActionForControlEvents(this, ColourSliderValueChanged,
                                                                  CCControlEvent.ValueChanged);

                // Set defaults
                UpdateHueAndControlPicker();
                AddChild(_huePicker);
                AddChild(_colourPicker);

                // Set content size
                ContentSize = _background.ContentSize;
                return true;
            }
            return false;
        }
예제 #35
0
 /// <summary>
 /// Constructs the infinite scrolling background node with the given texture sheet, which is the root texture
 /// of the child sprite batch node.
 /// </summary>
 /// <param name="textureName"></param>
 public CCParallaxScrollNode(string textureName)
 {
     m_ScrollOffsets = new List<CCParallaxScrollOffset>();
     m_Batch = new CCSpriteBatchNode(textureName);
     PTMRatio = kDefaultPTMRatio;
 }
        public SpriteBatchNodeOffsetAnchorScale()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

            for (int i = 0; i < 3; i++)
            {
                CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache;
                cache.AddSpriteFramesWithFile("animations/grossini.plist");
                cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray");

                //
                // Animation using Sprite BatchNode
                //
                CCSprite sprite = new CCSprite("grossini_dance_01.png");
                sprite.Position = (new CCPoint(s.Width / 4 * (i + 1), s.Height / 2));

                CCSprite point = new CCSprite("Images/r1");
                point.Scale = 0.25f;
                point.Position = sprite.Position;
                AddChild(point, 200);

                switch (i)
                {
                    case 0:
                        sprite.AnchorPoint = new CCPoint(0, 0);
                        break;
                    case 1:
                        sprite.AnchorPoint = new CCPoint(0.5f, 0.5f);
                        break;
                    case 2:
                        sprite.AnchorPoint = new CCPoint(1, 1);
                        break;
                }

                point.Position = sprite.Position;

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

                var animFrames = new List<CCSpriteFrame>(14);
                string str = "";
                for (int k = 0; k < 14; k++)
                {
                    string temp = "";
                    if (k+1<10)
                    {
                        temp = "0" + (k + 1);
                    }
                    else
                    {
                        temp = (k + 1).ToString();
                    }
                    str = string.Format("grossini_dance_{0}.png", temp);
                    CCSpriteFrame frame = cache.SpriteFrameByName(str);
                    animFrames.Add(frame);
                }

                CCAnimation animation = new CCAnimation(animFrames, 0.3f);
                sprite.RunAction(new CCRepeatForever (new CCAnimate (animation)));

                CCActionInterval scale = new CCScaleBy(2, 2);
                CCActionInterval scale_back = (CCActionInterval)scale.Reverse();
                CCActionInterval seq_scale = (CCActionInterval)(new CCSequence(scale, scale_back));
                sprite.RunAction(new CCRepeatForever (seq_scale));

                spritesheet.AddChild(sprite, i);

                //animFrames->release();    // win32 : memory leak    2010-0415
            }
        }
예제 #37
0
        public SpriteFrameTest()
        {
            CCSize s = CCDirector.SharedDirector.WinSize;

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

            //
            // Animation using Sprite BatchNode
            //
            m_pSprite1 = new CCSprite("grossini_dance_01.png");
            m_pSprite1.Position = (new CCPoint(s.Width / 2 -80, s.Height / 2));

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

            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.SpriteFrameByName(str);
                animFrames.Add(frame);
            }

            CCAnimation animation = new CCAnimation(animFrames, 0.3f);
            m_pSprite1.RunAction(new CCRepeatForever (new CCAnimate (animation)));

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

            //
            // Animation using standard Sprite
            //
            m_pSprite2 = new CCSprite("grossini_dance_01.png");
            m_pSprite2.Position = (new CCPoint(s.Width / 2 + 80, s.Height / 2));
            AddChild(m_pSprite2);


            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.SpriteFrameByName(str);
                moreFrames.Add(frame);
            }


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

            // append frames from another batch
            moreFrames.AddRange(animFrames);
            CCAnimation animMixed = new CCAnimation(moreFrames, 0.3f);


            m_pSprite2.RunAction(new CCRepeatForever (new CCAnimate (animMixed)));



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

            Schedule(startIn05Secs, 0.5f);
            m_nCounter = 0;
        }
예제 #38
0
        public bool InitWithTexture(CCTexture2D pTexture, CCRect rect, bool rotated)
        {
            base.Init();

            m_pobBatchNode = null;

            // shader program
            //setShaderProgram(CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor));

            m_bRecursiveDirty = false;
            Dirty = false;

            m_bOpacityModifyRGB = true;
            m_sBlendFunc = CCBlendFunc.AlphaBlend;

            m_bFlipX = m_bFlipY = false;

            // default transform anchor: center
            AnchorPoint = new CCPoint(0.5f, 0.5f);

            // zwoptex default values
            m_obOffsetPosition = CCPoint.Zero;

            m_bHasChildren = false;

            // clean the Quad
            m_sQuad = new CCV3F_C4B_T2F_Quad();

            // Atlas: Color
            var tmpColor = new CCColor4B(255, 255, 255, 255);
            m_sQuad.BottomLeft.Colors = tmpColor;
            m_sQuad.BottomRight.Colors = tmpColor;
            m_sQuad.TopLeft.Colors = tmpColor;
            m_sQuad.TopRight.Colors = tmpColor;

            // update texture (calls updateBlendFunc)
            Texture = pTexture;
            SetTextureRect(rect, rotated, rect.Size);

            // by default use "Self Render".
            // if the sprite is added to a batchnode, then it will automatically switch to "batchnode Render"
            BatchNode = null;

            return true;
        }
예제 #39
0
        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 = new CCSpriteBatchNode("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", "MarkerFelt", 32);
            AddChild(label, 0);
            label.Color = new CCColor3B(0, 0, 255);
            label.Position = new CCPoint(s.Width / 2, s.Height - 50);

            ScheduleUpdate();
        }
        public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets)
        {
            var opacity = Opacity;
            var color   = Color;

            // Release old sprites
            RemoveAllChildrenWithCleanup(true);

            _scale9Image = batchnode;

            _scale9Image.RemoveAllChildrenWithCleanup(true);

            m_capInsets = capInsets;

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

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

            // Set the given rect's size as original size
            m_spriteRect        = rect;
            m_originalSize      = rect.Size;
            m_preferredSize     = m_originalSize;
            m_capInsetsInternal = capInsets;

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

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

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

            float top_h    = m_capInsetsInternal.Origin.Y;
            float center_h = m_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)
            {
                // CCLog("!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();
                _centre.InitWithTexture(_scale9Image.Texture, centerbounds);
                _scale9Image.AddChild(_centre, 0, (int)Positions.Centre);

                // Top
                _top = new CCSprite();
                _top.InitWithTexture(_scale9Image.Texture, centertopbounds);
                _scale9Image.AddChild(_top, 1, (int)Positions.Top);

                // Bottom
                _bottom = new CCSprite();
                _bottom.InitWithTexture(_scale9Image.Texture, centerbottombounds);
                _scale9Image.AddChild(_bottom, 1, (int)Positions.Bottom);

                // Left
                _left = new CCSprite();
                _left.InitWithTexture(_scale9Image.Texture, leftcenterbounds);
                _scale9Image.AddChild(_left, 1, (int)Positions.Left);

                // Right
                _right = new CCSprite();
                _right.InitWithTexture(_scale9Image.Texture, rightcenterbounds);
                _scale9Image.AddChild(_right, 1, (int)Positions.Right);

                // Top left
                _topLeft = new CCSprite();
                _topLeft.InitWithTexture(_scale9Image.Texture, lefttopbounds);
                _scale9Image.AddChild(_topLeft, 2, (int)Positions.TopLeft);

                // Top right
                _topRight = new CCSprite();
                _topRight.InitWithTexture(_scale9Image.Texture, righttopbounds);
                _scale9Image.AddChild(_topRight, 2, (int)Positions.TopRight);

                // Bottom left
                _bottomLeft = new CCSprite();
                _bottomLeft.InitWithTexture(_scale9Image.Texture, leftbottombounds);
                _scale9Image.AddChild(_bottomLeft, 2, (int)Positions.BottomLeft);

                // Bottom right
                _bottomRight = new CCSprite();
                _bottomRight.InitWithTexture(_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();
                _centre.InitWithTexture(_scale9Image.Texture, rotatedcenterbounds, true);
                _scale9Image.AddChild(_centre, 0, (int)Positions.Centre);

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

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

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

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

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

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

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

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

            ContentSize = rect.Size;
            AddChild(_scale9Image);

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

            return(true);
        }
 public bool InitWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, CCRect capInsets)
 {
     return(InitWithBatchNode(batchnode, rect, false, capInsets));
 }
예제 #42
0
        public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets)
        {
            byte      opacity = m_cOpacity;
            CCColor3B color   = m_tColor;

            // Release old sprites
            RemoveAllChildrenWithCleanup(true);

            if (scale9Image != batchnode)
            {
                scale9Image = batchnode;
            }

            scale9Image.RemoveAllChildrenWithCleanup(true);

            m_capInsets = capInsets;

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

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

            // Set the given rect's size as original size
            m_spriteRect        = rect;
            m_originalSize      = rect.Size;
            m_preferredSize     = m_originalSize;
            m_capInsetsInternal = capInsets;

            // Get the image edges
            float l = rect.Origin.X;
            float t = rect.Origin.Y;
            float h = rect.Size.Height;
            float w = rect.Size.Width;

            // If there is no specified center region
            if (m_capInsetsInternal.Equals(CCRect.Zero))
            {
                // Apply the 3x3 grid format
                if (rotated)
                {
                    m_capInsetsInternal = new CCRect(l + h / 3, t + w / 3, w / 3, h / 3);
                }
                else
                {
                    m_capInsetsInternal = new CCRect(l + w / 3, t + h / 3, w / 3, h / 3);
                }
            }

            //
            // Set up the image
            //
            if (rotated)
            {
                // Sprite frame is rotated

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

                // Bottom
                bottom = new CCSprite();
                bottom.InitWithTexture(scale9Image.Texture, new CCRect(l,
                                                                       m_capInsetsInternal.Origin.Y,
                                                                       m_capInsetsInternal.Size.Width,
                                                                       m_capInsetsInternal.Origin.X - l),
                                       rotated
                                       );
                scale9Image.AddChild(bottom, 1, (int)Positions.pBottom);

                // Top
                top = new CCSprite();
                top.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height,
                                                                    m_capInsetsInternal.Origin.Y,
                                                                    m_capInsetsInternal.Size.Width,
                                                                    h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)),
                                    rotated
                                    );
                scale9Image.AddChild(top, 1, (int)Positions.pTop);

                // Right
                right = new CCSprite();
                right.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                      m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width,
                                                                      w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width,
                                                                      m_capInsetsInternal.Size.Height),
                                      rotated
                                      );
                scale9Image.AddChild(right, 1, (int)Positions.pRight);

                // Left
                left = new CCSprite();
                left.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                     t,
                                                                     m_capInsetsInternal.Origin.Y - t,
                                                                     m_capInsetsInternal.Size.Height),
                                     rotated
                                     );
                scale9Image.AddChild(left, 1, (int)Positions.pLeft);

                // Top right
                topRight = new CCSprite();
                topRight.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height,
                                                                         m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width,
                                                                         w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width,
                                                                         h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)),
                                         rotated
                                         );
                scale9Image.AddChild(topRight, 2, (int)Positions.pTopRight);

                // Top left
                topLeft = new CCSprite();
                topLeft.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Height,
                                                                        t,
                                                                        m_capInsetsInternal.Origin.Y - t,
                                                                        h - m_capInsetsInternal.Size.Height - (m_capInsetsInternal.Origin.X - l)),
                                        rotated
                                        );
                scale9Image.AddChild(topLeft, 2, (int)Positions.pTopLeft);

                // Bottom right
                bottomRight = new CCSprite();
                bottomRight.InitWithTexture(scale9Image.Texture, new CCRect(l,
                                                                            m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Width,
                                                                            w - (m_capInsetsInternal.Origin.Y - t) - m_capInsetsInternal.Size.Width,
                                                                            m_capInsetsInternal.Origin.X - l),
                                            rotated
                                            );
                scale9Image.AddChild(bottomRight, 2, (int)Positions.pBottomRight);

                // Bottom left
                bottomLeft = new CCSprite();
                bottomLeft.InitWithTexture(scale9Image.Texture, new CCRect(l,
                                                                           t,
                                                                           m_capInsetsInternal.Origin.Y - t,
                                                                           m_capInsetsInternal.Origin.X - l),
                                           rotated
                                           );
                scale9Image.AddChild(bottomLeft, 2, (int)Positions.pBottomLeft);
            }
            else
            {
                // Sprite frame is not rotated
                // Centre
                centre = new CCSprite();
                centre.InitWithTexture(scale9Image.Texture, m_capInsetsInternal, rotated);
                scale9Image.AddChild(centre, 0, (int)Positions.pCentre);

                // Top
                top = new CCSprite();
                top.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                    t,
                                                                    m_capInsetsInternal.Size.Width,
                                                                    m_capInsetsInternal.Origin.Y - t),
                                    rotated
                                    );
                scale9Image.AddChild(top, 1, (int)Positions.pTop);

                // Bottom
                bottom = new CCSprite();
                bottom.InitWithTexture(scale9Image.Texture, new CCRect(m_capInsetsInternal.Origin.X,
                                                                       m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height,
                                                                       m_capInsetsInternal.Size.Width,
                                                                       h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)),
                                       rotated);
                scale9Image.AddChild(bottom, 1, (int)Positions.pBottom);

                // Left
                left = new CCSprite();
                left.InitWithTexture(scale9Image.Texture, new CCRect(
                                         l,
                                         m_capInsetsInternal.Origin.Y,
                                         m_capInsetsInternal.Origin.X - l,
                                         m_capInsetsInternal.Size.Height),
                                     rotated);
                scale9Image.AddChild(left, 1, (int)Positions.pLeft);

                // Right
                right = new CCSprite();
                right.InitWithTexture(scale9Image.Texture, new CCRect(
                                          m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width,
                                          m_capInsetsInternal.Origin.Y,
                                          w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width),
                                          m_capInsetsInternal.Size.Height),
                                      rotated);
                scale9Image.AddChild(right, 1, (int)Positions.pRight);

                // Top left
                topLeft = new CCSprite();
                topLeft.InitWithTexture(scale9Image.Texture, new CCRect(
                                            l,
                                            t,
                                            m_capInsetsInternal.Origin.X - l,
                                            m_capInsetsInternal.Origin.Y - t),
                                        rotated);

                scale9Image.AddChild(topLeft, 2, (int)Positions.pTopLeft);

                // Top right
                topRight = new CCSprite();
                topRight.InitWithTexture(scale9Image.Texture, new CCRect(
                                             m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width,
                                             t,
                                             w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width),
                                             m_capInsetsInternal.Origin.Y - t),
                                         rotated);

                scale9Image.AddChild(topRight, 2, (int)Positions.pTopRight);

                // Bottom left
                bottomLeft = new CCSprite();
                bottomLeft.InitWithTexture(scale9Image.Texture, new CCRect(
                                               l,
                                               m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height,
                                               m_capInsetsInternal.Origin.X - l,
                                               h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)),
                                           rotated);
                scale9Image.AddChild(bottomLeft, 2, (int)Positions.pBottomLeft);

                // Bottom right
                bottomRight = new CCSprite();
                bottomRight.InitWithTexture(scale9Image.Texture, new CCRect(
                                                m_capInsetsInternal.Origin.X + m_capInsetsInternal.Size.Width,
                                                m_capInsetsInternal.Origin.Y + m_capInsetsInternal.Size.Height,
                                                w - (m_capInsetsInternal.Origin.X - l + m_capInsetsInternal.Size.Width),
                                                h - (m_capInsetsInternal.Origin.Y - t + m_capInsetsInternal.Size.Height)),
                                            rotated);
                scale9Image.AddChild(bottomRight, 2, (int)Positions.pBottomRight);
            }

            ContentSize = rect.Size;
            AddChild(scale9Image);

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

            return(true);
        }
예제 #43
0
 /// <summary>
 /// Constructs the infinite scrolling background node with the given texture sheet, which is the root texture
 /// of the child sprite batch node.
 /// </summary>
 /// <param name="textureName"></param>
 public CCParallaxScrollNode(string textureName)
 {
     m_ScrollOffsets = new List <CCParallaxScrollOffset>();
     m_Batch         = new CCSpriteBatchNode(textureName);
     PTMRatio        = kDefaultPTMRatio;
 }