@@ -4,6 +4,7 @@ namespace Cocos2D
44{
55 public class CCMenuItemSprite : CCMenuItem
66 {
7+ protected float m_fOriginalScale ;
78 private CCNode m_pDisabledImage ;
89 private CCNode m_pNormalImage ;
910
@@ -86,6 +87,7 @@ public override bool Enabled
8687 public CCMenuItemSprite ( )
8788 : this ( null , null , null , null )
8889 {
90+ ZoomBehaviorOnTouch = false ;
8991 }
9092
9193 public CCMenuItemSprite ( Action < object > selector )
@@ -125,6 +127,11 @@ public CCMenuItemSprite(CCNode normalSprite, CCNode selectedSprite, CCNode disab
125127 CascadeOpacityEnabled = true ;
126128 }
127129
130+ /// <summary>
131+ /// Set this to true if you want to zoom-in/out on the button image like the CCMenuItemLabel works.
132+ /// </summary>
133+ public bool ZoomBehaviorOnTouch { get ; set ; }
134+
128135 public override void Selected ( )
129136 {
130137 base . Selected ( ) ;
@@ -144,6 +151,22 @@ public override void Selected()
144151 else
145152 {
146153 m_pNormalImage . Visible = true ;
154+ if ( ZoomBehaviorOnTouch )
155+ {
156+ CCAction action = GetActionByTag ( unchecked ( ( int ) kZoomActionTag ) ) ;
157+ if ( action != null )
158+ {
159+ StopAction ( action ) ;
160+ }
161+ else
162+ {
163+ m_fOriginalScale = Scale ;
164+ }
165+
166+ CCAction zoomAction = new CCScaleTo ( 0.1f , m_fOriginalScale * 1.2f ) ;
167+ zoomAction . Tag = unchecked ( ( int ) kZoomActionTag ) ;
168+ RunAction ( zoomAction ) ;
169+ }
147170 }
148171 }
149172 }
@@ -158,6 +181,13 @@ public override void Unselected()
158181 if ( m_pSelectedImage != null )
159182 {
160183 m_pSelectedImage . Visible = false ;
184+ if ( ZoomBehaviorOnTouch )
185+ {
186+ StopActionByTag ( unchecked ( ( int ) kZoomActionTag ) ) ;
187+ CCAction zoomAction = new CCScaleTo ( 0.1f , m_fOriginalScale ) ;
188+ zoomAction . Tag = unchecked ( ( int ) kZoomActionTag ) ;
189+ RunAction ( zoomAction ) ;
190+ }
161191 }
162192
163193 if ( m_pDisabledImage != null )
@@ -167,6 +197,19 @@ public override void Unselected()
167197 }
168198 }
169199
200+ public override void Activate ( )
201+ {
202+ if ( m_bIsEnabled )
203+ {
204+ if ( ZoomBehaviorOnTouch )
205+ {
206+ StopAllActions ( ) ;
207+ Scale = m_fOriginalScale ;
208+ }
209+ base . Activate ( ) ;
210+ }
211+ }
212+
170213 // Helper
171214 private void UpdateImagesVisibility ( )
172215 {
0 commit comments