public Box2DTestLayer() { TouchEnabled = true; AccelerometerEnabled = true; CCSize s = CCDirector.SharedDirector.WinSize; // init physics initPhysics(); // create reset button createResetButton(); //Set up sprite // Use batch node. Faster _batch = CCSpriteBatchNode.Create("Images/blocks", 100); m_pSpriteTexture = _batch.Texture; AddChild(_batch, 0, kTagParentNode); addNewSpriteAtPosition(new CCPoint(s.Width / 2, s.Height / 2)); CCLabelTTF label = new CCLabelTTF("Tap screen", "Marker Felt", 32); AddChild(label, 0); label.Color = new CCColor3B(0, 0, 255); label.Position = new CCPoint(s.Width / 2, s.Height - 50); ScheduleUpdate(); }
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 static CCSpriteBatchNode batchNodeWithFile(string fileImage) { CCSpriteBatchNode node = new CCSpriteBatchNode(); node.initWithFile(fileImage, 0x1d); return(node); }
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 static CCSpriteBatchNode batchNodeWithFile(string fileImage, int capacity) { CCSpriteBatchNode node = new CCSpriteBatchNode(); node.initWithFile(fileImage, capacity); return(node); }
public static CCSpriteBatchNode batchNodeWithTexture(CCTexture2D tex) { CCSpriteBatchNode node = new CCSpriteBatchNode(); node.initWithTexture(tex, 0x1d); return(node); }
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 static CCSpriteBatchNode Create(string fileImage) { var batchNode = new CCSpriteBatchNode(); batchNode.InitWithFile(fileImage, kDefaultSpriteBatchCapacity); return batchNode; }
public static CCSpriteBatchNode batchNodeWithTexture(CCTexture2D tex, int capacity) { CCSpriteBatchNode node = new CCSpriteBatchNode(); node.initWithTexture(tex, capacity); return(node); }
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; }
/// <summary> /// creates a CCSpriteBatchNode with a texture2d and a default capacity of 29 children. /// The capacity will be increased in 33% in runtime if it run out of space. /// </summary> public static CCSpriteBatchNode batchNodeWithTexture(Texture tex) { CCSpriteBatchNode batchNode = new CCSpriteBatchNode(); batchNode.initWithTexture(tex, defaultCapacity); return(batchNode); }
/// <summary> /// creates a CCSpriteBatchNode with a file image (.png, .jpeg, .pvr, etc) with a default capacity of 29 children. /// The capacity will be increased in 33% in runtime if it run out of space. /// The file will be loaded using the TextureMgr. /// </summary> public static CCSpriteBatchNode batchNodeWithFile(string fileImage) { CCSpriteBatchNode batchNode = new CCSpriteBatchNode(); batchNode.initWithFile(fileImage, defaultCapacity); return(batchNode); }
public SpriteBatchNodeReorderIssue767() { CCSize s = CCDirector.SharedDirector.WinSize; string scope = CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFramesWithFile("animations/ghosts.plist", "animations/ghosts"); CCNode aParent; CCSprite l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2; // // SpriteBatchNode: 3 levels of children // aParent = new CCSpriteBatchNode("animations/ghosts"); AddChild(aParent, 0, (int) kTagSprite.kTagSprite1); // parent l1 = new CCSprite(scope + "father.gif"); l1.Position = (new CCPoint(s.Width / 2, s.Height / 2)); aParent.AddChild(l1, 0, (int) kTagSprite.kTagSprite2); CCSize l1Size = l1.ContentSize; // child left l2a = new CCSprite(scope + "sister1.gif"); l2a.Position = (new CCPoint(-25 + l1Size.Width / 2, 0 + l1Size.Height / 2)); l1.AddChild(l2a, -1, (int) kTags.kTagSpriteLeft); CCSize l2aSize = l2a.ContentSize; // child right l2b = new CCSprite(scope + "sister2.gif"); l2b.Position = (new CCPoint(+25 + l1Size.Width / 2, 0 + l1Size.Height / 2)); l1.AddChild(l2b, 1, (int) kTags.kTagSpriteRight); CCSize l2bSize = l2a.ContentSize; // child left bottom l3a1 = new CCSprite(scope + "child1.gif"); l3a1.Scale = (0.65f); l3a1.Position = (new CCPoint(0 + l2aSize.Width / 2, -50 + l2aSize.Height / 2)); l2a.AddChild(l3a1, -1); // child left top l3a2 = new CCSprite(scope + "child1.gif"); l3a2.Scale = (0.65f); l3a2.Position = (new CCPoint(0 + l2aSize.Width / 2, +50 + l2aSize.Height / 2)); l2a.AddChild(l3a2, 1); // child right bottom l3b1 = new CCSprite(scope + "child1.gif"); l3b1.Scale = (0.65f); l3b1.Position = (new CCPoint(0 + l2bSize.Width / 2, -50 + l2bSize.Height / 2)); l2b.AddChild(l3b1, -1); // child right top l3b2 = new CCSprite(scope + "child1.gif"); l3b2.Scale = (0.65f); l3b2.Position = (new CCPoint(0 + l2bSize.Width / 2, +50 + l2bSize.Height / 2)); l2b.AddChild(l3b2, 1); Schedule(reorderSprites, 1); }
/// <summary> /// Initializes an sprite with an CCSpriteBatchNode and a rect in points /// </summary> public bool initWithBatchNode(CCSpriteBatchNode batchNode, CCRect rect) { if (initWithTexture(batchNode.Texture, rect)) { useBatchNode(batchNode); return(true); } return(false); }
public override void initWithQuantityOfNodes(int nNodes) { batchNode = new CCSpriteBatchNode("Images/spritesheet1"); AddChild(batchNode); base.initWithQuantityOfNodes(nNodes); ScheduleUpdate(); }
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 static CCSprite spriteWithBatchNode(CCSpriteBatchNode batchNode, CCRect rect) { CCSprite sprite = new CCSprite(); if (sprite.initWithBatchNode(batchNode, rect)) { return(sprite); } return(null); }
/// <summary> /// Initializes an sprite with an CCSpriteBatchNode and a rect in pixels /// @since v0.99.5 /// </summary> public bool initWithBatchNodeRectInPixels(CCSpriteBatchNode batchNode, CCRect rect) { if (initWithTexture(batchNode.Texture)) { setTextureRectInPixels(rect, false, rect.size); useBatchNode(batchNode); return(true); } return(false); }
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 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)(Random.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 (Random.NextDouble() < 0.2f) { x = (float)(Random.NextDouble() * s.Width); y = (float)(Random.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); }
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(); }
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); }
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 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); }
public void useSelfRender() { this.m_uAtlasIndex = ccMacros.CCSpriteIndexNotInitialized; this.m_bUseBatchNode = false; this.m_pobTextureAtlas = null; this.m_pobBatchNode = null; this.m_bDirty = this.m_bRecursiveDirty = false; float x = 0f + this.m_obOffsetPositionInPixels.x; float y = 0f + this.m_obOffsetPositionInPixels.y; float num3 = x + this.m_obRectInPixels.size.width; float num4 = y + this.m_obRectInPixels.size.height; this.m_sQuad.bl.vertices = ccTypes.vertex3(x, y, 0f); this.m_sQuad.br.vertices = ccTypes.vertex3(num3, y, 0f); this.m_sQuad.tl.vertices = ccTypes.vertex3(x, num4, 0f); this.m_sQuad.tr.vertices = ccTypes.vertex3(num3, num4, 0f); }
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); }
/// <summary> /// tell the sprite to use self-render. /// @since v0.99.0 /// </summary> public void useSelfRender() { m_uAtlasIndex = ccMacros.CCSpriteIndexNotInitialized; m_bUseBatchNode = false; m_pobTextureAtlas = null; m_pobBatchNode = null; m_bDirty = m_bRecursiveDirty = false; float x1 = 0 + m_obOffsetPositionInPixels.x; float y1 = 0 + m_obOffsetPositionInPixels.y; float x2 = x1 + m_obRectInPixels.size.width; float y2 = y1 + m_obRectInPixels.size.height; m_sQuad.bl.vertices = ccTypes.vertex3(x1, y1, 0); m_sQuad.br.vertices = ccTypes.vertex3(x2, y1, 0); m_sQuad.tl.vertices = ccTypes.vertex3(x1, y2, 0); m_sQuad.tr.vertices = ccTypes.vertex3(x2, y2, 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 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 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 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); } }
/// <summary> /// Initializes an sprite with an CCSpriteBatchNode and a rect in pixels /// @since v0.99.5 /// </summary> public bool initWithBatchNodeRectInPixels(CCSpriteBatchNode batchNode, CCRect rect) { if (initWithTexture(batchNode.Texture)) { setTextureRectInPixels(rect, false, rect.Size); useBatchNode(batchNode); return true; } return false; }
/// <summary> /// Creates an sprite with an CCBatchNode and a rect /// </summary> public static CCSprite spriteWithBatchNode(CCSpriteBatchNode batchNode, CCRect rect) { CCSprite pobSprite = new CCSprite(); if (pobSprite.initWithBatchNode(batchNode, rect)) { return pobSprite; } return null; }
/// <summary> /// Initializes an sprite with an CCSpriteBatchNode and a rect in points /// </summary> public bool initWithBatchNode(CCSpriteBatchNode batchNode, CCRect rect) { if (initWithTexture(batchNode.Texture, rect)) { useBatchNode(batchNode); return true; } return false; }
/// <summary> /// tell the sprite to use batch node render. /// @since v0.99.0 /// </summary> public void useBatchNode(CCSpriteBatchNode batchNode) { m_bUseBatchNode = true; m_pobTextureAtlas = batchNode.TextureAtlas; // weak ref m_pobBatchNode = batchNode; }
/// <summary> /// tell the sprite to use self-render. /// @since v0.99.0 /// </summary> public void useSelfRender() { m_uAtlasIndex = ccMacros.CCSpriteIndexNotInitialized; m_bUseBatchNode = false; m_pobTextureAtlas = null; m_pobBatchNode = null; m_bDirty = m_bRecursiveDirty = false; float x1 = 0 + m_obOffsetPositionInPixels.X; float y1 = 0 + m_obOffsetPositionInPixels.Y; float x2 = x1 + m_obRectInPixels.Size.Width; float y2 = y1 + m_obRectInPixels.Size.Height; m_sQuad.bl.vertices = ccTypes.vertex3(x1, y1, 0); m_sQuad.br.vertices = ccTypes.vertex3(x2, y1, 0); m_sQuad.tl.vertices = ccTypes.vertex3(x1, y2, 0); m_sQuad.tr.vertices = ccTypes.vertex3(x2, y2, 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); }
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; }
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; }
public void useBatchNode(CCSpriteBatchNode batchNode) { this.m_bUseBatchNode = true; this.m_pobTextureAtlas = batchNode.TextureAtlas; this.m_pobBatchNode = batchNode; }