private void performanceActions20(CCSprite pSprite) { Random random = new Random(); CCSize size = CCDirector.sharedDirector().getWinSize(); if (random.Next() < 0.2f) { pSprite.position = new CCPoint((random.Next() % (int)size.width), (random.Next() % (int)size.height)); } else { pSprite.position = new CCPoint(-1000, -1000); } float period = 0.5f + (random.Next() % 1000) / 500.0f; CCRotateBy rot = CCRotateBy.actionWithDuration(period, 360.0f * random.Next()); CCActionInterval rot_back = null; CCAction permanentRotation = CCRepeatForever.actionWithAction((CCActionInterval)CCSequence.actions(rot, rot_back)); pSprite.runAction(permanentRotation); float growDuration = 0.5f + (random.Next() % 1000) / 500.0f; CCActionInterval grow = CCScaleBy.actionWithDuration(growDuration, 0.5f, 0.5f); CCAction permanentScaleLoop = CCRepeatForever.actionWithAction(CCSequence.actionOneTwo(grow, grow.reverse())); pSprite.runAction(permanentScaleLoop); }
public Atlas4() { m_time = 0; // Upper Label CCLabelBMFont label = CCLabelBMFont.labelWithString("Bitmap Font Atlas", "fonts/fnt/bitmapFontTest"); addChild(label); CCSize s = CCDirector.sharedDirector().getWinSize(); label.position = new CCPoint(s.width / 2, s.height / 2); label.anchorPoint = new CCPoint(0.5f, 0.5f); CCSprite BChar = (CCSprite)label.getChildByTag(0); CCSprite FChar = (CCSprite)label.getChildByTag(7); CCSprite AChar = (CCSprite)label.getChildByTag(12); CCActionInterval rotate = CCRotateBy.actionWithDuration(2, 360); CCAction rot_4ever = CCRepeatForever.actionWithAction(rotate); CCActionInterval scale = CCScaleBy.actionWithDuration(2, 1.5f); CCFiniteTimeAction scale_back = scale.reverse(); CCFiniteTimeAction scale_seq = CCSequence.actions(scale, scale_back); CCAction scale_4ever = CCRepeatForever.actionWithAction((CCActionInterval)scale_seq); CCActionInterval jump = CCJumpBy.actionWithDuration(0.5f, new CCPoint(), 60, 1); CCAction jump_4ever = CCRepeatForever.actionWithAction(jump); CCActionInterval fade_out = CCFadeOut.actionWithDuration(1); CCActionInterval fade_in = CCFadeIn.actionWithDuration(1); CCFiniteTimeAction seq = CCSequence.actions(fade_out, fade_in); CCAction fade_4ever = CCRepeatForever.actionWithAction((CCActionInterval)seq); BChar.runAction(rot_4ever); BChar.runAction(scale_4ever); FChar.runAction(jump_4ever); AChar.runAction(fade_4ever); // Bottom Label CCLabelBMFont label2 = CCLabelBMFont.labelWithString("00.0", "fonts/fnt/bitmapFontTest"); addChild(label2, 0, (int)TagSprite.kTagBitmapAtlas2); label2.position = new CCPoint(s.width / 2.0f, 80); CCSprite lastChar = (CCSprite)label2.getChildByTag(3); lastChar.runAction((CCAction)(rot_4ever.copy())); //schedule( schedule_selector(Atlas4::step), 0.1f); base.schedule(step, 0.1f); }
public NodeToWorld() { // // This code tests that nodeToParent works OK: // - It tests different anchor Points // - It tests different children anchor points CCSprite back = CCSprite.spriteWithFile(TestResource.s_back3); addChild(back, -10); back.anchorPoint = (new CCPoint(0, 0)); CCSize backSize = back.contentSize; CCMenuItem item = CCMenuItemImage.itemFromNormalImage(TestResource.s_PlayNormal, TestResource.s_PlaySelect); CCMenu menu = CCMenu.menuWithItems(item); menu.alignItemsVertically(); menu.position = (new CCPoint(backSize.width / 2, backSize.height / 2)); back.addChild(menu); CCActionInterval rot = CCRotateBy.actionWithDuration(5, 360); CCAction fe = CCRepeatForever.actionWithAction(rot); item.runAction(fe); CCActionInterval move = CCMoveBy.actionWithDuration(3, new CCPoint(200, 0)); CCActionInterval move_back = (CCActionInterval)move.reverse(); CCFiniteTimeAction seq = CCSequence.actions(move, move_back); CCAction fe2 = CCRepeatForever.actionWithAction((CCActionInterval)seq); back.runAction(fe2); }
public TMXIsoZorder() { CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/iso-test-zorder"); addChild(map, 0, 1); CCSize s = map.contentSize; ////----UXLOG("ContentSize: %f, %f", s.width,s.height); map.position = (new CCPoint(-s.width / 2, 0)); m_tamara = CCSprite.spriteWithFile(s_pPathSister1); map.addChild(m_tamara, map.children.Count); int mapWidth = (int)(map.MapSize.width * map.TileSize.width); m_tamara.positionInPixels = new CCPoint(mapWidth / 2, 0); m_tamara.anchorPoint = new CCPoint(0.5f, 0); CCActionInterval move = CCMoveBy.actionWithDuration(10, new CCPoint(300 * 1 / CCDirector.sharedDirector().ContentScaleFactor, 250 * 1 / CCDirector.sharedDirector().ContentScaleFactor)); CCActionInterval back = (CCActionInterval)move.reverse(); CCFiniteTimeAction seq = CCSequence.actions(move, back); m_tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq)); schedule((this.repositionSprite)); }
public override void onEnter() { base.onEnter(); float x, y; CCSize size = CCDirector.sharedDirector().getWinSize(); x = size.width; y = size.height; CCSprite bg = CCSprite.spriteWithFile("Images/background3"); addChild(bg, 0, EffectAdvanceScene.kTagBackground); bg.position = new CCPoint(x / 2, y / 2); grossini = CCSprite.spriteWithFile("Images/grossinis_sister2"); bg.addChild(grossini, 1, EffectAdvanceScene.kTagSprite1); grossini.position = new CCPoint(x / 3.0f, 200); CCActionInterval sc = CCScaleBy.actionWithDuration(2, 5); CCFiniteTimeAction sc_back = sc.reverse(); grossini.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(sc, sc_back)))); tamara = CCSprite.spriteWithFile("Images/grossinis_sister1"); bg.addChild(tamara, 1, EffectAdvanceScene.kTagSprite2); tamara.position = new CCPoint(2 * x / 3.0f, 200); CCActionInterval sc2 = CCScaleBy.actionWithDuration(2, 5); CCFiniteTimeAction sc2_back = sc2.reverse(); tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)(CCSequence.actions(sc2, sc2_back)))); CCLabelTTF label = CCLabelTTF.labelWithString(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 = CCLabelTTF.labelWithString(strSubtitle, "Arial", 16); addChild(l, 101); l.position = new CCPoint(size.width / 2, size.height - 80); } CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage("Images/b1", "Images/b2", this, backCallback); CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage("Images/r1", "Images/r2", this, restartCallback); CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage("Images/f1", "Images/f2", this, nextCallback); CCMenu menu = CCMenu.menuWithItems(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 TMXIsoVertexZ() { CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/iso-test-vertexz"); addChild(map, 0, 1); CCSize s = map.contentSize; map.position = new CCPoint(-s.width / 2, 0); ////----UXLOG("ContentSize: %f, %f", s.width,s.height); // because I'm lazy, I'm reusing a tile as an sprite, but since this method uses vertexZ, you // can use any CCSprite and it will work OK. CCTMXLayer layer = map.layerNamed("Trees"); m_tamara = layer.tileAt(new CCPoint(29, 29)); CCActionInterval move = CCMoveBy.actionWithDuration(10, new CCPoint(300 * 1 / CCDirector.sharedDirector().ContentScaleFactor, 250 * 1 / CCDirector.sharedDirector().ContentScaleFactor)); CCActionInterval back = (CCActionInterval)move.reverse(); CCFiniteTimeAction seq = CCSequence.actions(move, back); m_tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq)); schedule(repositionSprite); }
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 void delay2(float dt) { CCSprite node = (CCSprite)(getChildByTag(2)); CCAction action1 = CCRotateBy.actionWithDuration(1, 360); node.runAction(action1); }
public Test5() { CCSprite sp1 = CCSprite.spriteWithFile(TestResource.s_pPathSister1); CCSprite sp2 = CCSprite.spriteWithFile(TestResource.s_pPathSister2); sp1.position = (new CCPoint(100, 160)); sp2.position = (new CCPoint(380, 160)); CCRotateBy rot = CCRotateBy.actionWithDuration(2, 360); CCActionInterval rot_back = rot.reverse() as CCActionInterval; CCAction forever = CCRepeatForever.actionWithAction( (CCActionInterval)(CCSequence.actions(rot, rot_back)) ); CCAction forever2 = (CCAction)(forever.copy()); forever.tag = (101); forever2.tag = (102); addChild(sp1, 0, CocosNodeTestStaticLibrary.kTagSprite1); addChild(sp2, 0, CocosNodeTestStaticLibrary.kTagSprite2); sp1.runAction(forever); sp2.runAction(forever2); schedule(new SEL_SCHEDULE(this.addAndRemove), 2.0f); }
public SceneTestLayer2() { m_timeCounter = 0; CCMenuItemFont item1 = CCMenuItemFont.itemFromString("replaceScene", this, onReplaceScene); CCMenuItemFont item2 = CCMenuItemFont.itemFromString("replaceScene w/transition", this, onReplaceSceneTran); CCMenuItemFont item3 = CCMenuItemFont.itemFromString("Go Back", this, onGoBack); CCMenu menu = CCMenu.menuWithItems(item1, item2, item3); menu.alignItemsVertically(); addChild(menu); CCSize s = CCDirector.sharedDirector().getWinSize(); CCSprite sprite = CCSprite.spriteWithFile(s_pPathGrossini); addChild(sprite); sprite.position = new CCPoint(s.width - 40, s.height / 2); CCActionInterval rotate = CCRotateBy.actionWithDuration(2, 360); CCAction repeat = CCRepeatForever.actionWithAction(rotate); sprite.runAction(repeat); schedule(testDealloc); }
public StressTest2() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCLayer sublayer = CCLayer.node(); CCSprite sp1 = CCSprite.spriteWithFile(TestResource.s_pPathSister1); sp1.position = (new CCPoint(80, s.height / 2)); CCActionInterval move = CCMoveBy.actionWithDuration(3, new CCPoint(350, 0)); CCActionInterval move_ease_inout3 = CCEaseInOut.actionWithAction((CCActionInterval)(move.copy()), 2.0f); CCActionInterval move_ease_inout_back3 = (CCActionInterval)move_ease_inout3.reverse(); CCFiniteTimeAction seq3 = CCSequence.actions(move_ease_inout3, move_ease_inout_back3); sp1.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq3)); sublayer.addChild(sp1, 1); CCParticleFire fire = CCParticleFire.node(); fire.Texture = (CCTextureCache.sharedTextureCache().addImage("Images/fire")); fire.position = (new CCPoint(80, s.height / 2 - 50)); CCActionInterval copy_seq3 = (CCActionInterval)(seq3.copy()); fire.runAction(CCRepeatForever.actionWithAction(copy_seq3)); sublayer.addChild(fire, 2); schedule((shouldNotLeak), 6.0f); addChild(sublayer, 0, CocosNodeTestStaticLibrary.kTagSprite1); }
public ParticleDemo() { initWithColor(ccTypes.ccc4(127, 127, 127, 255)); m_emitter = null; isTouchEnabled = true; CCSize s = CCDirector.sharedDirector().getWinSize(); CCLabelTTF label = CCLabelTTF.labelWithString(title(), "Arial", 28); addChild(label, 100, 1000); label.position = new CCPoint(s.width / 2, s.height - 50); CCLabelTTF tapScreen = CCLabelTTF.labelWithString("(Tap the Screen)", "Arial", 20); tapScreen.position = new CCPoint(s.width / 2, s.height - 80); addChild(tapScreen, 100); CCMenuItemImage item1 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathB1, TestResource.s_pPathB2, this, new SEL_MenuHandler(backCallback)); CCMenuItemImage item2 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathR1, TestResource.s_pPathR2, this, new SEL_MenuHandler(restartCallback)); CCMenuItemImage item3 = CCMenuItemImage.itemFromNormalImage(TestResource.s_pPathF1, TestResource.s_pPathF2, this, new SEL_MenuHandler(nextCallback)); CCMenuItemToggle item4 = CCMenuItemToggle.itemWithTarget(this, new SEL_MenuHandler(toggleCallback), CCMenuItemFont.itemFromString("Free Movement"), CCMenuItemFont.itemFromString("Relative Movement"), CCMenuItemFont.itemFromString("Grouped Movement")); CCMenu menu = CCMenu.menuWithItems(item1, item2, item3, item4); menu.position = new CCPoint(0, 0); item1.position = new CCPoint(s.width / 2 - 100, 30); item2.position = new CCPoint(s.width / 2, 30); item3.position = new CCPoint(s.width / 2 + 100, 30); item4.position = new CCPoint(0, 100); item4.anchorPoint = new CCPoint(0, 0); addChild(menu, 100); CCLabelAtlas labelAtlas = CCLabelAtlas.labelWithString("0000", "fonts/fnt/images/fps_images", 16, 24, '.'); addChild(labelAtlas, 100, ParticleTestScene.kTagLabelAtlas); labelAtlas.position = new CCPoint(s.width - 66, 50); // moving background m_background = CCSprite.spriteWithFile(TestResource.s_back3); addChild(m_background, 5); m_background.position = new CCPoint(s.width / 2 - 120, s.height - 240); CCActionInterval move = CCMoveBy.actionWithDuration(4, new CCPoint(300, 0)); CCFiniteTimeAction move_back = move.reverse(); CCFiniteTimeAction seq = CCSequence.actions(move, move_back); m_background.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq)); schedule(new SEL_SCHEDULE(step)); }
public IntervalLayer() { m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f; CCSize s = CCDirector.sharedDirector().getWinSize(); // sun //CCParticleSystem sun = CCParticleSun.node(); //sun.Texture = CCTextureCache.sharedTextureCache().addImage("Images/fire"); //sun.position = (new CCPoint(s.width - 32, s.height - 32)); ////sun.setTotalParticles(130); //sun.Life = (0.6f); //this.addChild(sun); // timers m_label0 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4"); m_label1 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4"); m_label2 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4"); m_label3 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4"); m_label4 = CCLabelBMFont.labelWithString("0", "fonts/fnt/bitmapFontTest4"); base.scheduleUpdate(); schedule(step1); schedule(step2, 0); schedule(step3, 1.0f); schedule(step4, 2.0f); 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 = CCSprite.spriteWithFile(s_pPathGrossini); sprite.position = new CCPoint(40, 50); CCJumpBy jump = CCJumpBy.actionWithDuration(3, new CCPoint(s.width - 80, 0), 50, 4); addChild(sprite); sprite.runAction(CCRepeatForever.actionWithAction( (CCActionInterval)(CCSequence.actions(jump, jump.reverse())) ) ); // pause button CCMenuItem item1 = CCMenuItemFont.itemFromString("Pause", this, onPause); CCMenu menu = CCMenu.menuWithItems(item1); menu.position = new CCPoint(s.width / 2, s.height - 50); addChild(menu); }
public TMXReadWriteTest() { m_gid = 0; CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/orthogonal-test2"); addChild(map, 0, TileMapTestScene.kTagTileMap); CCSize s = map.contentSize; ////----UXLOG("ContentSize: %f, %f", s.width,s.height); CCTMXLayer layer = map.layerNamed("Layer 0"); layer.Texture.setAntiAliasTexParameters(); map.scale = 1; CCSprite tile0 = layer.tileAt(new CCPoint(1, 63)); CCSprite tile1 = layer.tileAt(new CCPoint(2, 63)); CCSprite tile2 = layer.tileAt(new CCPoint(3, 62));//ccp(1,62)); CCSprite tile3 = layer.tileAt(new CCPoint(2, 62)); tile0.anchorPoint = new CCPoint(0.5f, 0.5f); tile1.anchorPoint = new CCPoint(0.5f, 0.5f); tile2.anchorPoint = new CCPoint(0.5f, 0.5f); tile3.anchorPoint = new CCPoint(0.5f, 0.5f); CCActionInterval move = CCMoveBy.actionWithDuration(0.5f, new CCPoint(0, 160)); CCActionInterval rotate = CCRotateBy.actionWithDuration(2, 360); CCActionInterval scale = CCScaleBy.actionWithDuration(2, 5); CCActionInterval opacity = CCFadeOut.actionWithDuration(2); CCActionInterval fadein = CCFadeIn.actionWithDuration(2); CCActionInterval scaleback = CCScaleTo.actionWithDuration(1, 1); CCActionInstant finish = CCCallFuncN.actionWithTarget(this, removeSprite); CCFiniteTimeAction seq0 = CCSequence.actions(move, rotate, scale, opacity, fadein, scaleback, finish); CCActionInterval seq1 = (CCActionInterval)(seq0.copy()); CCActionInterval seq2 = (CCActionInterval)(seq0.copy()); CCActionInterval seq3 = (CCActionInterval)(seq0.copy()); tile0.runAction(seq0); tile1.runAction(seq1); tile2.runAction(seq2); tile3.runAction(seq3); m_gid = layer.tileGIDAt(new CCPoint(0, 63)); ////----UXLOG("Tile GID at:(0,63) is: %d", m_gid); schedule(updateCol, 2.0f); schedule(repaintWithGID, 2.0f); schedule(removeTiles, 1.0f); ////----UXLOG("++++atlas quantity: %d", layer->textureAtlas()->getTotalQuads()); ////----UXLOG("++++children: %d", layer->getChildren()->count() ); m_gid2 = 0; }
public SpriteColorOpacity() { CCSprite sprite1 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 0, 121 * 1, 85, 121)); CCSprite sprite2 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 1, 85, 121)); CCSprite sprite3 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 2, 121 * 1, 85, 121)); CCSprite sprite4 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 3, 121 * 1, 85, 121)); CCSprite sprite5 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 0, 121 * 1, 85, 121)); CCSprite sprite6 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 1, 85, 121)); CCSprite sprite7 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(85 * 2, 121 * 1, 85, 121)); CCSprite sprite8 = CCSprite.spriteWithFile("Images/grossini_dance_atlas", 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 addChild(sprite1, 0, (int)kTagSprite.kTagSprite1); addChild(sprite2, 0, (int)kTagSprite.kTagSprite2); addChild(sprite3, 0, (int)kTagSprite.kTagSprite3); addChild(sprite4, 0, (int)kTagSprite.kTagSprite4); addChild(sprite5, 0, (int)kTagSprite.kTagSprite5); addChild(sprite6, 0, (int)kTagSprite.kTagSprite6); addChild(sprite7, 0, (int)kTagSprite.kTagSprite7); addChild(sprite8, 0, (int)kTagSprite.kTagSprite8); schedule(removeAndAddSprite, 2); }
public override void onEnter() { base.onEnter(); float x, y; CCSize size = CCDirector.sharedDirector().getWinSize(); x = size.width; y = size.height; CCSprite sprite = CCSprite.spriteWithFile(s_pPathGrossini); CCSprite spriteSister1 = CCSprite.spriteWithFile(s_pPathSister1); CCSprite spriteSister2 = CCSprite.spriteWithFile(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 = CCRotateBy.actionWithDuration(16, -3600); addChild(sprite); addChild(spriteSister1); addChild(spriteSister2); sprite.runAction(rot); CCActionInterval jump1 = CCJumpBy.actionWithDuration(4, new CCPoint(-400, 0), 100, 4); CCActionInterval jump2 = (CCActionInterval)jump1.reverse(); CCActionInterval rot1 = CCRotateBy.actionWithDuration(4, 360 * 2); CCActionInterval rot2 = (CCActionInterval)rot1.reverse(); spriteSister1.runAction(CCRepeat.actionWithAction(CCSequence.actions(jump2, jump1), 5)); spriteSister2.runAction(CCRepeat.actionWithAction(CCSequence.actions((CCFiniteTimeAction)(jump1.copy()), (CCFiniteTimeAction)(jump2.copy())), 5)); spriteSister1.runAction(CCRepeat.actionWithAction(CCSequence.actions(rot1, rot2), 5)); spriteSister2.runAction(CCRepeat.actionWithAction(CCSequence.actions((CCFiniteTimeAction)(rot2.copy()), (CCFiniteTimeAction)(rot1.copy())), 5)); }
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 override void onEnter() { base.onEnter(); CCSprite child = CCSprite.spriteWithFile(s_pPathGrossini); child.position = (new CCPoint(200, 200)); addChild(child, 1); //Sum of all action's duration is 1.5 second. child.runAction(CCRotateBy.actionWithDuration(1.5f, 90)); child.runAction(CCSequence.actions( CCDelayTime.actionWithDuration(1.4f), CCFadeOut.actionWithDuration(1.1f)) ); //After 1.5 second, self will be removed. runAction(CCSequence.actions( CCDelayTime.actionWithDuration(1.4f), CCCallFunc.actionWithTarget(this, (removeThis))) ); }
public override void onEnter() { base.onEnter(); CCSize s = CCDirector.sharedDirector().getWinSize(); CCLabelTTF l = CCLabelTTF.labelWithString("Grossini only rotate/scale in 3 seconds", "Arial", 16); addChild(l); l.position = (new CCPoint(s.width / 2, 245)); CCSprite pGrossini = CCSprite.spriteWithFile(s_pPathGrossini); addChild(pGrossini, 0, (int)KTag.kTagGrossini); pGrossini.position = new CCPoint(s.width / 2, s.height / 2); pGrossini.runAction(CCScaleBy.actionWithDuration(2, 2)); CCActionManager.sharedManager().pauseTarget(pGrossini); pGrossini.runAction(CCRotateBy.actionWithDuration(2, 360)); this.schedule(resumeGrossini, 3.0f); }
public override void onEnter() { base.onEnter(); CCSprite grossini = CCSprite.spriteWithFile(s_pPathGrossini); addChild(grossini, 0, 2); grossini.position = (new CCPoint(200, 200)); grossini.runAction(CCSequence.actions( CCMoveBy.actionWithDuration(1, new CCPoint(150, 0)), CCCallFuncN.actionWithTarget(this, bugMe)) ); }
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 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 SpriteAnimationSplit() { CCSize s = CCDirector.sharedDirector().getWinSize(); CCTexture2D texture = CCTextureCache.sharedTextureCache().addImage("animations/images/dragon_animation"); // manually add frames to the frame cache CCSpriteFrame frame0 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 0, 132 * 0, 132, 132)); CCSpriteFrame frame1 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 1, 132 * 0, 132, 132)); CCSpriteFrame frame2 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 2, 132 * 0, 132, 132)); CCSpriteFrame frame3 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 3, 132 * 0, 132, 132)); CCSpriteFrame frame4 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 0, 132 * 1, 132, 132)); CCSpriteFrame frame5 = CCSpriteFrame.frameWithTexture(texture, new CCRect(132 * 1, 132 * 1, 132, 132)); // // Animation using Sprite BatchNode // CCSprite sprite = CCSprite.spriteWithSpriteFrame(frame0); sprite.position = (new CCPoint(s.width / 2 - 80, s.height / 2)); addChild(sprite); List <CCSpriteFrame> 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.animationWithFrames(animFrames, 0.2f); CCAnimate animate = CCAnimate.actionWithAnimation(animation, false); CCActionInterval seq = (CCActionInterval)(CCSequence.actions(animate, CCFlipX.actionWithFlipX(true), (CCFiniteTimeAction)animate.copy(), CCFlipX.actionWithFlipX(false) )); sprite.runAction(CCRepeatForever.actionWithAction(seq)); //animFrames->release(); // win32 : memory leak 2010-0415 }
public override void ccTouchesEnded(List <CCTouch> touches, CCEvent event_) { actor.actack(); base.ccTouchesEnded(touches, event_); CCTouch touch = touches.FirstOrDefault(); CCPoint location = touch.locationInView(touch.view()); location = CCDirector.sharedDirector().convertToGL(location); //set up initial location of projectile CCSize winSize = CCDirector.sharedDirector().getWinSize(); CCSprite projectile = CCSprite.spriteWithFile(@"sprites/hamberger"); projectile.position = new CCPoint(actor.position.x, actor.position.y + 20); this.addChild(projectile); float offX = location.x - projectile.position.x; float offY = location.y - projectile.position.y; offY -= 30; float realX = winSize.width + projectile.contentSize.width / 2; float ratio = offY / offX; float realY = realX * ratio + projectile.position.y; realY -= 30; CCPoint realDest = new CCPoint(realX, realY); //Determine the length of how far we're shooting float offRealX = realX - projectile.position.x; float offRealY = realY - projectile.position.y; offRealY -= 30; float length = (float)Math.Sqrt(offRealX * offRealX + offRealY * offRealY); float velocity = 480 / 1;//480pixls/lsec float realMoveDuration = length / velocity; //Move projectile to actual endpoint projectile.runAction(CCSequence.actions(CCMoveTo.actionWithDuration(realMoveDuration, realDest), CCCallFuncN.actionWithTarget(this, spriteMoveFinished))); }
public void addNewSpriteWithCoords(CCPoint p) { int idx = (int)(ccMacros.CCRANDOM_0_1() * 1400.0f / 100.0f); int x = (idx % 5) * 85; int y = (idx / 5) * 121; CCSprite sprite = CCSprite.spriteWithFile("Images/grossini_dance_atlas", new CCRect(x, y, 85, 121)); addChild(sprite); sprite.position = p; CCActionInterval action; float random = ccMacros.CCRANDOM_0_1(); 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); } object obj = action.reverse(); CCActionInterval action_back = (CCActionInterval)action.reverse(); CCActionInterval seq = (CCActionInterval)(CCSequence.actions(action, action_back)); sprite.runAction(CCRepeatForever.actionWithAction(seq)); }
public MainLayer() { base.isTouchEnabled = true; CCSprite sprite = CCSprite.spriteWithFile(ClickAndMoveTest.s_pPathGrossini); CCLayer layer = CCLayerColor.layerWithColor(new ccColor4B(255, 255, 0, 255)); addChild(layer, -1); addChild(sprite, 0, ClickAndMoveTest.kTagSprite); sprite.position = new CCPoint(20, 150); sprite.runAction(CCJumpTo.actionWithDuration(4, new CCPoint(300, 48), 100, 4)); layer.runAction(CCRepeatForever.actionWithAction( (CCActionInterval)(CCSequence.actions( CCFadeIn.actionWithDuration(1), CCFadeOut.actionWithDuration(1))) )); }
public SceneTestLayer3() { base.isTouchEnabled = true; CCLabelTTF label = CCLabelTTF.labelWithString("Touch to popScene", "Arial", 28); addChild(label); CCSize s = CCDirector.sharedDirector().getWinSize(); label.position = (new CCPoint(s.width / 2, s.height / 2)); CCSprite sprite = CCSprite.spriteWithFile(s_pPathGrossini); addChild(sprite); sprite.position = (new CCPoint(s.width - 40, s.height / 2)); CCActionInterval rotate = CCRotateBy.actionWithDuration(2, 360); CCAction repeat = CCRepeatForever.actionWithAction(rotate); sprite.runAction(repeat); //schedule(); }
public ConvertToNode() { this.isTouchEnabled = true; CCSize s = CCDirector.sharedDirector().getWinSize(); CCRotateBy rotate = CCRotateBy.actionWithDuration(10, 360); CCRepeatForever action = CCRepeatForever.actionWithAction(rotate); for (int i = 0; i < 3; i++) { CCSprite sprite = CCSprite.spriteWithFile("Images/grossini"); 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, 10, 100 + i); 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); CCRepeatForever copy = (CCRepeatForever)action.copy(); sprite.runAction(copy); addChild(sprite, i); } }