public void runing(CCLayer cclayer) { #region Sprite跑动动画 CCSize s = CCDirector.sharedDirector().getWinSize(); // 创建批处理节点,读取plist文件 CCSpriteBatchNode batch = CCSpriteBatchNode.batchNodeWithFile("plist/images/wolf_move");//批处理节点贴图 cclayer.addChild(batch, 0, 1); CCSpriteFrameCache.sharedSpriteFrameCache().addSpriteFramesWithFile("plist/wolf_move");//读取plsit文件 //起始精灵 this.initWithSpriteFrameName("wolf_move1.png"); this.position = (new CCPoint(s.width / 3, s.height / 2)); batch.addChild(this); // 创建逐帧数组 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动画信息 this.runAction(CCRepeatForever.actionWithAction(CCAnimate.actionWithAnimation(animation, false)));//执行动画 #endregion }
public Bomb(CCLayer layer) { Random rnd = new Random(); float posionX = 100 * (float)rnd.Next(1, 4);//Gold起始位置X坐标值 this.initWithFile("img/Wolf/Others/bomb"); this.position = new CCPoint(posionX, 850);//Gold起始位置 layer.addChild(this); this.runAction(CCMoveTo.actionWithDuration(5.0f, new CCPoint(posionX, -50)));//运动,垂直向下运动 }
public override void onEnter() { base.onEnter(); ccColor4B _ccColor4B = new ccColor4B(0, 0, 0, 0); CCSize winSize = CCDirector.sharedDirector().getWinSize(); CCLayer cCLayer = new CCLayer(); CCRenderTexture cCPoint = CCRenderTexture.renderTextureWithWidthAndHeight((int)winSize.width, (int)winSize.height); if (cCPoint == null) { return; } cCPoint.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); cCPoint.position = new CCPoint(winSize.width / 2f, winSize.height / 2f); cCPoint.anchorPoint = new CCPoint(0.5f, 0.5f); cCPoint.begin(); this.m_pInScene.visit(); cCPoint.end(); CCRenderTexture cCRenderTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)winSize.width, (int)winSize.height); cCRenderTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); cCRenderTexture.position = new CCPoint(winSize.width / 2f, winSize.height / 2f); cCRenderTexture.anchorPoint = new CCPoint(0.5f, 0.5f); cCRenderTexture.begin(); this.m_pOutScene.visit(); cCRenderTexture.end(); ccBlendFunc _ccBlendFunc = new ccBlendFunc(1, 1); ccBlendFunc _ccBlendFunc1 = new ccBlendFunc(770, 771); cCPoint.Sprite.BlendFunc = _ccBlendFunc; cCRenderTexture.Sprite.BlendFunc = _ccBlendFunc1; cCLayer.addChild(cCPoint); cCLayer.addChild(cCRenderTexture); cCPoint.Sprite.Opacity = 255; cCRenderTexture.Sprite.Opacity = 255; CCFiniteTimeAction[] cCFiniteTimeActionArray = new CCFiniteTimeAction[] { CCFadeTo.actionWithDuration(this.m_fDuration, 0), CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.hideOutShowIn)), CCCallFunc.actionWithTarget(this, new SEL_CallFunc(this.finish)) }; CCAction cCAction = CCSequence.actions(cCFiniteTimeActionArray); cCRenderTexture.Sprite.runAction(cCAction); this.addChild(cCLayer, 2, 2147483647); }
/// <summary> /// /// </summary> /// <param name="p_Layer"></param> /// <param name="p_Text"></param> /// <param name="p_LeftButtonPic"></param> /// <param name="p_RightButtonPic"></param> /// <param name="y"></param> public static void AddSetMenu(CCLayer p_Layer, String p_Text, String p_LeftButtonPic, String p_RightButtonPic, SEL_MenuHandler p_LeftHandle,SEL_MenuHandler p_RightHandle, ref float y) { CCLabelTTF language = CCLabelTTF.labelWithString(p_Text, "ChineseTitle", 28); language.Color = new ccColor3B(Color.White); CCMenuItemLabel tab1 = CCMenuItemLabel.itemWithLabel(language); //CCTexture2D cctext2D1 = Media.PictureManager.GetCCTexture2D(p_LeftButtonPic); //CCSprite sprite1 = CCSprite.spriteWithTexture(cctext2D1); CCMenuItemSprite tab2 = CCMenuItemImage.itemFromNormalImage(p_LeftButtonPic,null, p_Layer, p_LeftHandle); //CCTexture2D cctext2D2 = Media.PictureManager.GetCCTexture2D(p_RightButtonPic); // CCSprite sprite2 = CCSprite.spriteWithTexture(cctext2D2); CCMenuItemSprite tab3 = CCMenuItemImage.itemFromNormalImage(p_RightButtonPic, null, p_Layer, p_RightHandle); CCMenu p_Menu1 = CCMenu.menuWithItems(tab1); CCMenu p_Menu2 = CCMenu.menuWithItems(tab2); CCMenu p_Menu3 = CCMenu.menuWithItems(tab3); //position p_Menu2 float textwidth = tab1.contentSize.width < 40 ? 40 : tab1.contentSize.width; float displayCenter = CCDirector.sharedDirector().displaySizeInPixels.width / 2; float x2 = displayCenter - textwidth; float x1 = displayCenter; float x3 = displayCenter + textwidth; float y2=y+(tab1.contentSize.height-tab2.contentSize.height)/2; p_Menu2.position = new CCPoint(x2, y2); p_Menu1.position = new CCPoint(x1, y); p_Menu3.position = new CCPoint(x3, y2); p_Layer.addChild(p_Menu2); p_Layer.addChild(p_Menu1); p_Layer.addChild(p_Menu3); y -= tab2.contentSize.height + Blank; }
public GroundBase(int typeId, CCPoint position, CCLayer layer) { this.GroundType = typeId; string imgPath = GetRoleImgPathByRoleTypeId(typeId); Row = (int)position.y; Col = (int)position.x; if (!string.IsNullOrEmpty(imgPath)) { Sprite = CCSprite.spriteWithFile(imgPath); Sprite.position = new CCPoint(position.x * AppContext.MAP_WIDTH + 15, position.y * AppContext.MAP_WIDTH + 15); layer.addChild(Sprite); } }
public Role(string roleImgPath, CCPoint position, CCLayer layer, Map map) { this.map = map; this.layer = layer; Col = (int)position.x; Row = (int)position.y; if (!string.IsNullOrEmpty(roleImgPath)) { Sprite = CCSprite.spriteWithFile(roleImgPath); Sprite.position = new CCPoint(position.x * AppContext.MAP_WIDTH + 15, position.y * AppContext.MAP_WIDTH + 15); layer.addChild(Sprite); } OringinGround = map.GroundList[Row * Map.Width + Col]; GetPathNodeList(); }
/// <summary> /// ���µ÷� /// </summary> /// <param name="score"></param> private void UpdateScore(List<CCSprite> digitSprites, CCLayer scoreLayer, int score, bool playSound) { string scoreStr = score.ToString(); for (int i = digitSprites.Count; digitSprites.Count < scoreStr.Length; i++) { var tempDigit = CCSprite.spriteWithFile("imgs/score/" + scoreStr[i]); tempDigit.position = new CCPoint(i * tempDigit.contentSize.width, 0); digitSprites.Add(tempDigit); scoreLayer.addChild(tempDigit); } // ���� for (int i = 0; i < scoreStr.Length; i++) { digitSprites[i].Texture = CCTextureCache.sharedTextureCache().addImage("imgs/score/" + scoreStr[i]); } if (playSound && score > 0) { SimpleAudioEngine.sharedEngine().playEffect(@"musics/sfx_point"); } }
/// <summary> /// AddTitleMenu only text /// </summary> /// <param name="p_Layer">current CCLayer</param> /// <param name="p_TitleText">show text</param> /// <param name="y">current y</param> public static void AddTitleMenu(CCLayer p_Layer, String p_TitleText, ref float y) { CCLabelTTF label = CCLabelTTF.labelWithString(p_TitleText, "ChineseTitle", 28); label.Color = new ccColor3B(Color.White); CCMenuItemLabel tab = CCMenuItemLabel.itemWithLabel(label); CCMenu menu = CCMenu.menuWithItems(tab); menu.position = new CCPoint(CCDirector.sharedDirector().displaySizeInPixels.width / 2, y); //menu.position.y = p_CurrPoint.y; y -= tab.contentSize.height + Blank; p_Layer.addChild(menu); }
public void OnClick(CCLayer p_Layer) { p_Layer.isTouchEnabled = false; p_Layer.addChild(ResultPeople); ResultPeople.Play((obj) => { p_Layer.removeChild(ResultPeople,true); if (IsAnswer) { SceneController.RunScene(EnumScene.Question); } else { p_Layer.isTouchEnabled = true; } }); }
public override void onEnter() { base.onEnter(); // create a transparent color layer // in which we are going to add our rendertextures ccColor4B color = new ccColor4B(0, 0, 0, 0); CCSize size = CCDirector.sharedDirector().getWinSize(); //CCLayerColor layer = CCLayerColor.layerWithColor(color); CCLayer layer = new CCLayer(); // create the first render texture for inScene CCRenderTexture inTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)size.width, (int)size.height); if (null == inTexture) { return; } inTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); inTexture.position = new CCPoint(size.width / 2, size.height / 2); inTexture.anchorPoint = new CCPoint(0.5f, 0.5f); // render inScene to its texturebuffer inTexture.begin(); m_pInScene.visit(); inTexture.end(); // create the second render texture for outScene CCRenderTexture outTexture = CCRenderTexture.renderTextureWithWidthAndHeight((int)size.width, (int)size.height); outTexture.Sprite.anchorPoint = new CCPoint(0.5f, 0.5f); outTexture.position = new CCPoint(size.width / 2, size.height / 2); outTexture.anchorPoint = new CCPoint(0.5f, 0.5f); // render outScene to its texturebuffer outTexture.begin(); m_pOutScene.visit(); outTexture.end(); // create blend functions ccBlendFunc blend1 = new ccBlendFunc(OGLES.GL_ONE, OGLES.GL_ONE); // inScene will lay on background and will not be used with alpha ccBlendFunc blend2 = new ccBlendFunc(OGLES.GL_SRC_ALPHA, OGLES.GL_ONE_MINUS_SRC_ALPHA); // we are going to blend outScene via alpha // set blendfunctions inTexture.Sprite.BlendFunc = blend1; outTexture.Sprite.BlendFunc = blend2; // add render textures to the layer layer.addChild(inTexture); layer.addChild(outTexture); // initial opacity: inTexture.Sprite.Opacity = 255; outTexture.Sprite.Opacity = 255; // create the blend action CCAction layerAction = CCSequence.actions ( CCFadeTo.actionWithDuration(m_fDuration, 0), CCCallFunc.actionWithTarget(this, (base.hideOutShowIn)), CCCallFunc.actionWithTarget(this, (base.finish)) ); //// run the blend action outTexture.Sprite.runAction(layerAction); // add the layer (which contains our two rendertextures) to the scene addChild(layer, 2, kSceneFade); }