public void SwitchToNone() { if (m_nEnabledLayer != -1) { CCLayer outLayer = null; if (m_pLayers.ContainsKey(m_nEnabledLayer)) { outLayer = m_pLayers[m_nEnabledLayer]; if (m_OutAction != null) { outLayer.RunAction( new CCSequence( (CCFiniteTimeAction)m_OutAction.Copy(), new CCCallFunc(() => RemoveChild(outLayer, true)) ) ); } else { RemoveChild(outLayer, true); } } } // We have no enabled layer at this point m_nEnabledLayer = -1; }
/** switches to a certain layer indexed by n. * The current (old) layer will be removed from it's parent with 'cleanup:YES'. */ /// <summary> /// Swtich to the given index layer and use the given action after the layer is /// added to the scene. /// </summary> /// <param name="n"></param> public void SwitchTo(int n) { Debug.Assert(n < m_pLayers.Count, "Invalid index in MultiplexLayer switchTo message"); CCLayer outLayer = m_pLayers[m_nEnabledLayer]; if (m_OutAction != null) { outLayer.RunAction( CCSequence.FromActions( (CCFiniteTimeAction)m_OutAction.Copy(), new CCCallFunc(() => RemoveChild(outLayer, true)) ) ); } else { RemoveChild(outLayer, true); } m_nEnabledLayer = n; AddChild(m_pLayers[n]); if (m_InAction != null) { m_pLayers[n].RunAction(m_InAction.Copy()); } }
/// <summary> /// Swtich to the given index layer and use the given action after the layer is /// added to the parent. The parameter can be the index or it can be the tag of the layer. /// </summary> /// <param name="n">Send in NoLayer to hide all multiplexed layers. Otherwise, send in a tag or the logical index of the /// layer to show.</param> /// <returns>The layer that is going to be shown. This can return null if the SwitchTo layer is NoLayer</returns> public CCLayer SwitchTo(int n) { if (n != -1) { if (m_nEnabledLayer == n || m_nEnabledLayer == (n + kTagOffsetForUniqueness)) { // no-op if (m_nEnabledLayer == -1) { return(null); } return(m_pLayers[m_nEnabledLayer]); } } if (m_nEnabledLayer != -1) { CCLayer outLayer = null; if (m_pLayers.ContainsKey(m_nEnabledLayer)) { outLayer = m_pLayers[m_nEnabledLayer]; if (m_OutAction != null) { outLayer.RunAction( new CCSequence( (CCFiniteTimeAction)m_OutAction.Copy(), new CCCallFunc(() => RemoveChild(outLayer, true)) ) ); } else { RemoveChild(outLayer, true); } } // We have no enabled layer at this point m_nEnabledLayer = NoLayer; } // When NoLayer, the multiplexer shows nothing. if (n == NoLayer) { ShowFirstLayerOnEnter = false; return(null); } if (!m_pLayers.ContainsKey(n)) { int f = n + kTagOffsetForUniqueness; if (m_pLayers.ContainsKey(f)) { n = f; } else { // Invalid index - layer not found return(null); } } // Set the active layer AddChild(m_pLayers[n]); m_nEnabledLayer = n; // Run the in-action on the new layer if (m_InAction != null) { m_pLayers[n].RunAction(m_InAction.Copy()); } return(m_pLayers[m_nEnabledLayer]); }
public override void OnEnter() { base.OnEnter(); this.TouchEnabled = true; CCSize s = CCDirector.SharedDirector.WinSize; CCLayerColor layer1 = new CCLayerColor(new CCColor4B(0xFF, 0xFF, 0x00, 0x80), s.Width * 0.75f, s.Height * 0.75f); layer1.IgnoreAnchorPointForPosition = false; layer1.Position = (new CCPoint(s.Width / 2, s.Height / 2)); layer1.ChildClippingMode = CCClipMode.Bounds; AddChild(layer1, 1); s = layer1.ContentSize; m_pInnerLayer = new CCLayerColor(new CCColor4B(0xFF, 0x00, 0x00, 0x80), s.Width * 0.5f, s.Height * 0.5f); m_pInnerLayer.IgnoreAnchorPointForPosition = false; m_pInnerLayer.Position = (new CCPoint(s.Width / 2, s.Height / 2)); m_pInnerLayer.ChildClippingMode = CCClipMode.Bounds; layer1.AddChild(m_pInnerLayer, 1); // // Add two labels using BM label class // CCLabelBMFont CCLabelBMFont label1 = new CCLabelBMFont("LABEL1", "fonts/konqa32.fnt"); label1.Position = new CCPoint(m_pInnerLayer.ContentSize.Width, m_pInnerLayer.ContentSize.Height * 0.75f); m_pInnerLayer.AddChild(label1); CCLabelBMFont label2 = new CCLabelBMFont("LABEL2", "fonts/konqa32.fnt"); label2.Position = new CCPoint(0, m_pInnerLayer.ContentSize.Height * 0.25f); m_pInnerLayer.AddChild(label2); float runTime = 12f; CCScaleTo scaleTo2 = new CCScaleTo(runTime * 0.25f, 3.0f); CCScaleTo scaleTo3 = new CCScaleTo(runTime * 0.25f, 1.0f); CCFiniteTimeAction seq = new CCRepeatForever( new CCSequence(scaleTo2, scaleTo3) ); m_pInnerLayer.RunAction(seq); CCSize size = CCDirector.SharedDirector.WinSize; var move1 = new CCMoveTo(2, new CCPoint(size.Width / 2, size.Height)); var move2 = new CCMoveTo(2, new CCPoint(size.Width, size.Height / 2)); var move3 = new CCMoveTo(2, new CCPoint(size.Width / 2, 0)); var move4 = new CCMoveTo(2, new CCPoint(0, size.Height / 2)); layer1.RunAction(new CCRepeatForever(new CCSequence(move1, move2, move3, move4))); }