/** * 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); m_pContainer.RunAction(CCSequence.FromActions(scroll, expire)); Schedule(PerformedAnimatedScroll); }
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 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)CCSequence.FromActions(motion, motion.Reverse()))); m_root.RunAction(action1); var colorAction = new CCRepeatForever ((CCActionInterval) CCSequence.FromActions( 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]; CCActionInterval 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 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); }
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 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)); }
public override void OnEnter() { base.OnEnter(); CCLayerColor l = new CCLayerColor(m_tColor); m_pInScene.Visible = false; AddChild(l, 2, kSceneFade); CCNode f = GetChildByTag(kSceneFade); var a = (CCActionInterval) new CCSequence ( new CCFadeIn(m_fDuration / 2), new CCCallFunc((HideOutShowIn)), new CCFadeOut(m_fDuration / 2), new CCCallFunc((Finish)) ); f.RunAction(a); }
public void repeatForever(CCNode pSender) { var repeat = new CCRepeatForever (new CCRotateBy (1.0f, 360)); pSender.RunAction(repeat); }
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 = CCBKeyframeEasing.Linear; // Animate CCActionInterval 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 { // [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 == "opacity") { byte opacity = ((CCBValue)pValue).GetByteValue(); ((ICCRGBAProtocol)node).Opacity = opacity; } else if (pPropName == "displayFrame") { ((CCSprite)node).DisplayFrame = (CCSpriteFrame)pValue; } else if (pPropName == "color") { var color = (CCColor3BWapper)pValue; ((CCSprite)node).Color = color.getColor(); } else { CCLog.Log("unsupported property name is {0}", pPropName); Debug.Assert(false, "unsupported property now"); } } } }
public void RunAnimations(int nSeqId, float fTweenDuration) { Debug.Assert(nSeqId != -1, "Sequence id couldn't be found"); mRootNode.StopAllActions(); foreach (var pElement in mNodeSequences) { 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 (mBaseValues.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) ); mRootNode.RunAction(completeAction); // Set the running scene mRunningSequence = GetSequence(nSeqId); }
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 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)); }
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]; CCActionInterval 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 = CCSequence.FromActions(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 = CCBKeyframeEasing.Linear; // Animate CCActionInterval 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 { // [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 == "opacity") { byte opacity = ((CCBValue) pValue).GetByteValue(); ((ICCRGBAProtocol) node).Opacity = opacity; } else if (pPropName == "displayFrame") { ((CCSprite) node).DisplayFrame = (CCSpriteFrame) pValue; } else if (pPropName == "color") { var color = (ccColor3BWapper) pValue; ((CCSprite) node).Color = color.getColor(); } else { CCLog.Log("unsupported property name is {0}", pPropName); Debug.Assert(false, "unsupported property now"); } } } }