public Atlas4() { m_time = 0; // Upper Label CCLabelBMFont label = CCLabelBMFont.labelWithString("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt"); 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(1); 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); //CCActionInterval scale_back = scale.reverse(); CCActionInterval scale_back = null; CCFiniteTimeAction scale_seq = CCSequence.actions(scale, scale_back, null); 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, null); 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/bitmapFontTest.fnt"); 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); }
private void performanceActions(CCSprite pSprite) { Random random = new Random(); CCSize size = CCDirector.sharedDirector().getWinSize(); 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 = 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((CCActionInterval)CCSequence.actionOneTwo(grow, grow.reverse())); pSprite.runAction(permanentScaleLoop); }
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 TMXOrthoZorder() { CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/orthogonal-test-zorder"); base.addChild(map, 0, kTagTileMap); CCSize s = map.contentSize; ////----UXLOG("ContentSize: %f, %f", s.width,s.height); m_tamara = CCSprite.spriteWithFile(TestResource.s_pPathSister1); map.addChild(m_tamara, map.children.Count); m_tamara.anchorPoint = new CCPoint(0.5f, 0); CCActionInterval move = CCMoveBy.actionWithDuration(10, CCPointExtension.ccpMult(new CCPoint(400, 450), 1 / ccMacros.CC_CONTENT_SCALE_FACTOR())); CCFiniteTimeAction back = move.reverse(); CCFiniteTimeAction seq = CCSequence.actions(move, back); m_tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq)); schedule((this.repositionSprite)); }
public TMXOrthoVertexZ() { CCTMXTiledMap map = CCTMXTiledMap.tiledMapWithTMXFile("TileMaps/orthogonal-test-vertexz"); addChild(map, 0, TileMapTestScene.kTagTileMap); CCSize s = map.contentSize; ////----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(0, 11)); Debug.WriteLine("{0} vertexZ: {1}", m_tamara, m_tamara.vertexZ); CCActionInterval move = CCMoveBy.actionWithDuration(10, CCPointExtension.ccpMult(new CCPoint(400, 450), 1 / CCDirector.sharedDirector().ContentScaleFactor)); CCFiniteTimeAction back = move.reverse(); CCFiniteTimeAction seq = CCSequence.actions(move, back); m_tamara.runAction(CCRepeatForever.actionWithAction((CCActionInterval)seq)); schedule(repositionSprite); }
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 MoveLayer() { base.isTouchEnabled = true;//开启触屏事件 CCDirector.sharedDirector().deviceOrientation = ccDeviceOrientation.kCCDeviceOrientationPortraitUpsideDown;//设置朝向,竖屏 #region Sprite跑动动画 CCSize s = CCDirector.sharedDirector().getWinSize(); // 创建批处理节点,读取plist文件 CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("plist/images/wolf_move");//批处理节点贴图 addChild(batch, 0, 1); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("plist/wolf_move");//读取plsit文件 //起始精灵 sprite1 = CCSprite.spriteWithSpriteFrameName("wolf_move1.png"); sprite1.position = (new CCPoint(s.width / 3, s.height / 2)); batch.addChild(sprite1); // 创建逐帧数组 List<CCSpriteFrame> animFrames = new List<CCSpriteFrame>(); string str = ""; for (int i = 2; i < 8; i++) { string temp = ""; temp = i.ToString(); str = string.Format("wolf_move{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str); animFrames.Add(frame); } //动画Animate CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f);//Animation动画信息 sprite1.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));//执行动画 #endregion //直线匀速 //sprite1.runAction(CCMoveTo.actionWithDuration(5.0f, new CCPoint(0, 0)));//移动到坐标(0,0)位置 #region CCEaseInOut //CCActionInterval move = CCMoveBy.actionWithDuration(3, new CCPoint(280, 0));//CCMoveBy是相当位移动作 //CCActionInterval move_ease_inout = CCEaseInOut.actionWithAction(move);//ease缓冲 //sprite1.runAction(move_ease_inout); #endregion }
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)); }
/// <summary> /// ��һ����ӵ��� /// �ڶ�������box-2d�������潫������Ϊ��̬������ӵ����������� /// </summary> private void AddGround() { ground = CCSprite.spriteWithFile("imgs/ground/ground"); ground.position = new CCPoint(ground.contentSize.width / 2, ground.contentSize.height / 2); b2BodyDef groundBodyDef = new b2BodyDef(); groundBodyDef.position = new b2Vec2(ground.contentSize.width / PTM_RATIO / 2, ground.contentSize.height / PTM_RATIO / 2); groundBodyDef.userData = ground; // ��������Ӱ�죬�����˶� groundBodyDef.type = b2BodyType.b2_staticBody; // ����ground���˶���ʹ���ٶ���bird�ķ����ٶ�һ�� var action1 = CCMoveTo.actionWithDuration(ground.contentSize.width / (4 * PTM_RATIO * flySpeed), new CCPoint(ground.contentSize.width / 4, ground.position.y)); var action2 = CCMoveTo.actionWithDuration(0, new CCPoint(ground.contentSize.width / 2, ground.position.y)); var action = CCSequence.actionOneTwo(action1, action2); var repeatAction = CCRepeatForever.actionWithAction(action); repeatAction.tag = 0; ground.runAction(repeatAction); b2Body groundBody = world.CreateBody(groundBodyDef); b2PolygonShape groundBox = new b2PolygonShape(); b2FixtureDef boxShapeDef = new b2FixtureDef(); boxShapeDef.shape = groundBox; groundBox.SetAsBox(ground.contentSize.width / PTM_RATIO / 2, ground.contentSize.height / PTM_RATIO / 2); groundBody.CreateFixture(boxShapeDef); this.addChild(ground); }
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 override void ccTouchesEnded(List<CCTouch> touches, CCEvent event_) { if (nextProjectile != null) return; 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(@"images/Projectile"); nextProjectile = CCSprite.spriteWithFile(@"images/Projectile2"); nextProjectile.position = new CCPoint(20, winSize.height / 2); //Determine offset of location to projectile float offX = location.x - nextProjectile.position.x; float offY = location.y - nextProjectile.position.y; //Bail out if we are shooting or backwards if (offX <= 0) { return; } //Determine where we wish to shoot the projectile to float realX = winSize.width + nextProjectile.contentSize.width / 2; float ratio = offY / offX; float realY = realX * ratio + nextProjectile.position.y; CCPoint realDest = new CCPoint(realX, realY); //Determine the length of how far we're shooting float offRealX = realX - nextProjectile.position.x; float offRealY = realY - nextProjectile.position.y; float length = (float)Math.Sqrt(offRealX * offRealX + offRealY * offRealY); float velocity = 480 / 1;//480pixls/lsec float realMoveDuration = length / velocity; //Determine angle to face float angleRadians = (float)Math.Atan(offRealY / offRealX); float angleDegrees = MathHelper.ToDegrees(angleRadians); float cocosAngle = -1 * angleDegrees; float rotateSpeed = (float)(0.5 / Math.PI);//Would take 0.5 seconds to rotate 0.5 radians ,or half a circle float rotateDuration = Math.Abs(angleRadians * rotateSpeed); player.runAction(CCSequence.actions(CCRotateTo.actionWithDuration(rotateDuration, cocosAngle), CCCallFunc.actionWithTarget(this, finishShoot))); //Move projectile to actual endpoint nextProjectile.runAction(CCSequence.actions(CCMoveTo.actionWithDuration(realMoveDuration, realDest), CCCallFuncN.actionWithTarget(this, spriteMoveFinished))); nextProjectile.tag = 2; }
/// <summary> /// ���ɵ��� /// </summary> private void addTarget() { Random random = new Random(); var screenWidth = CCDirector.sharedDirector().getWinSize().width; var screenHeight = CCDirector.sharedDirector().getWinSize().height; //string number = random.Next(1, 15).ToString("00"); //if (int.Parse(number) / 2 == Convert.ToDouble(number) / 2) //{ // target = CCSprite.spriteWithFile(@"cars/sonice_cars_" + number); //} //else //{ // target = CCSprite.spriteWithFile(@"cars/lights_" + number); //} Monster target = null; //if (random.Next() % 2 == 0) //{ // target = WeakAndFastMonster.monster(); //} //else //{ // target = StrongAndSlowMonster.monster(); //} target = level.GetMonster(); var minY = target.contentSize.height / 2; var maxY = screenHeight - target.contentSize.height / 2; float rangeY = maxY - minY; float actualY = (random.Next() % rangeY) + minY; //create the target slightly off-screen along the right edge; //and along a random position along the Y axis as calculated above target.position = new CCPoint(screenWidth + screenWidth / 2, actualY); // target.tag = 1; _targets.Add(target); this.addChild(target); //Determine speed of the target //float minDuration = 4.0f; //float maxDuration = 7.0f; float minDuration = target.minMoveDuration; float maxDuration = target.maxMoveDuration; float rangeDuration = maxDuration - minDuration; float actualDuration = random.Next() % rangeDuration + minDuration; //Create the actions var actionMove = CCMoveTo.actionWithDuration(actualDuration, new CCPoint(-target.contentSize.width / 2, actualY)); var actionMoveDone = CCCallFuncN.actionWithTarget(this, spriteMoveFinished); target.runAction(CCSequence.actions(actionMove, actionMoveDone)); }
public AnimationCache() { CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini"); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_gray"); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("animations/grossini_blue"); // // create animation "dance" // List<CCSpriteFrame> animFrames = new List<CCSpriteFrame>(15); string str = ""; for (int i = 1; i < 15; i++) { string temp = ""; if (i<10) { temp = "0" + i; } else { temp = i.ToString(); } str = string.Format("grossini_dance_{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str); animFrames.Add(frame); } CCAnimation animation = CCAnimation.animationWithFrames(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance"); // // create animation "dance gray" // animFrames.Clear(); for (int i = 1; i < 15; i++) { string temp = ""; if (i < 10) { temp = "0" + i; } else { temp = i.ToString(); } str = String.Format("grossini_dance_gray_{0}.png", temp); CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str); animFrames.Add(frame); } animation = CCAnimation.animationWithFrames(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_gray"); // // create animation "dance blue" // animFrames.Clear(); for (int i = 1; i < 4; i++) { str = String.Format("grossini_blue_0{0}.png", i); CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache().spriteFrameByName(str); animFrames.Add(frame); } animation = CCAnimation.animationWithFrames(animFrames, 0.2f); // Add an animation to the Cache CCAnimationCache.sharedAnimationCache().addAnimation(animation, "dance_blue"); CCAnimationCache animCache = CCAnimationCache.sharedAnimationCache(); CCAnimation normal = animCache.animationByName("dance"); CCAnimation dance_grey = animCache.animationByName("dance_gray"); CCAnimation dance_blue = animCache.animationByName("dance_blue"); CCAnimate animN = CCAnimate.actionWithAnimation(normal); CCAnimate animG = CCAnimate.actionWithAnimation(dance_grey); CCAnimate animB = CCAnimate.actionWithAnimation(dance_blue); CCFiniteTimeAction seq = CCSequence.actions(animN, animG, animB); // create an sprite without texture CCSprite grossini = new CCSprite(); grossini.init(); CCSize winSize = CCDirector.sharedDirector().getWinSize(); grossini.position = (new CCPoint(winSize.width / 2, winSize.height / 2)); addChild(grossini); // run the animation grossini.runAction(seq); }