public SpriteFrameTest() { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFrames("animations/grossini.plist"); cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray"); cache.AddSpriteFrames("animations/grossini_blue.plist", "animations/grossini_blue"); var animFrames = new List<CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { str = string.Format("grossini_dance_{0:00}.png", i); CCSpriteFrame frame = cache[str]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.3f); var moreFrames = new List<CCSpriteFrame>(20); for (int i = 1; i < 15; i++) { string temp; str = string.Format("grossini_dance_gray_{0:00}.png", i); CCSpriteFrame frame = cache[str]; moreFrames.Add(frame); } for (int i = 1; i < 5; i++) { str = string.Format("grossini_blue_{0:00}.png", i); CCSpriteFrame frame = cache[str]; moreFrames.Add(frame); } // append frames from another batch moreFrames.AddRange(animFrames); animMixed = new CCAnimation(moreFrames, 0.3f); CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini"); AddChild(spritebatch); sprite1 = new CCSprite("grossini_dance_01.png"); spritebatch.AddChild(sprite1); // to test issue #732, uncomment the following line sprite1.FlipX = false; sprite1.FlipY = false; // Animation using standard Sprite sprite2 = new CCSprite("grossini_dance_01.png"); AddChild(sprite2); // to test issue #732, uncomment the following line sprite2.FlipX = false; sprite2.FlipY = false; }
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. // // small capacity. Testing resizing. // Don't use capacity=1 in your real game. It is expensive to resize the capacity batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 1); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprites = new CCSprite[numOfSprites]; for (int i = 0; i < 5; i++) { sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121)); sprites[i].VertexZ = (10 + i * 40); batch.AddChild(sprites[i], 0); } for (int i = 5; i < 11; i++) { sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121)); sprites[i].VertexZ = 10 + (10 - i) * 40; batch.AddChild(sprites[i], 0); } }
public GameLayer() { var touchListener = new CCEventListenerTouchAllAtOnce (); touchListener.OnTouchesEnded = OnTouchesEnded; AddEventListener (touchListener, this); Color = new CCColor3B (CCColor4B.White); Opacity = 255; visibleBananas = new List<CCSprite> (); hitBananas = new List<CCSprite> (); // batch node for physics balls ballsBatch = new CCSpriteBatchNode ("balls", 100); ballTexture = ballsBatch.Texture; AddChild (ballsBatch, 1, 1); AddGrass (); AddSun (); AddMonkey (); StartScheduling(); CCSimpleAudioEngine.SharedEngine.PlayBackgroundMusic ("Sounds/backgroundMusic", true); }
public void ProcessSprite(CCSpriteBatchNode sprite) { //sprite.BlendFunc = new CCBlendFunc(blendSrc, blendDst); //sprite.IsAntialiased = true; //sprite.IsOpacityModifyRGB = true; //sprite. }
public override void OnEnter() { base.OnEnter(); CCSize winSize = Layer.VisibleBoundsWorldspace.Size; float x = winSize.Width / 2; float y = 0 + (winSize.Height / 2); CCLog.Log("S9BatchNodeBasic ..."); var batchNode = new CCSpriteBatchNode("Images/blocks9.png"); //batchNode.AnchorPoint = new CCPoint(0.5f, 0.5f); CCLog.Log("batchNode created with : Images/blocks9.png"); var blocks = new CCScale9Sprite(); CCLog.Log("... created"); blocks.UpdateWithBatchNode(batchNode, new CCRect(0, 0, 96, 96), false, new CCRect(0, 0, 96, 96)); CCLog.Log("... updateWithBatchNode"); blocks.Position = new CCPoint(x, y); CCLog.Log("... setPosition"); AddChild(blocks); CCLog.Log("AddChild"); CCLog.Log("... S9BatchNodeBasic done."); }
public SpriteBatchNodeZOrder() { 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); sprites = new CCSprite[numOfSprites]; for (int i = 0; i < 5; i++) { sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121)); batch.AddChild(sprites[i], i); } for (int i = 5; i < 10; i++) { sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121)); batch.AddChild(sprites[i], 14 - i); } sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 0, 85, 121)); batch.AddChild(sprite1, -1, (int)kTagSprite.kTagSprite1); sprite1.Scale = 6; sprite1.Color = CCColor3B.Red; }
public SpriteBatchNodeNewTexture() { CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); texture1 = batch.Texture; texture2 = CCTextureCache.SharedTextureCache.AddImage("Images/grossini_dance_atlas-mono"); }
public override void initWithQuantityOfNodes(int nNodes) { batchNode = new CCSpriteBatchNode("Images/spritesheet1"); AddChild(batchNode); base.initWithQuantityOfNodes(nNodes); Schedule (); }
public SpriteBatchNodeReorderIssue766() { batchNode = new CCSpriteBatchNode("Images/piece", 15); AddChild(batchNode, 1, 0); sprite1 = MakeSpriteZ(2); sprite2 = MakeSpriteZ(3); sprite3 = MakeSpriteZ(4); }
public MainLayer() { var batchnode = new CCSpriteBatchNode("Images/sprites", 10); AddChild(batchnode, -1, (int)Tags.SpriteManager); var background = new CCSprite(batchnode.Texture, new CCRect(0, 0, 320, 480)); background.Position = new CCPoint(160, 240); batchnode.AddChild(background); }
public SpriteBatchNodeOffsetAnchorSkewScale() { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFrames("animations/grossini.plist"); cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray"); // Create animations and actions var animFrames = new List<CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { string temp = ""; if (j+1<10) { temp = "0" + (j + 1); } else { temp = (j + 1).ToString(); } tmp = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache[tmp]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.3f); // skew CCSkewBy skewX = new CCSkewBy (2, 45, 0); CCFiniteTimeAction skewX_back = (CCFiniteTimeAction)skewX.Reverse(); CCSkewBy skewY = new CCSkewBy (2, 0, 45); CCFiniteTimeAction skewY_back = (CCFiniteTimeAction)skewY.Reverse(); // scale CCScaleBy scale = new CCScaleBy(2, 2); CCFiniteTimeAction scale_back = (CCFiniteTimeAction)scale.Reverse(); seq_scale = new CCSequence(scale, scale_back); seq_skew = new CCSequence(skewX, skewX_back, skewY, skewY_back); sprites = new CCSprite[numOfSprites]; pointSprites = new CCSprite[numOfSprites]; for (int i = 0; i < numOfSprites; i++) { // Animation using Sprite batch sprites[i] = new CCSprite("grossini_dance_01.png"); pointSprites[i] = new CCSprite("Images/r1"); CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini"); AddChild(spritebatch); AddChild(pointSprites[i], 200); spritebatch.AddChild(sprites[i], i); } }
void InitCCScale9Sprite(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets) { if (batchnode != null) { UpdateWithBatchNode(batchnode, rect, rotated, capInsets); } AnchorPoint = new CCPoint(0.5f, 0.5f); positionsAreDirty = true; }
public SpriteBatchNodeFlip() { CCSpriteBatchNode batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 10); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121)); batch.AddChild(sprite1, 0, (int)kTagSprite.kTagSprite1); sprite2 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121)); batch.AddChild(sprite2, 0, (int)kTagSprite.kTagSprite2); }
public CCSpriteBatchNode AddBatchSprite(string filename) { if (filename.EndsWith(".plist")) filename = filename.Replace(".plist", ""); var batch = new CCSpriteBatchNode(filename); AddChild(batch); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames(filename + ".plist"); return batch; }
public SpriteBatchNode1() { CCSpriteBatchNode BatchNode = new CCSpriteBatchNode("Images/grossini_dance_atlas", 50); AddChild(BatchNode, 0, (int)kTags.kTagSpriteBatchNode); // Register Touch Event var touchListener = new CCEventListenerTouchAllAtOnce(); touchListener.OnTouchesEnded = OnTouchesEnded; AddEventListener(touchListener); }
public SpriteBatchNodeReorderIssue744() { // 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); sprite = new CCSprite(batch.Texture, new CCRect(0, 0, 85, 121)); batch.AddChild(sprite, 3); batch.ReorderChild(sprite, 1); }
public SpriteBatchNodeChildrenChildren() { CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("animations/ghosts.plist"); var rot = new CCRotateBy (10, 360); seq = new CCRepeatForever (rot); var rot_back = rot.Reverse(); rot_back_fe = new CCRepeatForever (rot_back); // SpriteBatchNode: 3 levels of children aParent = new CCSpriteBatchNode("animations/ghosts"); AddChild(aParent); // parent l1 = new CCSprite("father.gif"); aParent.AddChild(l1); // child left l2a = new CCSprite("sister1.gif"); l1.AddChild(l2a); // child right l2b = new CCSprite("sister2.gif"); l1.AddChild(l2b); // child left bottom l3a1 = new CCSprite("child1.gif"); l3a1.Scale = 0.45f; l2a.AddChild(l3a1); // child left top l3a2 = new CCSprite("child1.gif"); l3a2.Scale = 0.45f; l2a.AddChild(l3a2); // child right bottom l3b1 = new CCSprite("child1.gif"); l3b1.Scale = 0.45f; l3b1.FlipY = true; l2b.AddChild(l3b1); // child right top l3b2 = new CCSprite("child1.gif"); l3b2.Scale = 0.45f; l3b2.FlipY = true; l2b.AddChild(l3b2); }
public SpriteBatchNodeChildrenZ() { CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("animations/grossini.plist"); // test 1 batch = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprite1 = new CCSprite("grossini_dance_01.png"); sprite2 = new CCSprite("grossini_dance_02.png"); sprite3 = new CCSprite("grossini_dance_03.png"); batch.AddChild(sprite1); sprite1.AddChild(sprite2, 2); sprite1.AddChild(sprite3, -2); // test 2 batch2 = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch2, 0, (int)kTags.kTagSpriteBatchNode); sprite4 = new CCSprite("grossini_dance_01.png"); sprite5 = new CCSprite("grossini_dance_02.png"); sprite6 = new CCSprite("grossini_dance_03.png"); batch.AddChild(sprite4); sprite4.AddChild(sprite5, -2); sprite4.AddChild(sprite6, 2); // test 3 batch3 = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch3, 0, (int)kTags.kTagSpriteBatchNode); sprite7 = new CCSprite("grossini_dance_01.png"); sprite8 = new CCSprite("grossini_dance_02.png"); sprite9 = new CCSprite("grossini_dance_03.png"); batch3.AddChild(sprite7, 10); batch3.AddChild(sprite8, -10); batch3.AddChild(sprite9, -5); // test 4 batch4 = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch4, 0, (int)kTags.kTagSpriteBatchNode); sprite10 = new CCSprite("grossini_dance_01.png"); sprite11 = new CCSprite("grossini_dance_02.png"); sprite12 = new CCSprite("grossini_dance_03.png"); batch4.AddChild(sprite10, -10); batch4.AddChild(sprite11, -5); batch4.AddChild(sprite12, -2); }
public SpriteBatchNodeChildrenAnchorPoint() { CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("animations/grossini.plist"); CCNode aParent; aParent = new CCSpriteBatchNode("animations/grossini", 50); AddChild(aParent, 0); sprite1 = new CCSprite("grossini_dance_08.png"); sprite2 = new CCSprite("grossini_dance_02.png"); sprite3 = new CCSprite("grossini_dance_03.png"); sprite4 = new CCSprite("grossini_dance_04.png"); aParent.AddChild(sprite1); sprite1.AddChild(sprite2, -2); sprite1.AddChild(sprite3, -2); sprite1.AddChild(sprite4, 3); point = new CCSprite("Images/r1"); AddChild(point, 10); sprite5 = new CCSprite("grossini_dance_08.png"); sprite6 = new CCSprite("grossini_dance_02.png"); sprite7 = new CCSprite("grossini_dance_03.png"); sprite8 = new CCSprite("grossini_dance_04.png"); aParent.AddChild(sprite5); sprite5.AddChild(sprite6, -2); sprite5.AddChild(sprite7, -2); sprite5.AddChild(sprite8, 3); point2 = new CCSprite("Images/r1"); AddChild(point2, 10); sprite9 = new CCSprite("grossini_dance_08.png"); sprite10 = new CCSprite("grossini_dance_02.png"); sprite11 = new CCSprite("grossini_dance_03.png"); sprite12 = new CCSprite("grossini_dance_04.png"); sprite12.Position = (new CCPoint(0, 0)); sprite12.Scale = 0.5f; aParent.AddChild(sprite9); sprite9.AddChild(sprite10, -2); sprite9.AddChild(sprite11, -2); sprite9.AddChild(sprite12, 3); point3 = new CCSprite("Images/r1"); AddChild(point3, 10); }
public SpriteBatchNodeOffsetAnchorFlip() { CCSpriteFrameCache cache = CCSpriteFrameCache.SharedSpriteFrameCache; cache.AddSpriteFrames("animations/grossini.plist"); cache.AddSpriteFrames("animations/grossini_gray.plist", "animations/grossini_gray"); // Create animations and actions var animFrames = new List<CCSpriteFrame>(); string tmp = ""; for (int j = 0; j < 14; j++) { string temp = ""; if (j+1<10) { temp = "0" + (j + 1); } else { temp = (j + 1).ToString(); } tmp = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = cache[tmp]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.3f); CCFlipY flip = new CCFlipY(true); CCFlipY flip_back = new CCFlipY(false); CCDelayTime delay = new CCDelayTime (1); seq = new CCSequence(delay, flip, delay, flip_back); sprites = new CCSprite[numOfSprites]; pointSprites = new CCSprite[numOfSprites]; for (int i = 0; i < numOfSprites; i++) { // Animation using Sprite batch sprites[i] = new CCSprite("grossini_dance_01.png"); pointSprites[i] = new CCSprite("Images/r1"); CCSpriteBatchNode spritebatch = new CCSpriteBatchNode("animations/grossini"); AddChild(spritebatch); AddChild(pointSprites[i], 200); spritebatch.AddChild(sprites[i], i); } }
public override void RemoveAllChildren(bool cleanup) { if (batchNode != null) { CCSpriteBatchNode batch = batchNode; CCNode[] elements = Children.Elements; for (int i = 0, count = Children.Count; i < count; i++) { batch.RemoveSpriteFromAtlas((CCSprite)elements[i]); } } base.RemoveAllChildren(cleanup); }
public SpriteSubclass() { CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("animations/ghosts.plist"); CCSpriteBatchNode aParent = new CCSpriteBatchNode("animations/ghosts"); // MySprite1 sprite = MySprite1.Create("father.gif"); aParent.AddChild(sprite); AddChild(aParent); // MySprite2 sprite2 = new MySprite2("Images/grossini"); AddChild(sprite2); }
public SpriteBatchNodeChildrenScale() { CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("animations/grossini_family.plist"); var rot = new CCRotateBy (10, 360); seq = new CCRepeatForever(rot); // Children + Scale using Sprite // Test 1 aParent = new CCNode(); sprite1 = new CCSprite("grossinis_sister1.png"); sprite2 = new CCSprite("grossinis_sister2.png"); AddChild(aParent); aParent.AddChild(sprite1); sprite1.AddChild(sprite2); // Children + Scale using SpriteBatchNode // Test 2 aParent2 = new CCSpriteBatchNode("animations/grossini_family"); sprite3 = new CCSprite("grossinis_sister1.png"); sprite4 = new CCSprite("grossinis_sister2.png"); sprite4.Position = (new CCPoint(50, 0)); AddChild(aParent2); aParent2.AddChild(sprite3); sprite3.AddChild(sprite4); // Children + Scale using Sprite // Test 3 aParent3 = new CCNode (); sprite5 = new CCSprite("grossinis_sister1.png"); sprite6 = new CCSprite("grossinis_sister2.png"); AddChild(aParent3); aParent3.AddChild(sprite5); sprite5.AddChild(sprite6); // Children + Scale using Sprite // Test 4 aParent4 = new CCSpriteBatchNode("animations/grossini_family"); sprite7 = new CCSprite("grossinis_sister1.png"); sprite8 = new CCSprite("grossinis_sister2.png"); AddChild(aParent4); aParent4.AddChild(sprite7); sprite7.AddChild(sprite8); }
public CCControlColourPicker() { // Register Touch Event var touchListener = new CCEventListenerTouchOneByOne(); touchListener.IsSwallowTouches = true; touchListener.OnTouchBegan = OnTouchBegan; AddEventListener(touchListener); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("extensions/CCControlColourPickerSpriteSheet.plist"); var spriteSheet = new CCSpriteBatchNode("extensions/CCControlColourPickerSpriteSheet.png"); AddChild(spriteSheet); Hsv.H = 0; Hsv.S = 0; Hsv.V = 0; // Add image Background = CCControlUtils.AddSpriteToTargetWithPosAndAnchor("menuColourPanelBackground.png", spriteSheet, CCPoint.Zero, new CCPoint(0.5f, 0.5f)); CCPoint backgroundPointZero = Background.Position - new CCPoint(Background.ContentSize.Width / 2, Background.ContentSize.Height / 2); // Setup panels float hueShift = 8; float colourShift = 28; CCPoint huePickerPos = new CCPoint(backgroundPointZero.X + hueShift, backgroundPointZero.Y + hueShift); HuePicker = new CCControlHuePicker(spriteSheet, huePickerPos); CCPoint colourPickerPos = new CCPoint(backgroundPointZero.X + colourShift, backgroundPointZero.Y + colourShift); ColourPicker = new CCControlSaturationBrightnessPicker(spriteSheet, colourPickerPos); // Setup events HuePicker.AddTargetWithActionForControlEvents(this, HueSliderValueChanged, CCControlEvent.ValueChanged); ColourPicker.AddTargetWithActionForControlEvents(this, ColourSliderValueChanged, CCControlEvent.ValueChanged); UpdateHueAndControlPicker(); AddChild(HuePicker); AddChild(ColourPicker); ContentSize = Background.ContentSize; }
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 SpriteBatchNodeAliased() { var batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 10); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121)); batch.AddChild(sprite1, 0, (int)kTagSprite.kTagSprite1); sprite2 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121)); batch.AddChild(sprite2, 0, (int)kTagSprite.kTagSprite2); var scale = new CCScaleBy(2, 5); var scale_back = (CCFiniteTimeAction)scale.Reverse(); repeat = new CCRepeatForever (scale, scale_back); }
public GameLayer () { var touchListener = new CCEventListenerTouchAllAtOnce (); touchListener.OnTouchesEnded = OnTouchesEnded; AddEventListener (touchListener, this); Color = new CCColor3B (CCColor4B.White); Opacity = 255; visibleBananas = new List<CCSprite> (); hitBananas = new List<CCSprite> (); // batch node for physics balls ballsBatch = new CCSpriteBatchNode ("balls", 100); ballTexture = ballsBatch.Texture; AddChild (ballsBatch, 1, 1); AddGrass (); AddSun (); AddMonkey (); Schedule (t => { visibleBananas.Add (AddBanana ()); elapsedTime += t; if (ShouldEndGame ()) { EndGame (); } AddBall (); }, 1.0f); Schedule (t => CheckCollision ()); Schedule (t => { world.Step (t, 8, 1); foreach (CCPhysicsSprite sprite in ballsBatch.Children) { if (sprite.Visible && sprite.PhysicsBody.Position.x < 0f || sprite.PhysicsBody.Position.x * PTM_RATIO > ContentSize.Width) { //or should it be Layer.VisibleBoundsWorldspace.Size.Width world.DestroyBody (sprite.PhysicsBody); sprite.Visible = false; sprite.RemoveFromParent (); } else { sprite.UpdateTransformedSpriteTextureQuads (); } } }); }
public SpriteBatchNodeChildren() { CCSpriteBatchNode batch = new CCSpriteBatchNode("animations/grossini", 50); AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("animations/grossini.plist"); sprite1 = new CCSprite("grossini_dance_01.png"); sprite2 = new CCSprite("grossini_dance_02.png"); sprite3 = new CCSprite("grossini_dance_03.png"); batch.AddChild(sprite1); sprite1.AddChild(sprite2); sprite1.AddChild(sprite3); 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[str]; animFrames.Add(frame); } animation = new CCAnimation(animFrames, 0.2f); action = new CCMoveBy (2, new CCPoint(200, 0)); action_back = (CCFiniteTimeAction)action.Reverse(); action_rot = new CCRotateBy (2, 360); action_s = new CCScaleBy(2, 2); action_s_back = (CCFiniteTimeAction)action_s.Reverse(); seq2 = (CCFiniteTimeAction)action_rot.Reverse(); }
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); sprite1 = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121)); sprite2 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121)); sprite3 = new CCSprite(batch.Texture, new CCRect(85 * 2, 121 * 1, 85, 121)); sprite4 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 1, 85, 121)); sprite5 = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121)); sprite6 = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 1, 85, 121)); sprite7 = new CCSprite(batch.Texture, new CCRect(85 * 2, 121 * 1, 85, 121)); sprite8 = new CCSprite(batch.Texture, new CCRect(85 * 3, 121 * 1, 85, 121)); CCFiniteTimeAction action = new CCFadeIn (2); CCFiniteTimeAction action_back = (CCFiniteTimeAction)action.Reverse(); fade = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(action, action_back))); CCFiniteTimeAction tintred = new CCTintBy (2, 0, -255, -255); CCFiniteTimeAction tintred_back = (CCFiniteTimeAction)tintred.Reverse(); red = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintred, tintred_back))); CCFiniteTimeAction tintgreen = new CCTintBy (2, -255, 0, -255); CCFiniteTimeAction tintgreen_back = (CCFiniteTimeAction)tintgreen.Reverse(); green = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintgreen, tintgreen_back))); CCFiniteTimeAction tintblue = new CCTintBy (2, -255, -255, 0); CCFiniteTimeAction tintblue_back = (CCFiniteTimeAction)tintblue.Reverse(); blue = new CCRepeatForever ((CCFiniteTimeAction)(new CCSequence(tintblue, tintblue_back))); 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); }
protected override void AddedToScene() { base.AddedToScene(); contentLayer = new CCLayer(); Window.IsUseDepthTesting = true; node = new CCNode(Layer.VisibleBoundsWorldspace.Size); node.AnchorPoint = CCPoint.AnchorMiddle; node.IgnoreAnchorPointForPosition = true; AddChild(contentLayer); contentLayer.AddChild(node); CCSize layerSize = contentLayer.VisibleBoundsWorldspace.Size; float step = layerSize.Width / 12; // small capacity. Testing resizing. // Don't use capacity=1 in your real game. It is expensive to resize the capacity batch = new CCSpriteBatchNode("Images/grossini_dance_atlas", 1); node.AddChild(batch, 0, (int)kTags.kTagSpriteBatchNode); sprites = new CCSprite[numOfSprites]; for (int i = 0; i < 5; i++) { sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 0, 121 * 1, 85, 121)); sprites[i].Position = (new CCPoint((i + 1) * step, layerSize.Height / 2)); sprites[i].VertexZ = (10 + i * 20); batch.AddChild(sprites[i], 0); } for (int i = 5; i < 11; i++) { sprites[i] = new CCSprite(batch.Texture, new CCRect(85 * 1, 121 * 0, 85, 121)); sprites[i].Position = (new CCPoint((i + 1) * step, layerSize.Height / 2)); sprites[i].VertexZ = 10 + (10 - i) * 20; batch.AddChild(sprites[i], 0); } // camera uses the center of the image as the pivoting point node.RunAction(new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0)); }
public SpriteBatchNodeAnchorPoint() { sprites = new CCSprite[numOfSprites]; pointSprites = new CCSprite[numOfSprites]; CCRotateBy rotate = new CCRotateBy(10, 360); action = new CCRepeatForever(rotate); // 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); for (int i = 0; i < numOfSprites; i++) { CCSprite sprite = new CCSprite(batch.Texture, new CCRect(85, 121 * 1, 85, 121)); batch.AddChild(sprite, i); CCSprite point = new CCSprite("Images/r1"); AddChild(point, 10); 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; sprites[i] = sprite; pointSprites[i] = point; } }
public RenderTextureZbuffer() { label = new CCLabelTtf("vertexZ = 50", "Marker Felt", 32); AddChild(label); label2 = new CCLabelTtf("vertexZ = 0", "Marker Felt", 32); AddChild(label2); label3 = new CCLabelTtf("vertexZ = -50", "Marker Felt", 32); AddChild(label3); CCSpriteFrameCache.SharedSpriteFrameCache.AddSpriteFrames("Images/bugs/circle.plist"); mgr = new CCSpriteBatchNode("Images/bugs/circle", 9); AddChild(mgr); sp1 = new CCSprite("Images/bugs/circle"); sp2 = new CCSprite("Images/bugs/circle"); sp3 = new CCSprite("Images/bugs/circle"); sp4 = new CCSprite("Images/bugs/circle"); sp5 = new CCSprite("Images/bugs/circle"); sp6 = new CCSprite("Images/bugs/circle"); sp7 = new CCSprite("Images/bugs/circle"); sp8 = new CCSprite("Images/bugs/circle"); sp9 = new CCSprite("Images/bugs/circle"); mgr.AddChild(sp1, 9); mgr.AddChild(sp2, 8); mgr.AddChild(sp3, 7); mgr.AddChild(sp4, 6); mgr.AddChild(sp5, 5); mgr.AddChild(sp6, 4); mgr.AddChild(sp7, 3); mgr.AddChild(sp8, 2); mgr.AddChild(sp9, 1); sp9.Color = CCColor3B.Yellow; }
public bool UpdateWithBatchNode(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets) { var opacity = Opacity; var color = Color; // Release old sprites RemoveAllChildren(true); scale9Image = batchnode; scale9Image.RemoveAllChildren(true); this.capInsets = capInsets; spriteFrameRotated = rotated; // If there is no given rect if (rect.Equals(CCRect.Zero)) { // Get the texture size as original CCSize textureSize = scale9Image.TextureAtlas.Texture.ContentSizeInPixels; rect = new CCRect(0, 0, textureSize.Width, textureSize.Height); } // Set the given rect's size as original size spriteRect = rect; originalSize = rect.Size; preferredSize = originalSize; capInsetsInternal = capInsets; float h = rect.Size.Height; float w = rect.Size.Width; // If there is no specified center region if (capInsetsInternal.Equals(CCRect.Zero)) { capInsetsInternal = new CCRect(w / 3, h / 3, w / 3, h / 3); } float left_w = capInsetsInternal.Origin.X; float center_w = capInsetsInternal.Size.Width; float right_w = rect.Size.Width - (left_w + center_w); float top_h = capInsetsInternal.Origin.Y; float center_h = capInsetsInternal.Size.Height; float bottom_h = rect.Size.Height - (top_h + center_h); // calculate rects // ... top row float x = 0.0f; float y = 0.0f; // top left CCRect lefttopbounds = new CCRect(x, y, left_w, top_h); // top center x += left_w; CCRect centertopbounds = new CCRect(x, y, center_w, top_h); // top right x += center_w; CCRect righttopbounds = new CCRect(x, y, right_w, top_h); // ... center row x = 0.0f; y = 0.0f; y += top_h; // center left CCRect leftcenterbounds = new CCRect(x, y, left_w, center_h); // center center x += left_w; CCRect centerbounds = new CCRect(x, y, center_w, center_h); // center right x += center_w; CCRect rightcenterbounds = new CCRect(x, y, right_w, center_h); // ... bottom row x = 0.0f; y = 0.0f; y += top_h; y += center_h; // bottom left CCRect leftbottombounds = new CCRect(x, y, left_w, bottom_h); // bottom center x += left_w; CCRect centerbottombounds = new CCRect(x, y, center_w, bottom_h); // bottom right x += center_w; CCRect rightbottombounds = new CCRect(x, y, right_w, bottom_h); if (!rotated) { CCAffineTransform t = CCAffineTransform.Identity; t = CCAffineTransform.Translate(t, rect.Origin.X, rect.Origin.Y); centerbounds = CCAffineTransform.Transform(centerbounds, t); rightbottombounds = CCAffineTransform.Transform(rightbottombounds, t); leftbottombounds = CCAffineTransform.Transform(leftbottombounds, t); righttopbounds = CCAffineTransform.Transform(righttopbounds, t); lefttopbounds = CCAffineTransform.Transform(lefttopbounds, t); rightcenterbounds = CCAffineTransform.Transform(rightcenterbounds, t); leftcenterbounds = CCAffineTransform.Transform(leftcenterbounds, t); centerbottombounds = CCAffineTransform.Transform(centerbottombounds, t); centertopbounds = CCAffineTransform.Transform(centertopbounds, t); // Centre centre = new CCSprite(scale9Image.Texture, centerbounds); scale9Image.AddChild(centre, 0, (int)Positions.Centre); // Top top = new CCSprite(scale9Image.Texture, centerbounds); scale9Image.AddChild(top, 1, (int)Positions.Top); // Bottom bottom = new CCSprite(scale9Image.Texture, centerbottombounds); scale9Image.AddChild(bottom, 1, (int)Positions.Bottom); // Left left = new CCSprite(scale9Image.Texture, leftcenterbounds); scale9Image.AddChild(left, 1, (int)Positions.Left); // Right right = new CCSprite(scale9Image.Texture, rightcenterbounds); scale9Image.AddChild(right, 1, (int)Positions.Right); // Top left topLeft = new CCSprite(scale9Image.Texture, lefttopbounds); scale9Image.AddChild(topLeft, 2, (int)Positions.TopLeft); // Top right topRight = new CCSprite(scale9Image.Texture, righttopbounds); scale9Image.AddChild(topRight, 2, (int)Positions.TopRight); // Bottom left bottomLeft = new CCSprite(scale9Image.Texture, leftbottombounds); scale9Image.AddChild(bottomLeft, 2, (int)Positions.BottomLeft); // Bottom right bottomRight = new CCSprite(scale9Image.Texture, rightbottombounds); scale9Image.AddChild(bottomRight, 2, (int)Positions.BottomRight); } else { // set up transformation of coordinates // to handle the case where the sprite is stored rotated // in the spritesheet // CCLog("rotated"); CCAffineTransform t = CCAffineTransform.Identity; CCRect rotatedcenterbounds = centerbounds; CCRect rotatedrightbottombounds = rightbottombounds; CCRect rotatedleftbottombounds = leftbottombounds; CCRect rotatedrighttopbounds = righttopbounds; CCRect rotatedlefttopbounds = lefttopbounds; CCRect rotatedrightcenterbounds = rightcenterbounds; CCRect rotatedleftcenterbounds = leftcenterbounds; CCRect rotatedcenterbottombounds = centerbottombounds; CCRect rotatedcentertopbounds = centertopbounds; t = CCAffineTransform.Translate(t, rect.Size.Height + rect.Origin.X, rect.Origin.Y); t = CCAffineTransform.Rotate(t, 1.57079633f); centerbounds = CCAffineTransform.Transform(centerbounds, t); rightbottombounds = CCAffineTransform.Transform(rightbottombounds, t); leftbottombounds = CCAffineTransform.Transform(leftbottombounds, t); righttopbounds = CCAffineTransform.Transform(righttopbounds, t); lefttopbounds = CCAffineTransform.Transform(lefttopbounds, t); rightcenterbounds = CCAffineTransform.Transform(rightcenterbounds, t); leftcenterbounds = CCAffineTransform.Transform(leftcenterbounds, t); centerbottombounds = CCAffineTransform.Transform(centerbottombounds, t); centertopbounds = CCAffineTransform.Transform(centertopbounds, t); rotatedcenterbounds.Origin = centerbounds.Origin; rotatedrightbottombounds.Origin = rightbottombounds.Origin; rotatedleftbottombounds.Origin = leftbottombounds.Origin; rotatedrighttopbounds.Origin = righttopbounds.Origin; rotatedlefttopbounds.Origin = lefttopbounds.Origin; rotatedrightcenterbounds.Origin = rightcenterbounds.Origin; rotatedleftcenterbounds.Origin = leftcenterbounds.Origin; rotatedcenterbottombounds.Origin = centerbottombounds.Origin; rotatedcentertopbounds.Origin = centertopbounds.Origin; // Centre centre = new CCSprite(scale9Image.Texture, rotatedcenterbounds, true); //centre.InitWithTexture(scale9Image.Texture, rotatedcenterbounds, true); scale9Image.AddChild(centre, 0, (int)Positions.Centre); // Top top = new CCSprite(scale9Image.Texture, rotatedcentertopbounds, true); //top.InitWithTexture(scale9Image.Texture, rotatedcentertopbounds, true); scale9Image.AddChild(top, 1, (int)Positions.Top); // Bottom bottom = new CCSprite(scale9Image.Texture, rotatedcenterbottombounds, true); //bottom.InitWithTexture(scale9Image.Texture, rotatedcenterbottombounds, true); scale9Image.AddChild(bottom, 1, (int)Positions.Bottom); // Left left = new CCSprite(scale9Image.Texture, rotatedleftcenterbounds, true); //left.InitWithTexture(scale9Image.Texture, rotatedleftcenterbounds, true); scale9Image.AddChild(left, 1, (int)Positions.Left); // Right right = new CCSprite(scale9Image.Texture, rotatedrightcenterbounds, true); //right.InitWithTexture(scale9Image.Texture, rotatedrightcenterbounds, true); scale9Image.AddChild(right, 1, (int)Positions.Right); // Top left topLeft = new CCSprite(scale9Image.Texture, rotatedlefttopbounds, true); //topLeft.InitWithTexture(scale9Image.Texture, rotatedlefttopbounds, true); scale9Image.AddChild(topLeft, 2, (int)Positions.TopLeft); // Top right topRight = new CCSprite(scale9Image.Texture, rotatedrighttopbounds, true); //topRight.InitWithTexture(scale9Image.Texture, rotatedrighttopbounds, true); scale9Image.AddChild(topRight, 2, (int)Positions.TopRight); // Bottom left bottomLeft = new CCSprite(scale9Image.Texture, rotatedleftbottombounds, true); //bottomLeft.InitWithTexture(scale9Image.Texture, rotatedleftbottombounds, true); scale9Image.AddChild(bottomLeft, 2, (int)Positions.BottomLeft); // Bottom right bottomRight = new CCSprite(scale9Image.Texture, rotatedrightbottombounds, true); //bottomRight.InitWithTexture(scale9Image.Texture, rotatedrightbottombounds, true); scale9Image.AddChild(bottomRight, 2, (int)Positions.BottomRight); } ContentSize = rect.Size; AddChild(scale9Image); if (spritesGenerated) { // Restore color and opacity Opacity = opacity; Color = color; } spritesGenerated = true; return(true); }
public CCScale9Sprite(CCSpriteBatchNode batchnode, CCRect rect, CCRect capInsets) : this(batchnode, rect, false, capInsets) { }
public CCScale9Sprite(CCSpriteBatchNode batchnode, CCRect rect, bool rotated, CCRect capInsets) { InitCCScale9Sprite(batchnode, rect, rotated, capInsets); }