private void ShowPicture() { CCSprite sprite = CCSprite.spriteWithTexture(m_Picture); sprite.position = new CCPoint(240, 590); addChild(sprite, 0); }
public override void updateQuantityOfNodes() { CCSize s = CCDirector.sharedDirector().getWinSize(); Random random = new Random(); // increase nodes if (currentQuantityOfNodes < quantityOfNodes) { for (int i = 0; i < (quantityOfNodes - currentQuantityOfNodes); i++) { CCSprite sprite = CCSprite.spriteWithTexture(batchNode.Texture, new CCRect(0, 0, 32, 32)); batchNode.addChild(sprite); sprite.position = new CCPoint(random.Next() * s.width, random.Next() * s.height); } } // decrease nodes else if (currentQuantityOfNodes > quantityOfNodes) { for (int i = 0; i < (currentQuantityOfNodes - quantityOfNodes); i++) { int index = currentQuantityOfNodes - i - 1; batchNode.removeChildAtIndex(index, true); } } currentQuantityOfNodes = quantityOfNodes; }
private void AddLine() { CCSprite spriteline = CCSprite.spriteWithTexture(Media.PictureManager.GetCCTexture2DWithFile("image/Line")); spriteline.position = new CCPoint(DisplaySize.width / 2, m_y); addChild(spriteline); }
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); }
/// <summary> /// 背景初始化 /// </summary> private void BackGroundInit(CCSize p_Size) { CCTexture2D backgroud = Media.PictureManager.GetCCTexture2DWithFile("image/BackGround"); CCSprite pSprite = CCSprite.spriteWithTexture(backgroud); // position the sprite on the center of the screen pSprite.position = new CCPoint(p_Size.width / 2, p_Size.height / 2); // add the sprite as a child to this layer this.addChild(pSprite, 0); }
public override void update(float dt) { //srandom(0); // 15 percent int totalToAdd = (int)(currentQuantityOfNodes * 0.15f); if (totalToAdd > 0) { List <CCSprite> sprites = new List <CCSprite>(); // Don't include the sprite creation time as part of the profiling for (int i = 0; i < totalToAdd; i++) { CCSprite pSprite = CCSprite.spriteWithTexture(batchNode.Texture, new CCRect(0, 0, 32, 32)); sprites.Add(pSprite); } // add them with random Z (very important!) for (int i = 0; i < totalToAdd; i++) { batchNode.addChild((CCNode)(sprites[i]), (int)(ccMacros.CCRANDOM_MINUS1_1() * 50), PerformanceNodeChildrenTest.kTagBase + i); } // [batchNode sortAllChildren]; // reorder them //#if CC_ENABLE_PROFILERS // CCProfilingBeginTimingBlock(_profilingTimer); //#endif for (int i = 0; i < totalToAdd; i++) { CCNode pNode = (CCNode)(batchNode.children[i]); batchNode.reorderChild(pNode, (int)(ccMacros.CCRANDOM_MINUS1_1() * 50)); } //#if CC_ENABLE_PROFILERS // CCProfilingEndTimingBlock(_profilingTimer); //#endif // remove them for (int i = 0; i < totalToAdd; i++) { batchNode.removeChildByTag(PerformanceNodeChildrenTest.kTagBase + i, true); } } }
public void addNewSprite() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCPoint p = new CCPoint((float)(rand.NextDouble() * s.width), (float)(rand.NextDouble() * s.height)); int idx = (int)(rand.NextDouble() * 1400 / 100); int x = (idx % 5) * 85; int y = (idx / 5) * 121; CCNode node = getChildByTag((int)kTags.kTagSpriteBatchNode); CCSprite sprite = CCSprite.spriteWithTexture(m_texture1, new CCRect(x, y, 85, 121)); node.addChild(sprite); sprite.position = (new CCPoint(p.x, p.y)); CCActionInterval action; float random = (float)rand.NextDouble(); if (random < 0.20) { action = CCScaleBy.actionWithDuration(3, 2); } else if (random < 0.40) { action = CCRotateBy.actionWithDuration(3, 360); } else if (random < 0.60) { action = CCBlink.actionWithDuration(1, 3); } else if (random < 0.8) { action = CCTintBy.actionWithDuration(2, 0, -255, -255); } else { action = CCFadeOut.actionWithDuration(2); } CCActionInterval action_back = (CCActionInterval)action.reverse(); CCActionInterval seq = (CCActionInterval)(CCSequence.actions(action, action_back)); sprite.runAction(CCRepeatForever.actionWithAction(seq)); }
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)); }
/// <summary> /// show word /// </summary> /// <param name="p_Word">word object</param> private void LoadWord(Word p_Word) { m_y -= 10; //Picture CCTexture2D text2d = Media.PictureManager.GetCCTexture2D(p_Word); CCSprite spritepic = CCSprite.spriteWithTexture(text2d); if (PictureWidth < text2d.ContentSizeInPixels.width) { spritepic.scaleX = PictureWidth / text2d.ContentSizeInPixels.width; } if (PictureHeight < text2d.ContentSizeInPixels.height) { spritepic.scaleY = PictureHeight / text2d.ContentSizeInPixels.height; } spritepic.contentSize.width = PictureWidth; spritepic.contentSize.height = PictureHeight; //word name CCLabelTTF chineseText = CCLabelTTF.labelWithString(p_Word.ChineseName, "ChineseContent", 28); CCMenuItemLabel chineseLabel = CCMenuItemLabel.itemWithLabel(chineseText); CCLabelTTF englishText = CCLabelTTF.labelWithString(p_Word.EnglishName, "EnglishContent", 28); CCMenuItemLabel englishLabel = CCMenuItemLabel.itemWithLabel(englishText); //del button CCLabelTTF delText = CCLabelTTF.labelWithString("删除", "ChineseContent", 28); CCMenuItemLabel delbutton = CCMenuItemLabel.itemWithLabel(delText, this, this.DeleteClick); delbutton.userData = p_Word; CCMenu menu = CCMenu.menuWithItems(delbutton); spritepic.position = new CCPoint(80, m_y - spritepic.contentSize.height / 2); chineseLabel.position = new CCPoint(250, m_y - 40); chineseLabel.Color = new ccColor3B(Color.Black); englishLabel.position = new CCPoint(250, m_y - 80); englishLabel.Color = new ccColor3B(Color.Black); menu.position = new CCPoint(430, m_y - 60); delbutton.Color = new ccColor3B(Color.Black); addChild(spritepic); addChild(chineseLabel); addChild(englishLabel); addChild(menu); m_y -= PictureHeight; m_y -= 10; }
public void addNewSpriteWithCoords(CCPoint p) { CCSpriteBatchNode BatchNode = (CCSpriteBatchNode)getChildByTag((int)kTags.kTagSpriteBatchNode); int idx = (int)(rand.NextDouble() * 1400 / 100); int x = (idx % 5) * 85; int y = (idx / 5) * 121; CCSprite sprite = CCSprite.spriteWithTexture(BatchNode.Texture, new CCRect(x, y, 85, 121)); BatchNode.addChild(sprite); sprite.position = (new CCPoint(p.x, p.y)); CCActionInterval action = null; float random = (float)rand.NextDouble(); if (random < 0.20) { action = CCScaleBy.actionWithDuration(3, 2); } else if (random < 0.40) { action = CCRotateBy.actionWithDuration(3, 360); } else if (random < 0.60) { action = CCBlink.actionWithDuration(1, 3); } else if (random < 0.8) { action = CCTintBy.actionWithDuration(2, 0, -255, -255); } else { action = CCFadeOut.actionWithDuration(2); } CCActionInterval action_back = (CCActionInterval)action.reverse(); CCActionInterval seq = (CCActionInterval)(CCSequence.actions(action, action_back)); sprite.runAction(CCRepeatForever.actionWithAction(seq)); }
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 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 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 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); }