public SpriteBatchNodeAliased() { CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 10); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSize s = CCDirector.sharedDirector().getWinSize(); CCSprite sprite1 = CCSprite.spriteWithTexture(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 = CCSprite.spriteWithTexture(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 = CCScaleBy.actionWithDuration(2, 5); CCActionInterval scale_back = (CCActionInterval)scale.reverse(); CCActionInterval seq = (CCActionInterval)(CCSequence.actions(scale, scale_back)); CCAction repeat = CCRepeatForever.actionWithAction(seq); CCAction repeat2 = (CCAction)(repeat.copy()); sprite1.runAction(repeat); sprite2.runAction(repeat2); }
public SpriteBatchNodeReorderIssue767() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/ghosts", "animations/images/ghosts"); CCNode aParent; CCSprite l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2; // // SpriteBatchNode: 3 levels of children // aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/ghosts"); addChild(aParent, 0, (int)kTagSprite.kTagSprite1); // parent l1 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 SpriteBatchNodeReorder() { List <Object> a = new List <Object>(10); CCSpriteBatchNode asmtest = CCSpriteBatchNode.batchNodeWithFile("animations/images/ghosts"); for (int i = 0; i < 10; i++) { CCSprite s1 = CCSprite.spriteWithBatchNode(asmtest, 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; List <CCNode> 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; List <CCSprite> 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; } //a.release(); //memory leak : 2010-0415 }
public SpriteChildrenVisibility() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini"); CCNode aParent; CCSprite sprite1, sprite2, sprite3; // // SpriteBatchNode // // parents aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50); aParent.position = (new CCPoint(s.width / 3, s.height / 2)); addChild(aParent, 0); sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite1.position = (new CCPoint(0, 0)); sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite2.position = (new CCPoint(20, 30)); sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite3.position = (new CCPoint(-20, 30)); aParent.addChild(sprite1); sprite1.addChild(sprite2, -2); sprite1.addChild(sprite3, 2); sprite1.runAction(CCBlink.actionWithDuration(5, 10)); // // Sprite // aParent = CCNode.node(); aParent.position = (new CCPoint(2 * s.width / 3, s.height / 2)); addChild(aParent, 0); sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite1.position = (new CCPoint(0, 0)); sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite2.position = (new CCPoint(20, 30)); sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite3.position = (new CCPoint(-20, 30)); aParent.addChild(sprite1); sprite1.addChild(sprite2, -2); sprite1.addChild(sprite3, 2); sprite1.runAction(CCBlink.actionWithDuration(5, 10)); }
public SpriteHybrid() { CCSize s = CCDirector.sharedDirector().getWinSize(); // parents CCNode parent1 = CCNode.node(); CCSpriteBatchNode parent2 = CCSpriteBatchNode.batchNodeWithFile("animations/images/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"); // create 250 sprites // only show 80% of them for (int i = 0; i < 250; i++) { int spriteIdx = (int)(rand.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 = CCSprite.spriteWithSpriteFrame(frame); parent1.addChild(sprite, i, i); float x = -1000; float y = -1000; if (rand.NextDouble() < 0.2f) { x = (float)(rand.NextDouble() * s.width); y = (float)(rand.NextDouble() * s.height); } sprite.position = (new CCPoint(x, y)); CCActionInterval action = CCRotateBy.actionWithDuration(4, 360); sprite.runAction(CCRepeatForever.actionWithAction(action)); } m_usingSpriteBatchNode = false; schedule(reparentSprite, 2); }
public SpriteBatchNode1() { isTouchEnabled = true; CCSpriteBatchNode BatchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 50); addChild(BatchNode, 0, (int)kTags.kTagSpriteBatchNode); CCSize s = CCDirector.sharedDirector().getWinSize(); addNewSpriteWithCoords(new CCPoint(s.width / 2, s.height / 2)); }
public override void initWithQuantityOfNodes(int nNodes) { batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/spritesheet1"); addChild(batchNode); NodeChildrenMainScene nodeChildrenMainScene = new NodeChildrenMainScene(); nodeChildrenMainScene.initWithQuantityOfNodes(nNodes); //#if CC_ENABLE_PROFILERS // _profilingTimer = CCProfiler::timerWithName(profilerName().c_str(), this); //#endif CCNode ccnode = new CCNode(); ccnode.scheduleUpdate(); }
public SpriteBatchNodeReorderIssue744() { CCSize s = CCDirector.sharedDirector().getWinSize(); // Testing issue #744 // http://code.google.com/p/cocos2d-iphone/issues/detail?id=744 CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 15); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSprite sprite = CCSprite.spriteWithBatchNode(batch, 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 SpriteBatchNodeReorderIssue766() { batchNode = CCSpriteBatchNode.batchNodeWithFile("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 SpriteBatchNodeNewTexture() { isTouchEnabled = true; CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("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 SpriteBatchNodeAnchorPoint() { // small capacity. Testing resizing. // Don't use capacity=1 in your real game. It is expensive to resize the capacity CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSize s = CCDirector.sharedDirector().getWinSize(); CCActionInterval rotate = CCRotateBy.actionWithDuration(10, 360); CCAction action = CCRepeatForever.actionWithAction(rotate); for (int i = 0; i < 3; i++) { CCSprite sprite = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * i, 121 * 1, 85, 121)); sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2)); CCSprite point = CCSprite.spriteWithFile("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 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().getWinSize(); 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 = CCSpriteBatchNode.batchNodeWithFile("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 = CCSprite.spriteWithTexture(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 = CCSprite.spriteWithTexture(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(CCOrbitCamera.actionWithDuration(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 = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1); addChild(batch, 0, kTagSpriteBatchNode); batch.isRelativeAnchorPoint = false; CCSize s = CCDirector.sharedDirector().getWinSize(); batch.anchorPoint = new CCPoint(0.5f, 0.5f); batch.contentSize = (new CCSize(s.width, s.height)); // SpriteBatchNode actions CCActionInterval rotate = CCRotateBy.actionWithDuration(5, 360); CCAction action = CCRepeatForever.actionWithAction(rotate); // SpriteBatchNode actions CCActionInterval rotate_back = (CCActionInterval)rotate.reverse(); CCActionInterval rotate_seq = (CCActionInterval)(CCSequence.actions(rotate, rotate_back)); CCAction rotate_forever = CCRepeatForever.actionWithAction(rotate_seq); CCActionInterval scale = CCScaleBy.actionWithDuration(5, 1.5f); CCActionInterval scale_back = (CCActionInterval)scale.reverse(); CCActionInterval scale_seq = (CCActionInterval)(CCSequence.actions(scale, scale_back)); CCAction scale_forever = CCRepeatForever.actionWithAction(scale_seq); float step = s.width / 4; for (int i = 0; i < 3; i++) { CCSprite sprite = CCSprite.spriteWithTexture(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 SpriteSubclass() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/ghosts"); CCSpriteBatchNode aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/ghosts"); // MySprite1 MySprite1 sprite = MySprite1.spriteWithSpriteFrameName("father.gif"); sprite.position = (new CCPoint(s.width / 4 * 1, s.height / 2)); aParent.addChild(sprite); addChild(aParent); // MySprite2 MySprite2 sprite2 = MySprite2.spriteWithFile("Images/grossini"); addChild(sprite2); sprite2.position = (new CCPoint(s.width / 4 * 3, s.height / 2)); }
public SpriteBatchNodeFlip() { CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 10); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSize s = CCDirector.sharedDirector().getWinSize(); CCSprite sprite1 = CCSprite.spriteWithTexture(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 = CCSprite.spriteWithTexture(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 Uncle_sprite() { //uncledata = data; // 创建走的动画 List <CCSpriteFrame> _runFream = new List <CCSpriteFrame>(); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile(@"plist/zhengyu"); CCSpriteBatchNode sheet = CCSpriteBatchNode.batchNodeWithFile(@"plist/Images/zhengyu"); this.addChild(sheet); for (int i = 1; i <= 4; i++) { _runFream.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(String.Format("MM0{0}.png", i))); } _run = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_runFream, 0.12f)); List <CCSpriteFrame> _actackFream = new List <CCSpriteFrame>(); // 创建攻击时候动作 for (int i = 1; i <= 5; i++) { _actackFream.Add(CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(String.Format("Mthrow0{0}.png", i))); } _actack = CCAnimate.actionWithAnimation(CCAnimation.animationWithFrames(_actackFream, 0.3f)); position = new CCPoint(100, 100); // 初始化开始帧 base.initWithSpriteFrame(_runFream[0]); // 如果手机倾斜 if (Accelerometer.IsSupported) { gSensor = new Accelerometer(); gSensor.CurrentValueChanged += new EventHandler <SensorReadingEventArgs <AccelerometerReading> >(gSensor_CurrentValueChanged); gSensor.Start(); } }
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 = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSize s = CCDirector.sharedDirector().getWinSize(); float step = s.width / 11; for (int i = 0; i < 5; i++) { CCSprite sprite = CCSprite.spriteWithTexture(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 = CCSprite.spriteWithTexture(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 = CCSprite.spriteWithTexture(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 SpriteBatchNodeChildrenAnchorPoint() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini"); CCNode aParent; CCSprite sprite1, sprite2, sprite3, sprite4, point; // // SpriteBatchNode // // parents aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50); addChild(aParent, 0); // anchor (0,0) sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png"); sprite1.position = (new CCPoint(s.width / 4, s.height / 2)); sprite1.anchorPoint = (new CCPoint(0, 0)); sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite2.position = (new CCPoint(20, 30)); sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite3.position = (new CCPoint(-20, 30)); sprite4 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithFile("Images/r1"); point.scale = 0.25f; point.position = sprite1.position; addChild(point, 10); // anchor (0.5, 0.5) sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png"); sprite1.position = (new CCPoint(s.width / 2, s.height / 2)); sprite1.anchorPoint = (new CCPoint(0.5f, 0.5f)); sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite2.position = (new CCPoint(20, 30)); sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite3.position = (new CCPoint(-20, 30)); sprite4 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithFile("Images/r1"); point.scale = 0.25f; point.position = sprite1.position; addChild(point, 10); // anchor (1,1) sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_08.png"); sprite1.position = (new CCPoint(s.width / 2 + s.width / 4, s.height / 2)); sprite1.anchorPoint = (new CCPoint(1, 1)); sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite2.position = (new CCPoint(20, 30)); sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite3.position = (new CCPoint(-20, 30)); sprite4 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithFile("Images/r1"); point.scale = 0.25f; point.position = sprite1.position; addChild(point, 10); }
public SpriteBatchNodeOffsetAnchorFlip() { CCSize s = CCDirector.sharedDirector().getWinSize(); for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache(); cache.addSpriteFramesWithFile("animations/grossini"); cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray"); // // Animation using Sprite batch // CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2)); CCSprite point = CCSprite.spriteWithFile("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 = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini"); addChild(spritebatch); List <CCSpriteFrame> 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 = CCAnimation.animationWithFrames(animFrames); sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(2.8f, animation, false))); animFrames = null; CCFlipY flip = CCFlipY.actionWithFlipY(true); CCFlipY flip_back = CCFlipY.actionWithFlipY(false); CCDelayTime delay = CCDelayTime.actionWithDuration(1); CCFiniteTimeAction seq = CCSequence.actions((CCFiniteTimeAction)delay, (CCFiniteTimeAction)flip, (CCFiniteTimeAction)delay.copyWithZone(null), (CCFiniteTimeAction)flip_back); sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq)); spritebatch.addChild(sprite, i); } }
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.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888); batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossinis_sister1", 100); p.addChild(batchNode, 0); break; case 3: CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444); batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossinis_sister1", 100); p.addChild(batchNode, 0); break; /// case 5: CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888); batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 100); p.addChild(batchNode, 0); break; case 6: CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444); batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 100); p.addChild(batchNode, 0); break; /// case 8: CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA8888); batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/spritesheet1", 100); p.addChild(batchNode, 0); break; case 9: CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_RGBA4444); batchNode = CCSpriteBatchNode.batchNodeWithFile("Images/spritesheet1", 100); p.addChild(batchNode, 0); break; default: break; } //if (batchNode != null) //{ // batchNode.retain(); //} CCTexture2D.setDefaultAlphaPixelFormat(CCTexture2DPixelFormat.kCCTexture2DPixelFormat_Default); }
public RenderTextureZbuffer() { //this->setIsTouchEnabled(true); isTouchEnabled = true; CCSize size = CCDirector.sharedDirector().getWinSize(); CCLabelTTF label = CCLabelTTF.labelWithString("vertexZ = 50", "Marker Felt", 64); label.position = new CCPoint(size.width / 2, size.height * 0.25f); this.addChild(label); CCLabelTTF label2 = CCLabelTTF.labelWithString("vertexZ = 0", "Marker Felt", 64); label2.position = new CCPoint(size.width / 2, size.height * 0.5f); this.addChild(label2); CCLabelTTF label3 = CCLabelTTF.labelWithString("vertexZ = -50", "Marker Felt", 64); label3.position = new CCPoint(size.width / 2, size.height * 0.75f); this.addChild(label3); label.vertexZ = 50; label2.vertexZ = 0; label3.vertexZ = -50; #warning "CCSpriteFrameCache is not exist! " //CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("Images/bugs/circle.plist"); mgr = CCSpriteBatchNode.batchNodeWithFile("Images/bugs/circle.png", 9); this.addChild(mgr); sp1 = CCSprite.spriteWithSpriteFrameName("circle.png"); sp2 = CCSprite.spriteWithSpriteFrameName("circle.png"); sp3 = CCSprite.spriteWithSpriteFrameName("circle.png"); sp4 = CCSprite.spriteWithSpriteFrameName("circle.png"); sp5 = CCSprite.spriteWithSpriteFrameName("circle.png"); sp6 = CCSprite.spriteWithSpriteFrameName("circle.png"); sp7 = CCSprite.spriteWithSpriteFrameName("circle.png"); sp8 = CCSprite.spriteWithSpriteFrameName("circle.png"); sp9 = CCSprite.spriteWithSpriteFrameName("circle.png"); 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 = new ccColor3B { r = 255, g = 255, b = 0 }; }
public SpriteBatchNodeChildren() { CCSize s = CCDirector.sharedDirector().getWinSize(); // parents CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini"); CCSprite sprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite1.position = (new CCPoint(s.width / 3, s.height / 2)); CCSprite sprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite2.position = (new CCPoint(50, 50)); CCSprite sprite3 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite3.position = (new CCPoint(-50, -50)); batch.addChild(sprite1); sprite1.addChild(sprite2); sprite1.addChild(sprite3); // BEGIN NEW CODE List <CCSpriteFrame> 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 = CCAnimation.animationWithFrames(animFrames, 0.2f); sprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false))); // END NEW CODE CCActionInterval action = CCMoveBy.actionWithDuration(2, new CCPoint(200, 0)); CCActionInterval action_back = (CCActionInterval)action.reverse(); CCActionInterval action_rot = CCRotateBy.actionWithDuration(2, 360); CCActionInterval action_s = CCScaleBy.actionWithDuration(2, 2); CCActionInterval action_s_back = (CCActionInterval)action_s.reverse(); CCActionInterval seq2 = (CCActionInterval)action_rot.reverse(); sprite2.runAction(CCRepeatForever.actionWithAction(seq2)); sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction(action_rot))); sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back))))); sprite1.runAction((CCAction)(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action_s, action_s_back))))); }
public override void onEnter() { base.onEnter(); CCSize s = CCDirector.sharedDirector().getWinSize(); // 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", "animations/images/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 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite.position = (new CCPoint(s.width * 0.5f, s.height * 0.5f)); CCSpriteBatchNode spriteBatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini-aliases"); spriteBatch.addChild(sprite); addChild(spriteBatch); List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { string temp = ""; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } // Obtain frames by alias name str = string.Format("dance_{0}", temp); CCSpriteFrame frame = cache.spriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames); // 14 frames * 1sec = 14 seconds sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(14.0f, animation, false))); }
public SpriteBatchNodeChildrenScale() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_family"); CCNode aParent; CCSprite sprite1, sprite2; CCActionInterval rot = CCRotateBy.actionWithDuration(10, 360); CCAction seq = CCRepeatForever.actionWithAction(rot); // // Children + Scale using Sprite // Test 1 // aParent = CCNode.node(); sprite1 = CCSprite.spriteWithSpriteFrameName("grossinis_sister1"); sprite1.position = new CCPoint(s.width / 4, s.height / 4); sprite1.scaleX = -0.5f; sprite1.scaleY = 2.0f; sprite1.runAction(seq); sprite2 = CCSprite.spriteWithSpriteFrameName("grossinis_sister2"); sprite2.position = (new CCPoint(50, 0)); addChild(aParent); aParent.addChild(sprite1); sprite1.addChild(sprite2); // // Children + Scale using SpriteBatchNode // Test 2 // aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini_family"); sprite1 = CCSprite.spriteWithSpriteFrameName("grossinis_sister1"); 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 = CCSprite.spriteWithSpriteFrameName("grossinis_sister2"); sprite2.position = (new CCPoint(50, 0)); addChild(aParent); aParent.addChild(sprite1); sprite1.addChild(sprite2); // // Children + Scale using Sprite // Test 3 // aParent = CCNode.node(); sprite1 = CCSprite.spriteWithSpriteFrameName("grossinis_sister1"); 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 = CCSprite.spriteWithSpriteFrameName("grossinis_sister2"); sprite2.position = (new CCPoint(50, 0)); addChild(aParent); aParent.addChild(sprite1); sprite1.addChild(sprite2); // // Children + Scale using Sprite // Test 4 // aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini_family"); sprite1 = CCSprite.spriteWithSpriteFrameName("grossinis_sister1"); 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 = CCSprite.spriteWithSpriteFrameName("grossinis_sister2"); sprite2.position = (new CCPoint(50, 0)); addChild(aParent); aParent.addChild(sprite1); sprite1.addChild(sprite2); }
public SpriteBatchNodeOffsetAnchorRotation() { CCSize s = CCDirector.sharedDirector().getWinSize(); for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache(); cache.addSpriteFramesWithFile("animations/grossini"); cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray"); // // Animation using Sprite BatchNode // CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite.position = (new CCPoint(s.width / 4 * (i + 1), s.height / 2)); CCSprite point = CCSprite.spriteWithFile("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 = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini"); addChild(spritebatch); List <CCSpriteFrame> 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 + ""; } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache.spriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames); sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false))); sprite.runAction(CCRepeatForever.actionWithAction(CCRotateBy.actionWithDuration(10, 360))); spritebatch.addChild(sprite, i); //animFrames.release(); // win32 : memory leak 2010-0415 } }
public SpriteBatchNodeOffsetAnchorSkewScale() { CCSize s = CCDirector.sharedDirector().getWinSize(); for (int i = 0; i < 3; i++) { CCSpriteFrameCache cache = CCSpriteFrameCache.sharedSpriteFrameCache(); cache.addSpriteFramesWithFile("animations/grossini"); cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray"); // // Animation using Sprite batch // CCSprite sprite = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite.position = new CCPoint(s.width / 4 * (i + 1), s.height / 2); CCSprite point = CCSprite.spriteWithFile("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 = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini"); addChild(spritebatch); List <CCSpriteFrame> 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 = CCAnimation.animationWithFrames(animFrames); sprite.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithDuration(2.8f, animation, false))); animFrames = null; // skew CCSkewBy skewX = CCSkewBy.actionWithDuration(2, 45, 0); CCActionInterval skewX_back = (CCActionInterval)skewX.reverse(); CCSkewBy skewY = CCSkewBy.actionWithDuration(2, 0, 45); CCActionInterval skewY_back = (CCActionInterval)skewY.reverse(); CCFiniteTimeAction seq_skew = CCSequence.actions(skewX, skewX_back, skewY, skewY_back); sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_skew)); // scale CCScaleBy scale = CCScaleBy.actionWithDuration(2, 2); CCActionInterval scale_back = (CCActionInterval)scale.reverse(); CCFiniteTimeAction seq_scale = CCSequence.actions(scale, scale_back); sprite.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq_scale)); spritebatch.addChild(sprite, i); } }
public SpriteBatchNodeChildrenChildren() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/ghosts"); CCSpriteBatchNode aParent; CCSprite l1, l2a, l2b, l3a1, l3a2, l3b1, l3b2; CCActionInterval rot = CCRotateBy.actionWithDuration(10, 360); CCAction seq = CCRepeatForever.actionWithAction(rot); CCActionInterval rot_back = (CCActionInterval)rot.reverse(); CCAction rot_back_fe = CCRepeatForever.actionWithAction(rot_back); // // SpriteBatchNode: 3 levels of children // aParent = CCSpriteBatchNode.batchNodeWithFile("animations/images/ghosts"); aParent.Texture.generateMipmap(); addChild(aParent); // parent l1 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("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 = CCSprite.spriteWithSpriteFrameName("child1.gif"); l3b1.scale = 0.45f; l3b1.IsFlipY = true; l3b1.position = new CCPoint(0 + l2bSize.width / 2, -100 + l2bSize.height / 2); l2b.addChild(l3b1); // child right top l3b2 = CCSprite.spriteWithSpriteFrameName("child1.gif"); l3b2.scale = 0.45f; l3b2.IsFlipY = true; l3b1.position = new CCPoint(0 + l2bSize.width / 2, +100 + l2bSize.height / 2); l2b.addChild(l3b2); }
public SpriteBatchNodeColorOpacity() { // small capacity. Testing resizing. // Don't use capacity=1 in your real game. It is expensive to resize the capacity CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("Images/grossini_dance_atlas", 1); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSprite sprite1 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121)); CCSprite sprite2 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121)); CCSprite sprite3 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 2, 121 * 1, 85, 121)); CCSprite sprite4 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 3, 121 * 1, 85, 121)); CCSprite sprite5 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121)); CCSprite sprite6 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121)); CCSprite sprite7 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 2, 121 * 1, 85, 121)); CCSprite sprite8 = CCSprite.spriteWithTexture(batch.Texture, new CCRect(85 * 3, 121 * 1, 85, 121)); CCSize s = CCDirector.sharedDirector().getWinSize(); 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 = CCFadeIn.actionWithDuration(2); CCActionInterval action_back = (CCActionInterval)action.reverse(); CCAction fade = CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back))); CCActionInterval tintred = CCTintBy.actionWithDuration(2, 0, -255, -255); CCActionInterval tintred_back = (CCActionInterval)tintred.reverse(); CCAction red = CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(tintred, tintred_back))); CCActionInterval tintgreen = CCTintBy.actionWithDuration(2, -255, 0, -255); CCActionInterval tintgreen_back = (CCActionInterval)tintgreen.reverse(); CCAction green = CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(tintgreen, tintgreen_back))); CCActionInterval tintblue = CCTintBy.actionWithDuration(2, -255, -255, 0); CCActionInterval tintblue_back = (CCActionInterval)tintblue.reverse(); CCAction blue = CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(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 SpriteFrameTest() { CCSize s = CCDirector.sharedDirector().getWinSize(); // 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"); cache.addSpriteFramesWithFile("animations/grossini_gray", "animations/images/grossini_gray"); cache.addSpriteFramesWithFile("animations/grossini_blue", "animations/images/grossini_blue"); // // Animation using Sprite BatchNode // m_pSprite1 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); m_pSprite1.position = (new CCPoint(s.width / 2 - 80, s.height / 2)); CCSpriteBatchNode spritebatch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini"); spritebatch.addChild(m_pSprite1); addChild(spritebatch); List <CCSpriteFrame> animFrames = new List <CCSpriteFrame>(15); 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 = cache.spriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames); m_pSprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false))); // to test issue #732, uncomment the following line m_pSprite1.IsFlipX = false; m_pSprite1.IsFlipY = false; // // Animation using standard Sprite // m_pSprite2 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); m_pSprite2.position = (new CCPoint(s.width / 2 + 80, s.height / 2)); addChild(m_pSprite2); List <CCSpriteFrame> moreFrames = new List <CCSpriteFrame>(20); for (int i = 1; i < 15; i++) { string temp; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } str = string.Format("grossini_dance_gray_{0}.png", temp); CCSpriteFrame frame = cache.spriteFrameByName(str); moreFrames.Add(frame); } for (int i = 1; i < 5; i++) { str = string.Format("grossini_blue_0{0}.png", i); CCSpriteFrame frame = cache.spriteFrameByName(str); moreFrames.Add(frame); } // append frames from another batch moreFrames.AddRange(animFrames); CCAnimation animMixed = CCAnimation.animationWithFrames(moreFrames); m_pSprite2.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animMixed, false))); // to test issue #732, uncomment the following line m_pSprite2.IsFlipX = (false); m_pSprite2.IsFlipY = (false); schedule(startIn05Secs, 0.5f); m_nCounter = 0; }
public SpriteBatchNodeChildren2() { CCSize s = CCDirector.sharedDirector().getWinSize(); // parents CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("animations/images/grossini", 50); batch.Texture.generateMipmap(); addChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini"); CCSprite sprite11 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite11.position = (new CCPoint(s.width / 3, s.height / 2)); CCSprite sprite12 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite12.position = (new CCPoint(20, 30)); sprite12.scale = 0.2f; CCSprite sprite13 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite13.position = (new CCPoint(-20, 30)); sprite13.scale = 0.2f; batch.addChild(sprite11); sprite11.addChild(sprite12, -2); sprite11.addChild(sprite13, 2); // don't rotate with it's parent sprite12.honorParentTransform = ((ccHonorParentTransform)(sprite12.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE)); // don't scale and rotate with it's parent sprite13.honorParentTransform = ((ccHonorParentTransform)(sprite13.honorParentTransform & (ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE | ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_ROTATE))); CCActionInterval action = CCMoveBy.actionWithDuration(2, new CCPoint(200, 0)); CCActionInterval action_back = (CCActionInterval)action.reverse(); CCActionInterval action_rot = CCRotateBy.actionWithDuration(2, 360); CCActionInterval action_s = CCScaleBy.actionWithDuration(2, 2); CCActionInterval action_s_back = (CCActionInterval)action_s.reverse(); sprite11.runAction(CCRepeatForever.actionWithAction(action_rot)); sprite11.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action, action_back)))); sprite11.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(action_s, action_s_back)))); // // another set of parent / children // CCSprite sprite21 = CCSprite.spriteWithSpriteFrameName("grossini_dance_01.png"); sprite21.position = (new CCPoint(2 * s.width / 3, s.height / 2 - 50)); CCSprite sprite22 = CCSprite.spriteWithSpriteFrameName("grossini_dance_02.png"); sprite22.position = (new CCPoint(20, 30)); sprite22.scale = 0.8f; CCSprite sprite23 = CCSprite.spriteWithSpriteFrameName("grossini_dance_03.png"); sprite23.position = (new CCPoint(-20, 30)); sprite23.scale = 0.8f; batch.addChild(sprite21); sprite21.addChild(sprite22, -2); sprite21.addChild(sprite23, 2); // don't rotate with it's parent sprite22.honorParentTransform = ((ccHonorParentTransform)(sprite22.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_TRANSLATE)); // don't scale and rotate with it's parent sprite23.honorParentTransform = ((ccHonorParentTransform)(sprite23.honorParentTransform & ccHonorParentTransform.CC_HONOR_PARENT_TRANSFORM_SCALE)); sprite21.runAction(CCRepeatForever.actionWithAction(CCRotateBy.actionWithDuration(1, 360))); sprite21.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(CCScaleTo.actionWithDuration(0.5f, 5.0f), CCScaleTo.actionWithDuration(0.5f, 1))))); }