public override void OnEnter() { base.OnEnter(); CCNode target = GetChildByTag(EffectAdvanceScene.kTagBackground); // To reuse a grid the grid size and the grid type must be the same. // in this case: // Lens3D is Grid3D and it's size is (15,10) // Waves3D is Grid3D and it's size is (15,10) CCSize size = CCDirector.SharedDirector.WinSize; CCActionInterval lens = new CCLens3D(0.0f, new CCGridSize(15, 10), new CCPoint(size.Width / 4, size.Height / 4), 240); CCActionInterval waves = new CCWaves3D(10, new CCGridSize(15, 10), 18, 15); CCFiniteTimeAction reuse = new CCReuseGrid(1); CCActionInterval delay = new CCDelayTime(8); CCActionInterval orbit = new CCOrbitCamera(5, 1, 2, 0, 180, 0, -90); CCFiniteTimeAction orbit_back = orbit.Reverse(); target.RunAction(new CCRepeatForever((new CCSequence(orbit, orbit_back)))); target.RunAction(new CCSequence(lens, delay, reuse, waves)); }
void onTouchesEnded(List <CCTouch> touches, CCEvent touchEvent) { //base.ccTouchesEnded(touches, event_); object it = touches.First(); CCTouch touch = (CCTouch)(it); var convertedLocation = touch.Location; CCNode s = this[ClickAndMoveTest.kTagSprite]; s.StopAllActions(); s.RunAction(new CCMoveTo(1, new CCPoint(convertedLocation.X, convertedLocation.Y))); float o = convertedLocation.X - s.Position.X; float a = convertedLocation.Y - s.Position.Y; float at = (float)(Math.Atan(o / a) * 57.29577951f); if (a < 0) { if (o < 0) { at = 180 + Math.Abs(at); } else { at = 180 - Math.Abs(at); } } s.RunAction(new CCRotateTo(1, at)); }
private void RunOutroAnimations() { var slideOutHeader = new CCMoveTo(1, new CCPoint(0, 200)); var sequence = new CCSequence(slideOutHeader, new CCDelayTime(0.2f), new CCCallFunc(() => CCDirector.SharedDirector.ReplaceScene(new MainScene()))); _gameHeader.RunAction(sequence); }
public override void TouchesEnded(List <CCTouch> touches, CCEvent event_) { //base.ccTouchesEnded(touches, event_); object it = touches.First(); CCTouch touch = (CCTouch)(it); CCPoint location = touch.LocationInView; CCPoint convertedLocation = CCDirector.SharedDirector.ConvertToGl(location); CCNode s = GetChildByTag(ClickAndMoveTest.kTagSprite); s.StopAllActions(); s.RunAction(new CCMoveTo(1, new CCPoint(convertedLocation.X, convertedLocation.Y))); float o = convertedLocation.X - s.Position.X; float a = convertedLocation.Y - s.Position.Y; float at = (float)(Math.Atan(o / a) * 57.29577951f); if (a < 0) { if (o < 0) { at = 180 + Math.Abs(at); } else { at = 180 - Math.Abs(at); } } s.RunAction(new CCRotateTo(1, at)); }
public NodeToWorld3D() { // // This code tests that nodeToParent works OK: // - It tests different anchor Points // - It tests different children anchor points parent = new CCNode(); parent.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(parent); back = new CCSprite(TestResource.s_back3); parent.AddChild(back, -10); back.AnchorPoint = CCPoint.Zero; var item = new CCMenuItemImage(TestResource.s_PlayNormal, TestResource.s_PlaySelect); menu = new CCMenu(item); menu.AlignItemsVertically(); back.AddChild(menu); item.RepeatForever(CocosNodeTestStaticLibrary.nodeRotate); back.RepeatForever(CocosNodeTestStaticLibrary.nodeMove, CocosNodeTestStaticLibrary.nodeMove.Reverse()); parent.RunAction (CocosNodeTestStaticLibrary.nodeOrbit); }
protected override CCNode Content() { CCNode node = Shape(); node.RunAction(ActionScale()); return(node); }
protected override CCNode Stencil() { CCNode node = Grossini(); node.RunAction(ActionRotate()); return(node); }
protected override CCNode Stencil() { CCNode node = Shape(); node.RunAction(this.ActionRotate()); return(node); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; CCRect visibleBounds = Layer.VisibleBoundsWorldspace; CCCamera contentCamera = contentLayer.Camera; contentCamera.Projection = CCCameraProjection.Projection3D; contentCamera.PerspectiveAspectRatio = 3.0f; CCPoint3 cameraCenter = contentCamera.CenterInWorldspace; CCPoint3 cameraTarget = contentCamera.TargetInWorldspace; float targeCenterLength = (cameraTarget - cameraCenter).Length; contentCamera.NearAndFarPerspectiveClipping = new CCPoint(0.15f, 100.0f); contentCamera.PerspectiveFieldOfView = (float)Math.Atan(visibleBounds.Size.Height / (2.0f * targeCenterLength)); Schedule(checkAnim); BaseNode.Position = windowSize.Center; var size = BaseNode.ContentSize; BaseNode[EffectTestScene.kTagKathia].Position = new CCPoint(size.Width / 3, size.Center.Y); BaseNode[EffectTestScene.kTagTamara].Position = new CCPoint(2 * size.Width / 3, size.Center.Y); BaseNode.RunAction(CurrentAction); }
private void MyOnGamePadButtonUpdate(CCGamePadButtonStatus backButton, CCGamePadButtonStatus startButton, CCGamePadButtonStatus systemButton, CCGamePadButtonStatus aButton, CCGamePadButtonStatus bButton, CCGamePadButtonStatus xButton, CCGamePadButtonStatus yButton, CCGamePadButtonStatus leftShoulder, CCGamePadButtonStatus rightShoulder, Microsoft.Xna.Framework.PlayerIndex player) { if (aButton == CCGamePadButtonStatus.Pressed) { _aButtonWasPressed = true; } else if (aButton == CCGamePadButtonStatus.Released && _aButtonWasPressed) { // Select the menu restartCallback(null); } if (yButton == CCGamePadButtonStatus.Pressed) { _yButtonWasPressed = true; } else if (yButton == CCGamePadButtonStatus.Released && _yButtonWasPressed) { CCNode node = GetChildByTag(kTagTileMap); node.RunAction(new CCRotateBy(1f, 15f)); } if (xButton == CCGamePadButtonStatus.Pressed) { _xButtonWasPressed = true; } else if (xButton == CCGamePadButtonStatus.Released && _xButtonWasPressed) { CCNode node = GetChildByTag(kTagTileMap); if (node != null) { node.RunAction(new CCRotateBy(1f, -15f)); } } }
public NodeToWorld3D() { // // This code tests that nodeToParent works OK: // - It tests different anchor Points // - It tests different children anchor points parent = new CCNode(); parent.AnchorPoint = new CCPoint(0.5f, 0.5f); AddChild(parent); back = new CCSprite(TestResource.s_back3); parent.AddChild(back, -10); back.AnchorPoint = CCPoint.Zero; var item = new CCMenuItemImage(TestResource.s_PlayNormal, TestResource.s_PlaySelect); menu = new CCMenu(item); menu.AlignItemsVertically(); back.AddChild(menu); item.RepeatForever(CocosNodeTestStaticLibrary.nodeRotate); back.RepeatForever(CocosNodeTestStaticLibrary.nodeMove, CocosNodeTestStaticLibrary.nodeMove.Reverse()); parent.RunAction(CocosNodeTestStaticLibrary.nodeOrbit); }
public override void OnEnter() { base.OnEnter(); CCNode target = GetChildByTag(EffectAdvanceScene.kTagBackground); // To reuse a grid the grid size and the grid type must be the same. // in this case: // ShakyTiles is TiledGrid3D and it's size is (15,10) // Shuffletiles is TiledGrid3D and it's size is (15,10) // TurnOfftiles is TiledGrid3D and it's size is (15,10) CCActionInterval shaky = new CCShakyTiles3D(4, false, new CCGridSize(15, 10), 5); CCActionInterval shuffle = new CCShuffleTiles(0, new CCGridSize(15, 10), 3); CCActionInterval turnoff = new CCTurnOffTiles(0, new CCGridSize(15, 10), 3); CCFiniteTimeAction turnon = turnoff.Reverse(); // reuse 2 times: // 1 for shuffle // 2 for turn off // turnon tiles will use a new grid CCFiniteTimeAction reuse = new CCReuseGrid(2); CCActionInterval delay = new CCDelayTime(1); // id orbit = [OrbitCamera::actionWithDuration:5 radius:1 deltaRadius:2 angleZ:0 deltaAngleZ:180 angleX:0 deltaAngleX:-90]; // id orbit_back = [orbit reverse]; // // [target runAction: [RepeatForever::actionWithAction: [Sequence actions: orbit, orbit_back, nil]]]; target.RunAction((CCSequence.FromActions(shaky, delay, reuse, shuffle, (CCFiniteTimeAction)delay.Copy(), turnoff, turnon))); }
public override void Update(float dt) { elapsed += dt; if (elapsed > 1f) { elapsed = 0f; // CCLabelBMFont if (label1 != null) { RemoveChild(label1); } CCNode node = new CCNode(); CCSize s = CCDirector.SharedDirector.WinSize; float x = s.Width * CCMacros.CCRandomBetween0And1(); float y = s.Height * CCMacros.CCRandomBetween0And1(); label1 = new CCLabelBMFont(string.Format("{0:N2},{1:N2} @ Mem Leak Ctor", x, y), "fonts/konqa32.fnt", 255f, CCTextAlignment.Right, CCPoint.Zero); node.AddChild(label1); label1.Position = new CCPoint(x, y); AddChild(node); label1 = node; // Start - test case for memory leak mentioned at https://cocos2dxna.codeplex.com/discussions/544032 node.Scale = 2f; //--> This action causes the leak CCScaleTo acScale = new CCScaleTo(0.1f, 1); CCDelayTime acShow = new CCDelayTime(0.1f); CCSplitRows acFadeOut = new CCSplitRows(0.1f, 20); CCRemoveSelf acRemove = new CCRemoveSelf(true); CCSequence seq = new CCSequence(acScale, acShow, acFadeOut, acRemove); node.RunAction(seq); } }
public TextLayer() { InitWithColor(CCTypes.CreateColor(32, 32, 32, 255)); var node = new CCNode(); CCActionInterval effect = getAction(); node.RunAction(effect); AddChild(node, 0, EffectTestScene.kTagBackground); var bg = new CCSprite(TestResource.s_back3); node.AddChild(bg, 0); bg.AnchorPoint = new CCPoint(0.5f, 0.5f); bg.Position = CCVisibleRect.Center; var grossini = new CCSprite(TestResource.s_pPathSister2); node.AddChild(grossini, 1); grossini.Position = new CCPoint(CCVisibleRect.Left.X + CCVisibleRect.VisibleRect.Size.Width / 3, CCVisibleRect.Center.Y); CCActionInterval sc = new CCScaleBy(2, 5); CCFiniteTimeAction sc_back = sc.Reverse(); grossini.RunAction(new CCRepeatForever((new CCSequence(sc, sc_back)))); var tamara = new CCSprite(TestResource.s_pPathSister1); node.AddChild(tamara, 1); tamara.Position = new CCPoint(CCVisibleRect.Left.X + 2 * CCVisibleRect.VisibleRect.Size.Width / 3, CCVisibleRect.Center.Y); CCActionInterval sc2 = new CCScaleBy(2, 5); CCFiniteTimeAction sc2_back = sc2.Reverse(); tamara.RunAction(new CCRepeatForever((new CCSequence(sc2, sc2_back)))); var label = new CCLabelTTF(EffectTestScene.effectsList[EffectTestScene.actionIdx], "arial", 32); label.Position = new CCPoint(CCVisibleRect.Center.X, CCVisibleRect.Top.Y - 80); AddChild(label); label.Tag = EffectTestScene.kTagLabel; var item1 = new CCMenuItemImage(TestResource.s_pPathB1, TestResource.s_pPathB2, backCallback); var item2 = new CCMenuItemImage(TestResource.s_pPathR1, TestResource.s_pPathR2, restartCallback); var item3 = new CCMenuItemImage(TestResource.s_pPathF1, TestResource.s_pPathF2, nextCallback); var menu = new CCMenu(item1, item2, item3); menu.Position = CCPoint.Zero; item1.Position = new CCPoint(CCVisibleRect.Center.X - item2.ContentSize.Width * 2, CCVisibleRect.Bottom.Y + item2.ContentSize.Height / 2); item2.Position = new CCPoint(CCVisibleRect.Center.X, CCVisibleRect.Bottom.Y + item2.ContentSize.Height / 2); item3.Position = new CCPoint(CCVisibleRect.Center.X + item2.ContentSize.Width * 2, CCVisibleRect.Bottom.Y + item2.ContentSize.Height / 2); AddChild(menu, 1); Schedule(checkAnim); }
/** * Sets a new content offset. It ignores max/min offset. It just sets what's given. (just like UIKit's UIScrollView) * You can override the animation duration with this method. * * @param offset new offset * @param animation duration */ public void SetContentOffsetInDuration(CCPoint offset, float dt) { CCMoveTo scroll = new CCMoveTo(dt, offset); CCCallFuncN expire = new CCCallFuncN(StoppedAnimatedScroll); container.RunAction(new CCSequence(scroll, expire)); Schedule(PerformedAnimatedScroll); }
public override void OnEnter() { base.OnEnter(); CCSize s = CCDirector.SharedDirector.WinSize; // the root object just rotates around m_root = new CCSprite(s_pPathR1); AddChild(m_root, 1); m_root.Position = new CCPoint(s.Width / 2, s.Height / 2); // the target object is offset from root, and the streak is moved to follow it m_target = new CCSprite(s_pPathR1); m_root.AddChild(m_target); m_target.Position = new CCPoint(s.Width / 4, 0); // create the streak object and add it to the scene streak = CCMotionStreak.Create(2, 3, 32, CCTypes.CCGreen, s_streak); streak.FastMode = true; AddChild(streak); // schedule an update on each frame so we can syncronize the streak with the target Schedule(onUpdate); var a1 = new CCRotateBy(2, 360); var action1 = new CCRepeatForever(a1); var motion = new CCMoveBy(2, new CCPoint(100, 0)); m_root.RunAction(new CCRepeatForever((CCActionInterval) new CCSequence(motion, motion.Reverse()))); m_root.RunAction(action1); var colorAction = new CCRepeatForever((CCActionInterval) new CCSequence( new CCTintTo(0.2f, 255, 0, 0), new CCTintTo(0.2f, 0, 255, 0), new CCTintTo(0.2f, 0, 0, 255), new CCTintTo(0.2f, 0, 255, 255), new CCTintTo(0.2f, 255, 255, 0), new CCTintTo(0.2f, 255, 0, 255), new CCTintTo(0.2f, 255, 255, 255) ) ); streak.RunAction(colorAction); }
private void RunAction(CCNode node, CCBSequenceProperty pSeqProp, float fTweenDuration) { List <CCBKeyframe> keyframes = pSeqProp.Keyframes; int numKeyframes = keyframes.Count; if (numKeyframes > 1) { // Make an animation! var actions = new List <CCFiniteTimeAction>(); CCBKeyframe keyframeFirst = keyframes[0]; float timeFirst = keyframeFirst.Time + fTweenDuration; if (timeFirst > 0) { actions.Add(new CCDelayTime(timeFirst)); } for (int i = 0; i < numKeyframes - 1; ++i) { CCBKeyframe kf0 = keyframes[i]; CCBKeyframe kf1 = keyframes[i + 1]; CCFiniteTimeAction action = GetAction(kf0, kf1, pSeqProp.Name, node); if (action != null) { // Apply easing action = GetEaseAction(action, kf0.EasingType, kf0.EasingOpt); actions.Add(action); } } if (actions.Count > 1) { CCFiniteTimeAction seq = new CCSequence(actions.ToArray()); node.RunAction(seq); } else { node.RunAction(actions[0]); } } }
public override void OnEnter() { base.OnEnter(); CCSize s = Layer.VisibleBoundsWorldspace.Size; // the root object just rotates around m_root = new CCSprite(s_pPathR1); AddChild(m_root, 1); m_root.Position = new CCPoint(s.Width / 2, s.Height / 2); // the target object is offset from root, and the streak is moved to follow it m_target = new CCSprite(s_pPathR1); m_root.AddChild(m_target); m_target.Position = new CCPoint(s.Width / 4, 0); // create the streak object and add it to the scene streak = new CCMotionStreak(2, 3, 32, CCColor3B.Green, s_streak); streak.FastMode = true; AddChild(streak); // schedule an update on each frame so we can syncronize the streak with the target Schedule(onUpdate); var a1 = new CCRotateBy (2, 360); var action1 = new CCRepeatForever (a1); var motion = new CCMoveBy (2, new CCPoint(100, 0)); m_root.RunAction(new CCRepeatForever ((CCFiniteTimeAction)new CCSequence(motion, motion.Reverse()))); m_root.RunAction(action1); var colorAction = new CCRepeatForever ((CCFiniteTimeAction) new CCSequence( new CCTintTo (0.2f, 255, 0, 0), new CCTintTo (0.2f, 0, 255, 0), new CCTintTo (0.2f, 0, 0, 255), new CCTintTo (0.2f, 0, 255, 255), new CCTintTo (0.2f, 255, 255, 0), new CCTintTo (0.2f, 255, 0, 255), new CCTintTo (0.2f, 255, 255, 255) ) ); streak.RunAction(colorAction); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; stencil.RunAction(this.ActionRotate()); content.RunAction(this.ActionScale()); var s = windowSize; this[kTagClipperNode].Position = new CCPoint(s.Width / 2 - 50, s.Height / 2 - 50); }
public static void AddJiggle(CCNode targetSprite) { var swingTime = CCRandom.Next(10, 31) / 100f; var rotateLeftAction = new CCRotateBy(swingTime, 1); var rotateRightAction = new CCRotateBy(swingTime * 2, -2); var rotateBackAction = new CCRotateBy(swingTime, 1); var rotateSequence = new CCSequence(rotateLeftAction, rotateRightAction, rotateBackAction); var repeatAction = new CCRepeatForever(rotateSequence); targetSprite.RunAction(repeatAction); }
public override void OnEnter() { base.OnEnter(); CCSize windowSize = Layer.VisibleBoundsWorldspace.Size; CCRect visibleBounds = Layer.VisibleBoundsWorldspace; Schedule(checkAnim); BaseNode.Position = windowSize.Center; var size = BaseNode.ContentSize; BaseNode[EffectTestScene.kTagKathia].Position = new CCPoint(size.Width / 3, size.Center.Y); BaseNode[EffectTestScene.kTagTamara].Position = new CCPoint(2 * size.Width / 3, size.Center.Y); BaseNode.RunAction(CurrentAction); }
public SpriteZVertex() { // // 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. // m_dir = 1; m_time = 0; CCSize s = CCDirector.SharedDirector.WinSize; float step = s.Width / 12; CCNode node = new CCNode(); // camera uses the center of the image as the pivoting point node.ContentSize = (new CCSize(s.Width, s.Height)); node.AnchorPoint = (new CCPoint(0.5f, 0.5f)); node.Position = (new CCPoint(s.Width / 2, s.Height / 2)); AddChild(node, 0); for (int i = 0; i < 5; i++) { CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 0, 121 * 1, 85, 121)); sprite.Position = (new CCPoint((i + 1) * step, s.Height / 2)); sprite.VertexZ = (10 + i * 40); node.AddChild(sprite, 0); } for (int i = 5; i < 11; i++) { CCSprite sprite = new CCSprite("Images/grossini_dance_atlas", new CCRect(85 * 1, 121 * 0, 85, 121)); sprite.Position = (new CCPoint((i + 1) * step, s.Height / 2)); sprite.VertexZ = 10 + (10 - i) * 40; node.AddChild(sprite, 0); } node.RunAction(new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0)); }
protected override void AddedToScene() { base.AddedToScene(); contentLayer = new CCLayer(); GameView.DepthTesting = 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 override void OnEnter() { base.OnEnter(); CCNode bg = GetChildByTag(EffectAdvanceScene.kTagBackground); CCNode target1 = bg.GetChildByTag(EffectAdvanceScene.kTagSprite1); CCNode target2 = bg.GetChildByTag(EffectAdvanceScene.kTagSprite2); CCActionInterval waves = new CCWaves(5, new CCGridSize(15, 10), 5, 20, true, false); CCActionInterval shaky = new CCShaky3D(5, new CCGridSize(15, 10), 4, false); target1.RunAction(new CCRepeatForever(waves)); target2.RunAction(new CCRepeatForever(shaky)); // moving background. Testing issue #244 CCActionInterval move = new CCMoveBy(3, new CCPoint(200, 0)); bg.RunAction(new CCRepeatForever(new CCSequence(move, move.Reverse()))); }
public override void OnEnter() { base.OnEnter(); //CCDirector::sharedDirector()->setProjection(CCDirectorProjection2D); CCActionInterval effect = new CCLiquid(1, 20, new CCGridSize(32, 24), 2); CCActionInterval stopEffect = (CCActionInterval)(CCSequence.FromActions( effect, new CCDelayTime(2), new CCStopGrid() // [DelayTime::actionWithDuration:2], // [[effect copy] autorelease], )); CCNode bg = GetChildByTag(EffectAdvanceScene.kTagBackground); bg.RunAction(stopEffect); }
public override void OnEnter() { base.OnEnter(); CCSize layerSize = contentLayer.VisibleBoundsWorldspace.Size; float step = layerSize.Width / 12; for (int i = 0; i < 5; i++) { sprites[i].Position = (new CCPoint((i + 1) * step, layerSize.Height / 2)); sprites[i].VertexZ = (10 + i * 20); } for (int i = 5; i < 11; i++) { sprites[i].Position = (new CCPoint((i + 1) * step, layerSize.Height / 2)); sprites[i].VertexZ = 10 + (10 - i) * 20; } node.RunAction(new CCOrbitCamera(10, 1, 0, 0, 360, 0, 0)); }
private void SetAnimatedProperty(string pPropName, CCNode node, object pValue, float fTweenDuraion) { if (fTweenDuraion > 0) { // Create a fake keyframe to generate the action from var kf1 = new CCBKeyframe(); kf1.Value = pValue; kf1.Time = fTweenDuraion; kf1.EasingType = CCBEasingType.Linear; // Animate CCFiniteTimeAction tweenAction = GetAction(null, kf1, pPropName, node); node.RunAction(tweenAction); } else { // Just set the value if (pPropName == "position") { // Get position type var array = (List<CCBValue>)GetBaseValue(node, pPropName); var type = (CCBPositionType)array[2].GetIntValue(); // Get relative position var value = (List<CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); node.Position = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, GetContainerSize(node.Parent), pPropName); } else if (pPropName == "scale") { // Get scale type var array = (List<CCBValue>)GetBaseValue(node, pPropName); var type = (CCBScaleType)array[2].GetIntValue(); // Get relative scale var value = (List<CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); CCBHelper.SetRelativeScale(node, x, y, type, pPropName); } else if (pPropName == "skew") { // Get relative scale var value = (List<CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); node.SkewX = x; node.SkewY = y; } else { // [node setValue:value forKey:name]; // TODO only handle rotation, opacity, displayFrame, color if (pPropName == "rotation") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.Rotation = rotate; } else if (pPropName == "rotationX") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.RotationX = rotate; } else if (pPropName == "rotationY") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.RotationY = rotate; } else if (pPropName == "opacity") { byte opacity = ((CCBValue)pValue).GetByteValue(); node.Opacity = opacity; } else if (pPropName == "displayFrame") { ((CCSprite)node).SpriteFrame = (CCSpriteFrame)pValue; } else if (pPropName == "color") { var color = (CCColor3BWapper)pValue; node.Color = color.Color; } else if (pPropName == "visible") { bool visible = ((CCBValue)pValue).GetBoolValue(); node.Visible = visible; } else { CCLog.Log("unsupported property name is {0}", pPropName); Debug.Assert(false, "unsupported property now"); } } } }
public void bugMe(CCNode node) { node.StopAllActions(); //After this stop next action not working, if remove this stop everything is working node.RunAction(new CCScaleTo(2, 2)); }
public void RunAnimationsForSequenceIdTweenDuration(int nSeqId, float fTweenDuration) { Debug.Assert(nSeqId != -1, "Sequence id couldn't be found"); _rootNode.StopAllActions(); foreach (var pElement in _nodeSequences) { CCNode node = pElement.Key; node.StopAllActions(); // Refer to CCBReader::readKeyframe() for the real type of value Dictionary <int, Dictionary <string, CCBSequenceProperty> > seqs = pElement.Value; var seqNodePropNames = new List <string>(); Dictionary <string, CCBSequenceProperty> seqNodeProps; if (seqs.TryGetValue(nSeqId, out seqNodeProps)) { // Reset nodes that have sequence node properties, and run actions on them foreach (var pElement1 in seqNodeProps) { string propName = pElement1.Key; CCBSequenceProperty seqProp = pElement1.Value; seqNodePropNames.Add(propName); SetFirstFrame(node, seqProp, fTweenDuration); RunAction(node, seqProp, fTweenDuration); } } // Reset the nodes that may have been changed by other timelines Dictionary <string, object> nodeBaseValues; if (_baseValues.TryGetValue(node, out nodeBaseValues)) { foreach (var pElement2 in nodeBaseValues) { if (!seqNodePropNames.Contains(pElement2.Key)) { object value = pElement2.Value; if (value != null) { SetAnimatedProperty(pElement2.Key, node, value, fTweenDuration); } } } } } // Make callback at end of sequence CCBSequence seq = GetSequence(nSeqId); CCAction completeAction = new CCSequence( new CCDelayTime(seq.Duration + fTweenDuration), new CCCallFunc(SequenceCompleted) ); _rootNode.RunAction(completeAction); // Set the running scene if (seq.CallBackChannel != null) { CCAction action = (CCAction)ActionForCallbackChannel(seq.CallBackChannel); if (action != null) { _rootNode.RunAction(action); } } if (seq.SoundChannel != null) { CCAction action = (CCAction)ActionForSoundChannel(seq.SoundChannel); if (action != null) { _rootNode.RunAction(action); } } _runningSequence = GetSequence(nSeqId); }
public void bugMe(CCNode node) { node.StopAllActions(); //After this stop next action not working, if remove this stop everything is working node.RunAction(new CCScaleTo(2, 2)); }
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)); }
void CreatePipesAndCoins() { var pipeNode = new CCNode(); pipeNode.AnchorPoint = CCPoint.Zero; pipeNode.Name = "pipe"; var bottomPipe = new CCSprite("pipe"); bottomPipe.AnchorPoint = CCPoint.Zero; bottomPipe.ScaleX = 0.5f; bottomPipe.FlipY = true; bottomPipe.Name = "bottomPipe"; bottomPipe.Position = new CCPoint(0, 0); var pipeGap = new CCDrawNode(); pipeGap.AnchorPoint = CCPoint.Zero; pipeGap.DrawRect(new CCRect(0, 0, 1, (player.ContentSize.Height * 2.8f) - pipeGapShrink), CCColor4B.Red); pipeGap.Name = "sensorScore"; pipeGap.Position = new CCPoint(bottomPipe.ScaledContentSize.Width, bottomPipe.ContentSize.Height); pipeGap.Visible = false; var topPipe = new CCSprite("pipe"); topPipe.AnchorPoint = CCPoint.Zero; topPipe.ScaleX = 0.5f; topPipe.Name = "topPipe"; topPipe.Position = new CCPoint(0, bottomPipe.ContentSize.Height + pipeGap.ContentSize.Height); pipeNode.AddChild(bottomPipe); pipeNode.AddChild(pipeGap); pipeNode.AddChild(topPipe); AddChild(pipeNode); this.ReorderChild(pipeNode, -20); float xPosition = ContentSize.Width; float yPosition = CCRandom.Next(-530, 5); pipeNode.Position = new CCPoint(xPosition, yPosition); //Create coin var coin = new CCSprite("gold_1"); coin.Name = "coin"; coin.Scale = 0.75f; int coinPos = CCRandom.Next(0, 3); if (coinPos == 0) { coin.Tag = 0; coin.PositionX = topPipe.PositionX + 190; coin.PositionY = topPipe.PositionY + 120; } else if (coinPos == 1) { coin.Tag = 1; coin.PositionX = topPipe.PositionX + coin.ContentSize.Width / 3; coin.PositionY = topPipe.PositionY - pipeGap.ContentSize.Height / 2; } else { coin.Tag = 2; coin.PositionX = topPipe.PositionX + 190; coin.PositionY = topPipe.PositionY - pipeGap.ContentSize.Height - 120; } pipeNode.AddChild(coin); this.ReorderChild(coin, 10); CCAnimation coinAnimation = new CCAnimation(); for (int i = 1; i <= 4; i++) { coinAnimation.AddSpriteFrame(new CCSprite(string.Format("gold_{0}", i))); } coinAnimation.DelayPerUnit = 0.1f; var animate = new CCAnimate(coinAnimation); var animationAction = new CCRepeatForever(animate); coin.RunAction(animationAction); float endPosition = ContentSize.Width + (pipeNode.ContentSize.Width * 2) + 190; var moveAction = new CCMoveBy(6.2f, new CCPoint(-endPosition, 0)); var remove = new CCRemoveSelf(); var moveSequence = new CCSequence(moveAction, remove); pipeNode.RunAction(moveSequence); }
public void repeatForever(CCNode pSender) { var repeat = new CCRepeatForever(new CCRotateBy(1.0f, 360)); pSender.RunAction(repeat); }
public TextLayer() { InitWithColor(CCTypes.CreateColor(32, 32, 32, 255)); float x, y; CCSize size = CCDirector.SharedDirector.WinSize; x = size.Width; y = size.Height; CCNode node = new CCNode(); CCActionInterval effect = getAction(); node.RunAction(effect); AddChild(node, 0, EffectTestScene.kTagBackground); CCSprite bg = new CCSprite(TestResource.s_back3); node.AddChild(bg, 0); bg.AnchorPoint = new CCPoint(0.5f, 0.5f); bg.Position = new CCPoint(size.Width / 2, size.Height / 2); CCSprite grossini = new CCSprite(TestResource.s_pPathSister2); node.AddChild(grossini, 1); grossini.Position = new CCPoint(x / 3, y / 2); CCActionInterval sc = new CCScaleBy(2, 5); CCFiniteTimeAction sc_back = sc.Reverse(); grossini.RunAction(new CCRepeatForever((CCActionInterval)(CCSequence.FromActions(sc, sc_back)))); //grossini.runAction(effect); CCSprite tamara = new CCSprite(TestResource.s_pPathSister1); node.AddChild(tamara, 1); tamara.Position = new CCPoint(2 * x / 3, y / 2); CCActionInterval sc2 = new CCScaleBy(2, 5); CCFiniteTimeAction sc2_back = sc2.Reverse(); tamara.RunAction(new CCRepeatForever((CCActionInterval)(CCSequence.FromActions(sc2, sc2_back)))); CCLabelTTF label = new CCLabelTTF(EffectTestScene.effectsList[EffectTestScene.actionIdx], "arial", 32); label.Position = new CCPoint(x / 2, y - 80); AddChild(label); label.Tag = EffectTestScene.kTagLabel; CCMenuItemImage item1 = new CCMenuItemImage(TestResource.s_pPathB1, TestResource.s_pPathB2, backCallback); CCMenuItemImage item2 = new CCMenuItemImage(TestResource.s_pPathR1, TestResource.s_pPathR2, restartCallback); CCMenuItemImage item3 = new CCMenuItemImage(TestResource.s_pPathF1, TestResource.s_pPathF2, nextCallback); CCMenu menu = new CCMenu(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); Schedule(checkAnim); }
public TextLayer() : base() { SizeF s = CCDirector.SharedDirector ().WinSize (); float x = s.Width; float y = s.Height; CCNode node = new CCNode (); CCAction effectClass = RestartAction (3f); node.RunAction (effectClass); this.AddChild (node, 0, (int)EffectLayers.kTagBackground); CCSprite bg = new CCSprite ("background3.png", true); node.AddChild (bg, 0); bg.Position = new PointF(x/2, y/2); CCSprite grossini = new CCSprite ("grossinis_sister2.png", true); node.AddChild (grossini, 1); grossini.Position = new PointF(x/3, y/2); CCScaleBy sc = new CCScaleBy (2, 5); CCActionInterval sc_back = sc.Reverse (); grossini.RunAction (new CCRepeatForever (new CCSequence (sc, sc_back))); CCSprite tamara = new CCSprite ("grossinis_sister1.png", true); node.AddChild (tamara, 1, (int)EffectLayers.kTagSprite2); tamara.Position = new PointF (2*x/3, y/2); CCScaleBy sc2 = new CCScaleBy (2, 5); CCActionInterval sc2_back = sc2.Reverse (); tamara.RunAction (new CCRepeatForever (new CCSequence (sc2, sc2_back))); CCLabelTTF label = new CCLabelTTF (effectsList[actionIdx].Replace("Demo", ""), "Marker Felt", 32); label.Position = new PointF (x/2, y-80); this.AddChild (label); label.Tag = (int)EffectLayers.kTagLabel; //menu CCMenuItemImage item1 = new CCMenuItemImage ("b1.png", "b2.png", null, BackCallback); CCMenuItemImage item2 = new CCMenuItemImage ("r1.png", "r2.png", null, RestartCallback); CCMenuItemImage item3 = new CCMenuItemImage ("f1.png", "f2.png", null, NextCallback); CCMenu menu = new CCMenu (item1, item2, item3); menu.Position = PointF.Empty; item1.Position = new PointF(s.Width/2 - item2.ContentSize.Width*2, item2.ContentSize.Height/2); item2.Position = new PointF( s.Width/2, item2.ContentSize.Height/2); item3.Position = new PointF( s.Width/2 + item2.ContentSize.Width*2, item2.ContentSize.Height/2); this.AddChild (menu, 1); this.Schedule (new MonoMac.ObjCRuntime.Selector ("checkAnim:")); }
public void RepeatForever(CCNode sender) { sender.RunAction(repeat); }
private void RunAction(CCNode node, CCBSequenceProperty pSeqProp, float fTweenDuration) { List<CCBKeyframe> keyframes = pSeqProp.Keyframes; int numKeyframes = keyframes.Count; if (numKeyframes > 1) { // Make an animation! var actions = new List<CCFiniteTimeAction>(); CCBKeyframe keyframeFirst = keyframes[0]; float timeFirst = keyframeFirst.Time + fTweenDuration; if (timeFirst > 0) { actions.Add(new CCDelayTime(timeFirst)); } for (int i = 0; i < numKeyframes - 1; ++i) { CCBKeyframe kf0 = keyframes[i]; CCBKeyframe kf1 = keyframes[i + 1]; CCFiniteTimeAction action = GetAction(kf0, kf1, pSeqProp.Name, node); if (action != null) { // Apply easing action = GetEaseAction(action, kf0.EasingType, kf0.EasingOpt); actions.Add(action); } } if (actions.Count > 1) { CCFiniteTimeAction seq = new CCSequence(actions.ToArray()); node.RunAction(seq); } else { node.RunAction(actions[0]); } } }
private void SetAnimatedProperty(string pPropName, CCNode node, object pValue, float fTweenDuraion) { if (fTweenDuraion > 0) { // Create a fake keyframe to generate the action from var kf1 = new CCBKeyframe(); kf1.Value = pValue; kf1.Time = fTweenDuraion; kf1.EasingType = CCBEasingType.Linear; // Animate CCFiniteTimeAction tweenAction = GetAction(null, kf1, pPropName, node); node.RunAction(tweenAction); } else { // Just set the value if (pPropName == "position") { // Get position type var array = (List <CCBValue>)GetBaseValue(node, pPropName); var type = (CCBPositionType)array[2].GetIntValue(); // Get relative position var value = (List <CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); node.Position = CCBHelper.GetAbsolutePosition(new CCPoint(x, y), type, GetContainerSize(node.Parent), pPropName); } else if (pPropName == "scale") { // Get scale type var array = (List <CCBValue>)GetBaseValue(node, pPropName); var type = (CCBScaleType)array[2].GetIntValue(); // Get relative scale var value = (List <CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); CCBHelper.SetRelativeScale(node, x, y, type, pPropName); } else if (pPropName == "skew") { // Get relative scale var value = (List <CCBValue>)pValue; float x = value[0].GetFloatValue(); float y = value[1].GetFloatValue(); node.SkewX = x; node.SkewY = y; } else { // [node setValue:value forKey:name]; // TODO only handle rotation, opacity, displayFrame, color if (pPropName == "rotation") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.Rotation = rotate; } else if (pPropName == "rotationX") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.RotationX = rotate; } else if (pPropName == "rotationY") { float rotate = ((CCBValue)pValue).GetFloatValue(); node.RotationY = rotate; } else if (pPropName == "opacity") { byte opacity = ((CCBValue)pValue).GetByteValue(); node.Opacity = opacity; } else if (pPropName == "displayFrame") { ((CCSprite)node).SpriteFrame = (CCSpriteFrame)pValue; } else if (pPropName == "color") { var color = (CCColor3BWapper)pValue; node.Color = color.Color; } else if (pPropName == "visible") { bool visible = ((CCBValue)pValue).GetBoolValue(); node.Visible = visible; } else { CCLog.Log("unsupported property name is {0}", pPropName); Debug.Assert(false, "unsupported property now"); } } } }