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)(CCSequence.FromActions(scale, scale_back)); CCAction repeat = new CCRepeatForever (seq); CCAction repeat2 = (CCAction)(repeat.Copy()); sprite1.RunAction(repeat); sprite2.RunAction(repeat2); }
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); }
public RenderTextureZbuffer() { //this->setIsTouchEnabled(true); TouchEnabled = true; CCSize size = CCDirector.SharedDirector.WinSize; CCLabelTTF label = new CCLabelTTF("vertexZ = 50", "Marker Felt", 32); label.Position = new CCPoint(size.Width / 2, size.Height * 0.25f); AddChild(label); CCLabelTTF label2 = new CCLabelTTF("vertexZ = 0", "Marker Felt", 32); label2.Position = new CCPoint(size.Width / 2, size.Height * 0.5f); AddChild(label2); CCLabelTTF label3 = new CCLabelTTF("vertexZ = -50", "Marker Felt", 32); label3.Position = new CCPoint(size.Width / 2, size.Height * 0.75f); AddChild(label3); label.VertexZ = 50; label2.VertexZ = 0; label3.VertexZ = -50; CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("Images/bugs/circle.plist"); mgr = CCSpriteBatchNode.Create("Images/bugs/circle", 9); AddChild(mgr); sp1 = new CCSprite("Images/bugs/circle"); sp2 = new CCSprite("Images/bugs/circle"); sp3 = new CCSprite("Images/bugs/circle"); sp4 = new CCSprite("Images/bugs/circle"); sp5 = new CCSprite("Images/bugs/circle"); sp6 = new CCSprite("Images/bugs/circle"); sp7 = new CCSprite("Images/bugs/circle"); sp8 = new CCSprite("Images/bugs/circle"); sp9 = new CCSprite("Images/bugs/circle"); mgr.AddChild(sp1, 9); mgr.AddChild(sp2, 8); mgr.AddChild(sp3, 7); mgr.AddChild(sp4, 6); mgr.AddChild(sp5, 5); mgr.AddChild(sp6, 4); mgr.AddChild(sp7, 3); mgr.AddChild(sp8, 2); mgr.AddChild(sp9, 1); sp1.VertexZ = 400; sp2.VertexZ = 300; sp3.VertexZ = 200; sp4.VertexZ = 100; sp5.VertexZ = 0; sp6.VertexZ = -100; sp7.VertexZ = -200; sp8.VertexZ = -300; sp9.VertexZ = -400; sp9.Scale = 2; sp9.Color = CCTypes.CCYellow; }
public 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); }
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)(CCSequence.FromActions(action, action_back))))); sprite1.RunAction((CCAction)(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(action_s, action_s_back))))); }
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 SpriteBatchNodeReorderIssue767() { CCSize s = CCDirector.SharedDirector.WinSize; string scope = CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/ghosts.plist", "animations/ghosts"); CCNode aParent; CCSprite l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2; // // SpriteBatchNode: 3 levels of children // aParent = new CCSpriteBatchNode("animations/ghosts"); AddChild(aParent, 0, (int) kTagSprite.kTagSprite1); // parent l1 = new CCSprite(scope + "father.gif"); l1.Position = (new CCPoint(s.Width / 2, s.Height / 2)); aParent.AddChild(l1, 0, (int) kTagSprite.kTagSprite2); CCSize l1Size = l1.ContentSize; // child left l2a = new CCSprite(scope + "sister1.gif"); l2a.Position = (new CCPoint(-25 + l1Size.Width / 2, 0 + l1Size.Height / 2)); l1.AddChild(l2a, -1, (int) kTags.kTagSpriteLeft); CCSize l2aSize = l2a.ContentSize; // child right l2b = new CCSprite(scope + "sister2.gif"); l2b.Position = (new CCPoint(+25 + l1Size.Width / 2, 0 + l1Size.Height / 2)); l1.AddChild(l2b, 1, (int) kTags.kTagSpriteRight); CCSize l2bSize = l2a.ContentSize; // child left bottom l3a1 = new CCSprite(scope + "child1.gif"); l3a1.Scale = (0.65f); l3a1.Position = (new CCPoint(0 + l2aSize.Width / 2, -50 + l2aSize.Height / 2)); l2a.AddChild(l3a1, -1); // child left top l3a2 = new CCSprite(scope + "child1.gif"); l3a2.Scale = (0.65f); l3a2.Position = (new CCPoint(0 + l2aSize.Width / 2, +50 + l2aSize.Height / 2)); l2a.AddChild(l3a2, 1); // child right bottom l3b1 = new CCSprite(scope + "child1.gif"); l3b1.Scale = (0.65f); l3b1.Position = (new CCPoint(0 + l2bSize.Width / 2, -50 + l2bSize.Height / 2)); l2b.AddChild(l3b1, -1); // child right top l3b2 = new CCSprite(scope + "child1.gif"); l3b2.Scale = (0.65f); l3b2.Position = (new CCPoint(0 + l2bSize.Width / 2, +50 + l2bSize.Height / 2)); l2b.AddChild(l3b2, 1); Schedule(reorderSprites, 1); }
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)); }
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); }
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); }
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 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; } }
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); } }
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 SpriteBatchNodeOffsetAnchorFlip() { 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 batch // 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 spritebatch = new CCSpriteBatchNode("animations/grossini"); AddChild(spritebatch); var animFrames = new List<CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { string temp = ""; if ( i + 1<10) { temp = "0" + (i+1); } else { temp = (i + 1).ToString(); } tmp = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.SpriteFrameByName(tmp); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever (new CCAnimate (animation))); animFrames = null; CCFlipY flip = new CCFlipY(true); CCFlipY flip_back = new CCFlipY(false); CCDelayTime delay = new CCDelayTime (1); CCFiniteTimeAction seq = CCSequence.FromActions((CCFiniteTimeAction)delay, (CCFiniteTimeAction)flip, (CCFiniteTimeAction)delay.Copy(null), (CCFiniteTimeAction)flip_back); sprite.RunAction(new CCRepeatForever ((CCActionInterval)seq)); spritebatch.AddChild(sprite, i); } }
public SpriteBatchNodeOffsetAnchorSkewScale() { 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 batch // 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 spritebatch = new CCSpriteBatchNode("animations/grossini"); AddChild(spritebatch); var animFrames = new List<CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { string temp = ""; if (j+1<10) { temp = "0" + (j + 1); } else { temp = (j + 1).ToString(); } tmp = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.SpriteFrameByName(tmp); animFrames.Add(frame); } CCAnimation animation = new CCAnimation(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever (new CCAnimate (animation))); animFrames = null; // skew CCSkewBy skewX = new CCSkewBy (2, 45, 0); CCActionInterval skewX_back = (CCActionInterval)skewX.Reverse(); CCSkewBy skewY = new CCSkewBy (2, 0, 45); CCActionInterval skewY_back = (CCActionInterval)skewY.Reverse(); CCFiniteTimeAction seq_skew = CCSequence.FromActions(skewX, skewX_back, skewY, skewY_back); sprite.RunAction(new CCRepeatForever ((CCActionInterval)seq_skew)); // scale CCScaleBy scale = new CCScaleBy(2, 2); CCActionInterval scale_back = (CCActionInterval)scale.Reverse(); CCFiniteTimeAction seq_scale = CCSequence.FromActions(scale, scale_back); sprite.RunAction(new CCRepeatForever ((CCActionInterval)seq_scale)); spritebatch.AddChild(sprite, i); } }
public SpriteBatchNodeChildrenChildren() { CCSize s = CCDirector.SharedDirector.WinSize; CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/ghosts.plist"); CCSpriteBatchNode aParent; CCSprite l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2; CCActionInterval rot = new CCRotateBy (10, 360); CCAction seq = new CCRepeatForever (rot); CCActionInterval rot_back = (CCActionInterval)rot.Reverse(); CCAction rot_back_fe = new CCRepeatForever (rot_back); // // SpriteBatchNode: 3 levels of children // aParent = new CCSpriteBatchNode("animations/ghosts"); aParent.Texture.GenerateMipmap(); AddChild(aParent); // parent l1 = new CCSprite("father.gif"); l1.Position = new CCPoint(s.Width / 2, s.Height / 2); l1.RunAction((CCAction)(seq.Copy())); aParent.AddChild(l1); CCSize l1Size = l1.ContentSize; // child left l2a = new CCSprite("sister1.gif"); l2a.Position = (new CCPoint(-50 + l1Size.Width / 2, 0 + l1Size.Height / 2)); l2a.RunAction((CCAction)(rot_back_fe.Copy())); l1.AddChild(l2a); CCSize l2aSize = l2a.ContentSize; // child right l2b = new CCSprite("sister2.gif"); l2b.Position = (new CCPoint(+50 + l1Size.Width / 2, 0 + l1Size.Height / 2)); l2b.RunAction((CCAction)(rot_back_fe.Copy())); l1.AddChild(l2b); CCSize l2bSize = l2a.ContentSize; // child left bottom l3a1 = new CCSprite("child1.gif"); l3a1.Scale = 0.45f; l3a1.Position = (new CCPoint(0 + l2aSize.Width / 2, -100 + l2aSize.Height / 2)); l2a.AddChild(l3a1); // child left top l3a2 = new CCSprite("child1.gif"); l3a2.Scale = 0.45f; l3a1.Position = (new CCPoint(0 + l2aSize.Width / 2, +100 + l2aSize.Height / 2)); l2a.AddChild(l3a2); // child right bottom l3b1 = new CCSprite("child1.gif"); l3b1.Scale = 0.45f; l3b1.FlipY = true; l3b1.Position = new CCPoint(0 + l2bSize.Width / 2, -100 + l2bSize.Height / 2); l2b.AddChild(l3b1); // child right top l3b2 = new CCSprite("child1.gif"); l3b2.Scale = 0.45f; l3b2.FlipY = true; l3b1.Position = new CCPoint(0 + l2bSize.Width / 2, +100 + l2bSize.Height / 2); l2b.AddChild(l3b2); }
public SpriteBatchNodeChildrenZ() { CCSize s = CCDirector.SharedDirector.WinSize; // parents CCSpriteBatchNode batch; CCSprite sprite1, sprite2, sprite3; CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist"); // test 1 batch = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprite1 = new CCSprite("grossini_dance_01.png"); sprite1.Position = (new CCPoint(s.Width / 3, s.Height / 2)); 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)); batch.AddChild(sprite1); sprite1.AddChild(sprite2, 2); sprite1.AddChild(sprite3, -2); // test 2 batch = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprite1 = new CCSprite("grossini_dance_01.png"); sprite1.Position = (new CCPoint(2 * s.Width / 3, s.Height / 2)); 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)); batch.AddChild(sprite1); sprite1.AddChild(sprite2, -2); sprite1.AddChild(sprite3, 2); // test 3 batch = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprite1 = new CCSprite("grossini_dance_01.png"); sprite1.Position = (new CCPoint(s.Width / 2 - 90, s.Height / 4)); sprite2 = new CCSprite("grossini_dance_02.png"); sprite2.Position = (new CCPoint(s.Width / 2 - 60, s.Height / 4)); sprite3 = new CCSprite("grossini_dance_03.png"); sprite3.Position = (new CCPoint(s.Width / 2 - 30, s.Height / 4)); batch.AddChild(sprite1, 10); batch.AddChild(sprite2, -10); batch.AddChild(sprite3, -5); // test 4 batch = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprite1 = new CCSprite("grossini_dance_01.png"); sprite1.Position = (new CCPoint(s.Width / 2 + 30, s.Height / 4)); sprite2 = new CCSprite("grossini_dance_02.png"); sprite2.Position = (new CCPoint(s.Width / 2 + 60, s.Height / 4)); sprite3 = new CCSprite("grossini_dance_03.png"); sprite3.Position = (new CCPoint(s.Width / 2 + 90, s.Height / 4)); batch.AddChild(sprite1, -10); batch.AddChild(sprite2, -5); batch.AddChild(sprite3, -2); }
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)(CCSequence.FromActions(scale, scale_back)); sprite.RunAction(new CCRepeatForever (seq_scale)); spritesheet.AddChild(sprite, i); //animFrames->release(); // win32 : memory leak 2010-0415 } }
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; }
public SpriteBatchNodeChildrenScale() { CCSize s = CCDirector.SharedDirector.WinSize; CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini_family.plist"); CCNode aParent; CCSprite sprite1, sprite2; CCActionInterval rot = new CCRotateBy (10, 360); CCAction seq = new CCRepeatForever (rot); // // Children + Scale using Sprite // Test 1 // aParent = new CCNode (); sprite1 = new CCSprite("grossinis_sister1.png"); sprite1.Position = new CCPoint(s.Width / 4, s.Height / 4); sprite1.ScaleX = -0.5f; sprite1.ScaleY = 2.0f; sprite1.RunAction(seq); sprite2 = new CCSprite("grossinis_sister2.png"); sprite2.Position = (new CCPoint(50, 0)); AddChild(aParent); aParent.AddChild(sprite1); sprite1.AddChild(sprite2); // // Children + Scale using SpriteBatchNode // Test 2 // aParent = new CCSpriteBatchNode("animations/grossini_family"); sprite1 = new CCSprite("grossinis_sister1.png"); sprite1.Position = new CCPoint(3 * s.Width / 4, s.Height / 4); sprite1.ScaleX = -0.5f; sprite1.ScaleY = 2.0f; sprite1.RunAction((CCAction)(seq.Copy())); sprite2 = new CCSprite("grossinis_sister2.png"); sprite2.Position = (new CCPoint(50, 0)); AddChild(aParent); aParent.AddChild(sprite1); sprite1.AddChild(sprite2); // // Children + Scale using Sprite // Test 3 // aParent = new CCNode (); sprite1 = new CCSprite("grossinis_sister1.png"); sprite1.Position = (new CCPoint(s.Width / 4, 2 * s.Height / 3)); sprite1.ScaleX = (1.5f); sprite1.ScaleY = -0.5f; sprite1.RunAction((CCAction)(seq.Copy())); sprite2 = new CCSprite("grossinis_sister2.png"); sprite2.Position = (new CCPoint(50, 0)); AddChild(aParent); aParent.AddChild(sprite1); sprite1.AddChild(sprite2); // // Children + Scale using Sprite // Test 4 // aParent = new CCSpriteBatchNode("animations/grossini_family"); sprite1 = new CCSprite("grossinis_sister1.png"); sprite1.Position = (new CCPoint(3 * s.Width / 4, 2 * s.Height / 3)); sprite1.ScaleX = 1.5f; sprite1.ScaleY = -0.5f; sprite1.RunAction((CCAction)(seq.Copy())); sprite2 = new CCSprite("grossinis_sister2.png"); sprite2.Position = (new CCPoint(50, 0)); AddChild(aParent); aParent.AddChild(sprite1); sprite1.AddChild(sprite2); }
public SpriteBatchNodeChildrenAnchorPoint() { CCSize s = CCDirector.SharedDirector.WinSize; CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/grossini.plist"); CCNode aParent; CCSprite sprite1, sprite2, sprite3, sprite4, point; // // SpriteBatchNode // // parents aParent = new CCSpriteBatchNode("animations/grossini", 50); AddChild(aParent, 0); // anchor (0,0) sprite1 = new CCSprite("grossini_dance_08.png"); sprite1.Position = (new CCPoint(s.Width / 4, s.Height / 2)); sprite1.AnchorPoint = (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)); sprite4 = new CCSprite("grossini_dance_04.png"); sprite4.Position = (new CCPoint(0, 0)); sprite4.Scale = 0.5f; aParent.AddChild(sprite1); sprite1.AddChild(sprite2, -2); sprite1.AddChild(sprite3, -2); sprite1.AddChild(sprite4, 3); point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = sprite1.Position; AddChild(point, 10); // anchor (0.5, 0.5) sprite1 = new CCSprite("grossini_dance_08.png"); sprite1.Position = (new CCPoint(s.Width / 2, s.Height / 2)); sprite1.AnchorPoint = (new CCPoint(0.5f, 0.5f)); 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)); sprite4 = new CCSprite("grossini_dance_04.png"); sprite4.Position = (new CCPoint(0, 0)); sprite4.Scale = 0.5f; aParent.AddChild(sprite1); sprite1.AddChild(sprite2, -2); sprite1.AddChild(sprite3, -2); sprite1.AddChild(sprite4, 3); point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = sprite1.Position; AddChild(point, 10); // anchor (1,1) sprite1 = new CCSprite("grossini_dance_08.png"); sprite1.Position = (new CCPoint(s.Width / 2 + s.Width / 4, s.Height / 2)); sprite1.AnchorPoint = (new CCPoint(1, 1)); 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)); sprite4 = new CCSprite("grossini_dance_04.png"); sprite4.Position = (new CCPoint(0, 0)); sprite4.Scale = 0.5f; aParent.AddChild(sprite1); sprite1.AddChild(sprite2, -2); sprite1.AddChild(sprite3, -2); sprite1.AddChild(sprite4, 3); point = new CCSprite("Images/r1"); point.Scale = 0.25f; point.Position = sprite1.Position; AddChild(point, 10); }