public CCControlSwitch(CCSprite maskSprite, CCSprite onSprite, CCSprite offSprite, CCSprite thumbSprite, CCLabel onLabel, CCLabel offLabel) { Debug.Assert(maskSprite != null, "Mask must not be nil."); Debug.Assert(onSprite != null, "onSprite must not be nil."); Debug.Assert(offSprite != null, "offSprite must not be nil."); Debug.Assert(thumbSprite != null, "thumbSprite must not be nil."); on = true; switchSprite = new CCControlSwitchSprite(maskSprite, onSprite, offSprite, thumbSprite, onLabel, offLabel); switchSprite.Position = new CCPoint(switchSprite.ContentSize.Width / 2, switchSprite.ContentSize.Height / 2); AddChild(switchSprite); IgnoreAnchorPointForPosition = false; AnchorPoint = new CCPoint(0.5f, 0.5f); ContentSize = switchSprite.ContentSize; // Register Touch Event var touchListener = new CCEventListenerTouchOneByOne(); touchListener.IsSwallowTouches = true; touchListener.OnTouchBegan = OnTouchBegan; touchListener.OnTouchMoved = OnTouchMoved; touchListener.OnTouchEnded = OnTouchEnded; touchListener.OnTouchCancelled = OnTouchCancelled; AddEventListener(touchListener); }