/// <summary> /// /// </summary> /// <param name="vel"></param> /// <param name="dt"></param> public void UpdateWithVelocity(CCPoint vel, float dt) { CCSize screen = CCDirector.SharedDirector.WinSize; CCPoint vel2 = vel * PTMRatio; for (int i = m_ScrollOffsets.Count - 1; i >= 0; i--) { CCParallaxScrollOffset scrollOffset = m_ScrollOffsets[i]; CCNode child = scrollOffset.Child; CCPoint relVel = scrollOffset.RelativeVelocity * PTMRatio; CCPoint totalVel = vel2 + relVel; CCPoint offset = (totalVel * dt); offset = offset * scrollOffset.Ratio; child.Position = child.Position + offset; if ((vel2.X < 0f && child.Position.X + child.ContentSize.Width < 0) || (vel2.X > 0 && child.Position.X > screen.Width)) { child.Position = child.Position + new CCPoint((vel2.X < 0f ? 1 : -1) * Math.Abs(scrollOffset.Offset.X), 0f); } // Positive y indicates upward movement in cocos2d if ((vel2.Y < 0 && child.Position.Y + child.ContentSize.Height < 0f) || (vel2.Y > 0 && child.Position.Y > screen.Height)) { child.Position = child.Position + new CCPoint(0f, (vel2.Y < 0f ? 1f : -1f) * Math.Abs(scrollOffset.Offset.Y)); } } }
/// <summary> /// /// </summary> /// <param name="y"></param> /// <param name="dt"></param> public void UpdateWithYPosition(float y, float dt) { for (int i = m_ScrollOffsets.Count - 1; i >= 0; i--) { CCParallaxScrollOffset scrollOffset = m_ScrollOffsets[i]; CCNode child = scrollOffset.Child; float offset = y * scrollOffset.Ratio.Y;//ccpCompMult(pos, scrollOffset.ratio); child.Position = new CCPoint(child.Position.X, scrollOffset.OriginalPosition.Y + offset); } }
public void AddChild(CCSprite node, int z, CCPoint r, CCPoint p, CCPoint s, CCPoint v) { node.AnchorPoint = CCPoint.Zero; CCParallaxScrollOffset obj = new CCParallaxScrollOffset(node, r, p, s, v); m_ScrollOffsets.Add(obj); if (m_Batch != null) { m_Batch.AddChild(node, z); } else { base.AddChild(node, z); } }
public void AddChild(CCSprite node, int z, CCPoint r, CCPoint p, CCPoint s, CCPoint v) { node.AnchorPoint = CCPoint.Zero; CCParallaxScrollOffset obj = new CCParallaxScrollOffset(node, r, p, s, v); m_ScrollOffsets.Add(obj); if (m_Batch != null) { m_Batch.AddChild(node, z); } else { base.AddChild(node, z); } }
public void RemoveChild(CCSprite node, bool cleanup) { int removeAt = -1; for (int i = 0; i < m_ScrollOffsets.Count; i++) { CCParallaxScrollOffset scrollOffset = m_ScrollOffsets[i]; if (scrollOffset.Child == node) { removeAt = i; break; } } if (removeAt != -1) { m_ScrollOffsets.RemoveAt(removeAt); } if (m_Batch != null) { m_Batch.RemoveChild(node, cleanup); } }