public SpriteBatchNodeChildren() { CCSize s = CCDirector.SharedDirector.WinSize; // parents CCSpriteBatchNode batch = CCSpriteBatchNode.Create("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 = CCAnimation.Create(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 SpriteOffsetAnchorRotation() { CCSize s = CCDirector.SharedDirector.WinSize; CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFramesWithFile("animations/grossini.plist"); cache.AddSpriteFramesWithFile("animations/grossini_gray.plist", "animations/grossini_gray"); for (int i = 0; i < 3; i++) { // // 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, 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; var animFrames = new List<CCSpriteFrame>(14); string str = ""; for (int j = 0; j < 14; j++) { str = string.Format("grossini_dance_{0:00}.png", j + 1); CCSpriteFrame frame = cache.SpriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.Create(animFrames, 0.3f); sprite.RunAction(new CCRepeatForever (new CCAnimate (animation))); sprite.RunAction(new CCRepeatForever (new CCRotateBy (10, 360))); AddChild(sprite, 0); //animFrames.release(); // win32 : memory leak 2010-0415 } }
public Test6() { CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1); CCSprite sp11 = new CCSprite(TestResource.s_pPathSister1); CCSprite sp2 = new CCSprite(TestResource.s_pPathSister2); CCSprite sp21 = new CCSprite(TestResource.s_pPathSister2); sp1.Position = (new CCPoint(100, 160)); sp2.Position = (new CCPoint(380, 160)); CCActionInterval rot = new CCRotateBy (2, 360); var rot_back = rot.Reverse() as CCActionInterval; CCAction forever1 = new CCRepeatForever ((CCActionInterval)CCSequence.FromActions(rot, rot_back)); var forever11 = (CCAction) (forever1.Copy()); var forever2 = (CCAction) (forever1.Copy()); var forever21 = (CCAction) (forever1.Copy()); AddChild(sp1, 0, CocosNodeTestStaticLibrary.kTagSprite1); sp1.AddChild(sp11); AddChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2); sp2.AddChild(sp21); sp1.RunAction(forever1); sp11.RunAction(forever11); sp2.RunAction(forever2); sp21.RunAction(forever21); Schedule(addAndRemove, 2.0f); }
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 void addNewSpriteWithCoords(CCPoint p) { int idx = (int)(CCMacros.CCRandomBetween0And1() * 1400.0f / 100.0f); int x = (idx % 5) * 85; int y = (idx / 5) * 121; CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(x, y, 85, 121)); AddChild(sprite); sprite.Position = p; CCActionInterval action; float random = CCMacros.CCRandomBetween0And1(); if (random < 0.20) action = new CCScaleBy(3, 2); else if (random < 0.40) action = new CCRotateBy (3, 360); else if (random < 0.60) action = new CCBlink (1, 3); else if (random < 0.8) action = new CCTintBy (2, 0, -255, -255); else action = new CCFadeOut (2); object obj = action.Reverse(); CCActionInterval action_back = (CCActionInterval)action.Reverse(); CCActionInterval seq = (CCActionInterval)(CCSequence.FromActions(action, action_back)); sprite.RunAction(new CCRepeatForever (seq)); }
private void performanceActions(CCSprite pSprite) { CCSize size = CCDirector.SharedDirector.WinSize; pSprite.Position = new CCPoint((Random.Next() % (int) size.Width), (Random.Next() % (int) size.Height)); float period = 0.5f + (Random.Next() % 1000) / 500.0f; CCRotateBy rot = new CCRotateBy (period, 360.0f * Random.Float_0_1()); var rot_back = rot.Reverse(); CCAction permanentRotation = new CCRepeatForever (CCSequence.FromActions(rot, rot_back)); pSprite.RunAction(permanentRotation); float growDuration = 0.5f + (Random.Next() % 1000) / 500.0f; CCActionInterval grow = new CCScaleBy(growDuration, 0.5f, 0.5f); CCAction permanentScaleLoop = new CCRepeatForever (new CCSequence (grow, grow.Reverse())); pSprite.RunAction(permanentScaleLoop); }
public override bool Init() { InitWithColor(new CCColor4B(0, 0, 255, 255)); CCMenuItemFont item1 = CCMenuItemFont.Create("(3) Touch to pushScene (self)", item0Clicked); CCMenuItemFont item2 = CCMenuItemFont.Create("(3) Touch to popScene", item1Clicked); CCMenuItemFont item3 = CCMenuItemFont.Create("(3) Touch to popToRootScene", item2Clicked); CCMenu menu = new CCMenu(item1, item2, item3); menu.AlignItemsVertically(); AddChild(menu); CCSize s = CCDirector.SharedDirector.WinSize; CCSprite sprite = new CCSprite(s_pPathGrossini); AddChild(sprite); sprite.Position = new CCPoint(s.Width /2, 40); CCActionInterval rotate = new CCRotateBy (2, 360); CCAction repeat = new CCRepeatForever (rotate); sprite.RunAction(repeat); Schedule(testDealloc); return true; }
public void addNewSprite() { CCSize s = CCDirector.SharedDirector.WinSize; CCPoint p = new CCPoint((float)(Random.NextDouble() * s.Width), (float)(Random.NextDouble() * s.Height)); CCSpriteBatchNode batch = (CCSpriteBatchNode)GetChildByTag((int)kTags.kTagSpriteBatchNode); int idx = (int)(Random.NextDouble() * 1400 / 100); int x = (idx % 5) * 85; int y = (idx / 5) * 121; CCSprite sprite = new CCSprite(batch.Texture, new CCRect(x, y, 85, 121)); batch.AddChild(sprite); sprite.Position = (new CCPoint(p.X, p.Y)); CCActionInterval action; float random = (float)Random.NextDouble(); if (random < 0.20) action = new CCScaleBy(3, 2); else if (random < 0.40) action = new CCRotateBy (3, 360); else if (random < 0.60) action = new CCBlink (1, 3); else if (random < 0.8) action = new CCTintBy (2, 0, -255, -255); else action = new CCFadeOut (2); CCActionInterval action_back = (CCActionInterval)action.Reverse(); CCActionInterval seq = (CCActionInterval)(CCSequence.FromActions(action, action_back)); sprite.RunAction(new CCRepeatForever (seq)); }
public StressTest2() { CCSize s = CCDirector.SharedDirector.WinSize; CCLayer sublayer = new CCLayer(); CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1); sp1.Position = (new CCPoint(80, s.Height / 2)); CCActionInterval move = new CCMoveBy (3, new CCPoint(350, 0)); CCActionInterval move_ease_inout3 = new CCEaseInOut((CCActionInterval) (move.Copy()), 2.0f); var move_ease_inout_back3 = (CCActionInterval) move_ease_inout3.Reverse(); CCFiniteTimeAction seq3 = CCSequence.FromActions(move_ease_inout3, move_ease_inout_back3); sp1.RunAction(new CCRepeatForever ((CCActionInterval) seq3)); sublayer.AddChild(sp1, 1); CCParticleFire fire = CCParticleFire.Create(); fire.Texture = (CCTextureCache.SharedTextureCache.AddImage("Images/fire")); fire.Position = (new CCPoint(80, s.Height / 2 - 50)); var copy_seq3 = (CCActionInterval) (seq3.Copy()); fire.RunAction(new CCRepeatForever (copy_seq3)); sublayer.AddChild(fire, 2); Schedule((shouldNotLeak), 6.0f); AddChild(sublayer, 0, CocosNodeTestStaticLibrary.kTagSprite1); }
public NodeToWorld() { // // This code tests that nodeToParent works OK: // - It tests different anchor Points // - It tests different children anchor points CCSprite back = new CCSprite(TestResource.s_back3); AddChild(back, -10); back.AnchorPoint = (new CCPoint(0, 0)); CCSize backSize = back.ContentSize; CCMenuItem item = new CCMenuItemImage(TestResource.s_PlayNormal, TestResource.s_PlaySelect); CCMenu menu = new CCMenu(item); menu.AlignItemsVertically(); menu.Position = (new CCPoint(backSize.Width / 2, backSize.Height / 2)); back.AddChild(menu); CCActionInterval rot = new CCRotateBy (5, 360); CCAction fe = new CCRepeatForever (rot); item.RunAction(fe); CCActionInterval move = new CCMoveBy (3, new CCPoint(200, 0)); var move_back = (CCActionInterval) move.Reverse(); CCFiniteTimeAction seq = CCSequence.FromActions(move, move_back); CCAction fe2 = new CCRepeatForever ((CCActionInterval) seq); back.RunAction(fe2); }
public SpriteBatchNodeAliased() { CCSpriteBatchNode batch = CCSpriteBatchNode.Create("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 IntervalLayer() { m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f; CCSize s = CCDirector.SharedDirector.WinSize; // sun CCParticleSystem sun = CCParticleSun.Create(); sun.Texture = CCTextureCache.SharedTextureCache.AddImage("Images/fire"); sun.Position = (new CCPoint(s.Width - 32, s.Height - 32)); sun.TotalParticles = 130; sun.Life = (0.6f); AddChild(sun); // timers m_label0 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt"); m_label1 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt"); m_label2 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt"); m_label3 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt"); m_label4 = CCLabelBMFont.Create("0", "fonts/bitmapFontTest4.fnt"); ScheduleUpdate(); Schedule(step1); Schedule(step2, 0); Schedule(step3, 1.0f); Schedule(step4, 2.0f); m_label0.Position = new CCPoint(s.Width * 1 / 6, s.Height / 2); m_label1.Position = new CCPoint(s.Width * 2 / 6, s.Height / 2); m_label2.Position = new CCPoint(s.Width * 3 / 6, s.Height / 2); m_label3.Position = new CCPoint(s.Width * 4 / 6, s.Height / 2); m_label4.Position = new CCPoint(s.Width * 5 / 6, s.Height / 2); AddChild(m_label0); AddChild(m_label1); AddChild(m_label2); AddChild(m_label3); AddChild(m_label4); // Sprite CCSprite sprite = new CCSprite(s_pPathGrossini); sprite.Position = new CCPoint(40, 50); CCJumpBy jump = new CCJumpBy (3, new CCPoint(s.Width - 80, 0), 50, 4); AddChild(sprite); sprite.RunAction(new CCRepeatForever ( (CCActionInterval) (CCSequence.FromActions(jump, jump.Reverse()))) ); // pause button CCMenuItem item1 = CCMenuItemFont.Create("Pause", onPause); CCMenu menu = new CCMenu(item1); menu.Position = new CCPoint(s.Width / 2, s.Height - 50); AddChild(menu); }
public TextLayer() { InitWithColor(CCTypes.CreateColor(32, 32, 32, 255)); float x, y; CCSize size = CCDirector.SharedDirector.WinSize; x = size.Width; y = size.Height; CCNode node = new CCNode (); CCActionInterval effect = getAction(); node.RunAction(effect); AddChild(node, 0, EffectTestScene.kTagBackground); CCSprite bg = new CCSprite(TestResource.s_back3); node.AddChild(bg, 0); bg.AnchorPoint = new CCPoint(0.5f, 0.5f); bg.Position = new CCPoint(size.Width / 2, size.Height / 2); CCSprite grossini = new CCSprite(TestResource.s_pPathSister2); node.AddChild(grossini, 1); grossini.Position = new CCPoint(x / 3, y / 2); CCActionInterval sc = new CCScaleBy(2, 5); CCFiniteTimeAction sc_back = sc.Reverse(); grossini.RunAction(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(sc, sc_back)))); //grossini.runAction(effect); CCSprite tamara = new CCSprite(TestResource.s_pPathSister1); node.AddChild(tamara, 1); tamara.Position = new CCPoint(2 * x / 3, y / 2); CCActionInterval sc2 = new CCScaleBy(2, 5); CCFiniteTimeAction sc2_back = sc2.Reverse(); tamara.RunAction(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(sc2, sc2_back)))); CCLabelTTF label = new CCLabelTTF(EffectTestScene.effectsList[EffectTestScene.actionIdx], "arial", 32); label.Position = new CCPoint(x / 2, y - 80); AddChild(label); label.Tag = EffectTestScene.kTagLabel; CCMenuItemImage item1 = new CCMenuItemImage(TestResource.s_pPathB1, TestResource.s_pPathB2, backCallback); CCMenuItemImage item2 = new CCMenuItemImage(TestResource.s_pPathR1, TestResource.s_pPathR2, restartCallback); CCMenuItemImage item3 = new CCMenuItemImage(TestResource.s_pPathF1, TestResource.s_pPathF2, nextCallback); CCMenu menu = new CCMenu(item1, item2, item3); menu.Position = new CCPoint(0, 0); item1.Position = new CCPoint(size.Width / 2 - 100, 30); item2.Position = new CCPoint(size.Width / 2, 30); item3.Position = new CCPoint(size.Width / 2 + 100, 30); AddChild(menu, 1); Schedule(checkAnim); }
public override void OnEnter() { base.OnEnter(); float x, y; CCSize size = CCDirector.SharedDirector.WinSize; x = size.Width; y = size.Height; CCSprite bg = new CCSprite("Images/background3"); AddChild(bg, 0, EffectAdvanceScene.kTagBackground); bg.Position = new CCPoint(x / 2, y / 2); grossini = new CCSprite("Images/grossinis_sister2"); bg.AddChild(grossini, 1, EffectAdvanceScene.kTagSprite1); grossini.Position = new CCPoint(x / 3.0f, 200); CCActionInterval sc = new CCScaleBy(2, 5); CCFiniteTimeAction sc_back = sc.Reverse(); grossini.RunAction(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(sc, sc_back)))); tamara = new CCSprite("Images/grossinis_sister1"); bg.AddChild(tamara, 1, EffectAdvanceScene.kTagSprite2); tamara.Position = new CCPoint(2 * x / 3.0f, 200); CCActionInterval sc2 = new CCScaleBy(2, 5); CCFiniteTimeAction sc2_back = sc2.Reverse(); tamara.RunAction(new CCRepeatForever ((CCActionInterval)(CCSequence.FromActions(sc2, sc2_back)))); CCLabelTTF label = new CCLabelTTF(title(), "arial", 28); label.Position = new CCPoint(x / 2, y - 80); AddChild(label); label.Tag = EffectAdvanceScene.kTagLabel; string strSubtitle = subtitle(); if (strSubtitle != null) { CCLabelTTF l = new CCLabelTTF(strSubtitle, "arial", 16); AddChild(l, 101); l.Position = new CCPoint(size.Width / 2, size.Height - 80); } CCMenuItemImage item1 = new CCMenuItemImage("Images/b1", "Images/b2", backCallback); CCMenuItemImage item2 = new CCMenuItemImage("Images/r1", "Images/r2", restartCallback); CCMenuItemImage item3 = new CCMenuItemImage("Images/f1", "Images/f2", nextCallback); CCMenu menu = CCMenu.Create(item1, item2, item3); menu.Position = new CCPoint(0, 0); item1.Position = new CCPoint(size.Width / 2 - 100, 30); item2.Position = new CCPoint(size.Width / 2, 30); item3.Position = new CCPoint(size.Width / 2 + 100, 30); AddChild(menu, 1); }
public override void OnEnter() { base.OnEnter(); float x, y; CCSize size = CCDirector.SharedDirector.WinSize; x = size.Width; y = size.Height; CCSprite sprite = new CCSprite(s_pPathGrossini); CCSprite spriteSister1 = new CCSprite(s_pPathSister1); CCSprite spriteSister2 = new CCSprite(s_pPathSister2); sprite.Scale = (1.5f); spriteSister1.Scale = (1.5f); spriteSister2.Scale = (1.5f); sprite.Position = (new CCPoint(x / 2, y / 2)); spriteSister1.Position = (new CCPoint(40, y / 2)); spriteSister2.Position = (new CCPoint(x - 40, y / 2)); CCAction rot = new CCRotateBy (16, -3600); AddChild(sprite); AddChild(spriteSister1); AddChild(spriteSister2); sprite.RunAction(rot); CCActionInterval jump1 = new CCJumpBy (4, new CCPoint(-400, 0), 100, 4); CCActionInterval jump2 = (CCActionInterval)jump1.Reverse(); CCActionInterval rot1 = new CCRotateBy (4, 360 * 2); CCActionInterval rot2 = (CCActionInterval)rot1.Reverse(); spriteSister1.RunAction(new CCRepeat (CCSequence.FromActions(jump2, jump1), 5)); spriteSister2.RunAction(new CCRepeat (CCSequence.FromActions((CCFiniteTimeAction)(jump1.Copy()), (CCFiniteTimeAction)(jump2.Copy())), 5)); spriteSister1.RunAction(new CCRepeat (CCSequence.FromActions(rot1, rot2), 5)); spriteSister2.RunAction(new CCRepeat (CCSequence.FromActions((CCFiniteTimeAction)(rot2.Copy()), (CCFiniteTimeAction)(rot1.Copy())), 5)); }
public override void OnEnter() { base.OnEnter(); CCSize s = CCDirector.SharedDirector.WinSize; CCLabelTTF l = new CCLabelTTF("Grossini only rotate/scale in 3 seconds", "arial", 16); AddChild(l); l.Position = (new CCPoint(s.Width / 2, 245)); CCSprite pGrossini = new CCSprite(s_pPathGrossini); AddChild(pGrossini, 0, (int)KTag.kTagGrossini); pGrossini.Position = new CCPoint(s.Width / 2, s.Height / 2); pGrossini.RunAction(new CCScaleBy(2, 2)); CCDirector.SharedDirector.ActionManager.PauseTarget(pGrossini); pGrossini.RunAction(new CCRotateBy (2, 360)); this.Schedule(resumeGrossini, 3.0f); }
public SpriteChildrenVisibility() { 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)); aParent.AddChild(sprite1); sprite1.AddChild(sprite2, -2); sprite1.AddChild(sprite3, 2); sprite1.RunAction(new CCBlink (5, 10)); // // 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)); aParent.AddChild(sprite1); sprite1.AddChild(sprite2, -2); sprite1.AddChild(sprite3, 2); sprite1.RunAction(new CCBlink (5, 10)); }
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 override void OnEnter() { base.OnEnter(); CCSprite child = new CCSprite(s_pPathGrossini); child.Position = (new CCPoint(200, 200)); AddChild(child, 1); //Sum of all action's duration is 1.5 second. child.RunAction(new CCRotateBy (1.5f, 90)); child.RunAction(CCSequence.FromActions( new CCDelayTime (1.4f), new CCFadeOut (1.1f)) ); //After 1.5 second, self will be removed. RunAction(CCSequence.FromActions( new CCDelayTime (1.4f), new CCCallFunc((removeThis))) ); }
public CameraCenterTest() { CCSize s = CCDirector.SharedDirector.WinSize; CCSprite sprite; CCOrbitCamera orbit; // LEFT-TOP sprite = new CCSprite("Images/white-512x512"); AddChild(sprite, 0); sprite.Position = new CCPoint(s.Width / 5 * 1, s.Height / 5 * 1); sprite.Color = CCTypes.CCRed; sprite.TextureRect = new CCRect(0, 0, 120, 50); orbit = new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0); sprite.RunAction(new CCRepeatForever (orbit)); // LEFT-BOTTOM sprite = new CCSprite("Images/white-512x512"); AddChild(sprite, 0, 40); sprite.Position = (new CCPoint(s.Width / 5 * 1, s.Height / 5 * 4)); sprite.Color = CCTypes.CCBlue; sprite.TextureRect = new CCRect(0, 0, 120, 50); orbit = new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0); sprite.RunAction(new CCRepeatForever (orbit)); // RIGHT-TOP sprite = new CCSprite("Images/white-512x512"); AddChild(sprite, 0); sprite.Position = (new CCPoint(s.Width / 5 * 4, s.Height / 5 * 1)); sprite.Color = CCTypes.CCYellow; sprite.TextureRect = new CCRect(0, 0, 120, 50); orbit = new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0); sprite.RunAction(new CCRepeatForever (orbit)); // RIGHT-BOTTOM sprite = new CCSprite("Images/white-512x512"); AddChild(sprite, 0, 40); sprite.Position = (new CCPoint(s.Width / 5 * 4, s.Height / 5 * 4)); sprite.Color = CCTypes.CCGreen; sprite.TextureRect = new CCRect(0, 0, 120, 50); orbit = new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0); sprite.RunAction(new CCRepeatForever (orbit)); // CENTER sprite = new CCSprite("Images/white-512x512"); AddChild(sprite, 0, 40); sprite.Position = (new CCPoint(s.Width / 2, s.Height / 2)); sprite.Color = CCTypes.CCWhite; sprite.TextureRect = new CCRect(0, 0, 120, 50); orbit = new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0); sprite.RunAction(new CCRepeatForever (orbit)); }
public override void OnEnter() { base.OnEnter(); CCSprite grossini = new CCSprite(s_pPathGrossini); AddChild(grossini, 0, 2); grossini.Position = (new CCPoint(200, 200)); grossini.RunAction(CCSequence.FromActions( new CCMoveBy (1, new CCPoint(150, 0)), new CCCallFuncN(bugMe)) ); }
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 CameraOrbitTest() { CCSize s = CCDirector.SharedDirector.WinSize; CCSprite p = new CCSprite(TestResource.s_back3); AddChild(p, 0); p.Position = (new CCPoint(s.Width / 2, s.Height / 2)); p.Opacity = 128; CCSprite sprite; CCOrbitCamera orbit; CCCamera cam; CCSize ss; // LEFT s = p.ContentSize; sprite = new CCSprite(TestResource.s_pPathGrossini); sprite.Scale = (0.5f); p.AddChild(sprite, 0); sprite.Position = (new CCPoint(s.Width / 4 * 1, s.Height / 2)); cam = sprite.Camera; orbit = new CCOrbitCamera(2, 1, 0, 0, 360, 0, 0); sprite.RunAction(new CCRepeatForever (orbit)); // CENTER sprite = new CCSprite(TestResource.s_pPathGrossini); sprite.Scale = 1.0f; p.AddChild(sprite, 0); sprite.Position = new CCPoint(s.Width / 4 * 2, s.Height / 2); orbit = new CCOrbitCamera(2, 1, 0, 0, 360, 45, 0); sprite.RunAction(new CCRepeatForever (orbit)); // RIGHT sprite = new CCSprite(TestResource.s_pPathGrossini); sprite.Scale = 2.0f; p.AddChild(sprite, 0); sprite.Position = new CCPoint(s.Width / 4 * 3, s.Height / 2); ss = sprite.ContentSize; orbit = new CCOrbitCamera(2, 1, 0, 0, 360, 90, -45); sprite.RunAction(new CCRepeatForever (orbit)); // PARENT orbit = new CCOrbitCamera(10, 1, 0, 0, 360, 0, 90); p.RunAction(new CCRepeatForever (orbit)); Scale = 1; }
public MainLayer() { base.TouchEnabled = true; CCSprite sprite = new CCSprite(ClickAndMoveTest.s_pPathGrossini); CCLayer layer = CCLayerColor.Create(new CCColor4B(255, 255, 0, 255)); AddChild(layer, -1); AddChild(sprite, 0, ClickAndMoveTest.kTagSprite); sprite.Position = new CCPoint(20, 150); sprite.RunAction(new CCJumpTo (4, new CCPoint(300, 48), 100, 4)); layer.RunAction(new CCRepeatForever ( (CCActionInterval)(CCSequence.FromActions( new CCFadeIn (1), new CCFadeOut (1))) )); }
public SceneTestLayer1() { CCMenuItemFont item1 = CCMenuItemFont.Create("(1) Test pushScene", onPushScene); CCMenuItemFont item2 = CCMenuItemFont.Create("(1) Test pushScene w/transition", onPushSceneTran); CCMenuItemFont item3 = CCMenuItemFont.Create("(1) Quit", onQuit); _PopMenuItem = CCMenuItemFont.Create("(1) Test popScene w/transition", onPopSceneTran); _TheMenu = new CCMenu(item1, item2, item3, _PopMenuItem); _TheMenu.AlignItemsVertically(); AddChild(_TheMenu); CCSize s = CCDirector.SharedDirector.WinSize; CCSprite sprite = new CCSprite(s_pPathGrossini); AddChild(sprite); sprite.Position = new CCPoint(s.Width - 40, s.Height / 2); CCActionInterval rotate = new CCRotateBy (2, 360); CCAction repeat = new CCRepeatForever (rotate); sprite.RunAction(repeat); }
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 = CCSpriteBatchNode.Create("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 override void OnEnter() { base.OnEnter(); CCSize s = CCDirector.SharedDirector.WinSize; CCLabelTTF l = new CCLabelTTF("Should not crash", "arial", 16); AddChild(l); l.Position = (new CCPoint(s.Width / 2, 245)); CCMoveBy pMove = new CCMoveBy (2, new CCPoint(200, 0)); CCCallFunc pCallback = new CCCallFunc(stopAction); CCActionInterval pSequence = (CCActionInterval)CCSequence.FromActions(pMove, pCallback); pSequence.Tag = (int)KTag.kTagSequence; CCSprite pChild = new CCSprite(s_pPathGrossini); pChild.Position = (new CCPoint(200, 200)); AddChild(pChild, 1, kTagGrossini); pChild.RunAction(pSequence); }
public SpriteAnimationSplit() { CCSize s = CCDirector.SharedDirector.WinSize; CCTexture2D texture = CCTextureCache.SharedTextureCache.AddImage("animations/dragon_animation"); // manually add frames to the frame cache CCSpriteFrame frame0 = CCSpriteFrame.Create(texture, new CCRect(132 * 0, 132 * 0, 132, 132)); CCSpriteFrame frame1 = CCSpriteFrame.Create(texture, new CCRect(132 * 1, 132 * 0, 132, 132)); CCSpriteFrame frame2 = CCSpriteFrame.Create(texture, new CCRect(132 * 2, 132 * 0, 132, 132)); CCSpriteFrame frame3 = CCSpriteFrame.Create(texture, new CCRect(132 * 3, 132 * 0, 132, 132)); CCSpriteFrame frame4 = CCSpriteFrame.Create(texture, new CCRect(132 * 0, 132 * 1, 132, 132)); CCSpriteFrame frame5 = CCSpriteFrame.Create(texture, new CCRect(132 * 1, 132 * 1, 132, 132)); // // Animation using Sprite BatchNode // CCSprite sprite = new CCSprite(frame0); sprite.Position = (new CCPoint(s.Width / 2 - 80, s.Height / 2)); AddChild(sprite); var animFrames = new List<CCSpriteFrame>(6); animFrames.Add(frame0); animFrames.Add(frame1); animFrames.Add(frame2); animFrames.Add(frame3); animFrames.Add(frame4); animFrames.Add(frame5); CCAnimation animation = CCAnimation.Create(animFrames, 0.2f); CCAnimate animate = new CCAnimate (animation); CCActionInterval seq = (CCActionInterval)(CCSequence.FromActions(animate, CCFlipX.Create(true), (CCFiniteTimeAction)animate.Copy(), CCFlipX.Create(false) )); sprite.RunAction(new CCRepeatForever (seq)); //animFrames->release(); // win32 : memory leak 2010-0415 }
public override void OnEnter() { base.OnEnter(); CCSize s = CCDirector.SharedDirector.WinSize; CCSprite sp1 = new CCSprite(TestResource.s_pPathSister1); CCSprite sp2 = new CCSprite(TestResource.s_pPathSister2); CCSprite sp3 = new CCSprite(TestResource.s_pPathSister1); CCSprite sp4 = new CCSprite(TestResource.s_pPathSister2); sp1.Position = (new CCPoint(100, s.Height / 2)); sp2.Position = (new CCPoint(380, s.Height / 2)); AddChild(sp1); AddChild(sp2); sp3.Scale = (0.25f); sp4.Scale = (0.25f); sp1.AddChild(sp3); sp2.AddChild(sp4); CCActionInterval a1 = new CCRotateBy (2, 360); CCActionInterval a2 = new CCScaleBy(2, 2); CCAction action1 = new CCRepeatForever ((CCActionInterval)CCSequence.FromActions(a1, a2, a2.Reverse()) ); CCAction action2 = new CCRepeatForever ((CCActionInterval) (CCSequence.FromActions( (CCActionInterval) (a1.Copy()), (CCActionInterval) (a2.Copy()), a2.Reverse())) ); sp2.AnchorPoint = (new CCPoint(0, 0)); sp1.RunAction(action1); sp2.RunAction(action2); }