Yeah... Where are you setting the new position? The AtlasSpriteManager or the AtlasMenu? I think they have to be in the same origin (position).. That's a limitation of MenuItemAtlasSprite... It's explained somewhere in the release notes or in this forum, somewhere... :)
Looping/Scrolling Menu
(51 posts) (26 voices)-
Posted 2 years ago #
-
Allright, thank you Joao!
I'll investigate this topic later on - for this release i'll use normal MenuItemSprites - with them it's working perfect.
Posted 2 years ago # -
Hello,
Today I ported it over to cocos2d 0.99-final.
Here is the zip: http://dl.dropbox.com/u/3314174/loopingmenu.zipIt works on simulator and device.
Posted 2 years ago # -
Can you upload the loopingmenu.zipo file again somehow? The link is bad. ;(
Posted 2 years ago # -
The link is working again: http://dl.dropbox.com/u/3314174/loopingmenu.zip
Posted 2 years ago # -
For what it's worth, I also added a post to my blog about using this excellent looping code in v0.99 with both text and graphic menu items as well as provided a sample project.
It can be viewed here: pocketworx.com
Posted 2 years ago # -
Wow! this is really really nice. I can't wait to use it in my app.
Posted 2 years ago # -
I'm playing with your code and I have some weird issue: After dragging any MenuItem, I receive a ccTouchCancelled.
Is that the expected behaviour?Posted 1 year ago # -
If you are dragging offscreen or touching with too many fingers at once, you will get that. Is that the case?
Posted 1 year ago # -
While building my project with SDK4 and cocos2d > .99.3 , I get a compiler warning "CCMenu may not respond to itemForTouch" and then while running on the device, I get a crash when touching an item from the LoopingMenu.
Is there a fix for this that I haven't seen?
Thanks!
EDIT: Just to be clear, I don't get this warning with SDK3.2.
Posted 1 year ago # -
How do I change this menu to scroll vertical instead?
I get that warning too.Posted 1 year ago # -
freeforce +1
i need it in vertical scroll....thanx!
Posted 1 year ago # -
Hey everyone,
I'm trying to implement this, but I get an
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'when I have touch events on my layer as well as the looping menu implemented. If I remove the looping menu, then everything is ok... thoughts?
Posted 1 year ago # -
If anybody wants this you can take Techy's code and add these to LoopingMenu.h:
int state; CCMenuItem *selectedItem;And add this to LoopingMenu.mm:
enum { kMenuStateTrackingTouch = 1, kMenuStateWaiting = 2, };I also commented out isAccelerometerEnabled = true; That gets rid of compiler warnings/errors and it works in 99.5.
Posted 1 year ago # -
I've tried to use Looping Menu and it was unsuccsesfull because of CCMenu has changed since the looping class was updated. state now is state_ , constants changed, and some others changes. Here is workable code:
LoopingMenu.mm/* * LoopingMenu.mm * Banzai * * Created by João Caxaria on 5/29/09. * Copyright 2009 Imaginary Factory. All rights reserved. * */ #import "LoopingMenu.h" #import "InputController.h" #import "cocos2d.h" #import "CCMenu.h" /* @interface CCMenu // returns touched menu item, if any, implemented in Menu.m -(CCMenuItem *) itemForTouch: (UITouch *) touch; @end */ /* enum { kMenuStateTrackingTouch = 1, kMenuStateWaiting = 2, }; */ @interface LoopingMenu (Animation) -(void) updateAnimation; -(void) moveItemsLeftBy:(float) offset; -(void) moveItemsRightBy:(float) offset; @end @implementation LoopingMenu @synthesize yOffset; #pragma mark - #pragma mark Menu -(void) alignItemsVerticallyWithPadding:(float)padding { [self alignItemsHorizontallyWithPadding:padding]; } -(void) alignItemsHorizontallyWithPadding:(float)padding { // isAccelerometerEnabled = YES; accelerometerVelocity = 0; [[UIAccelerometer sharedAccelerometer] setUpdateInterval:1.0/60.0]; hPadding = padding; lowerBound = [(CCMenuItem*)[children_ objectAtIndex:0] contentSize].height / 2.0; [super alignItemsHorizontallyWithPadding:padding]; [self updateAnimation]; } -(void) registerWithTouchDispatcher { [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:INT_MIN+1 swallowsTouches:false]; } #pragma mark - #pragma mark Accelerometer - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { if(touchDown) return; float x = acceleration.y; float y = acceleration.x; float tVectorLength=sqrt(x*x+y*y); if(tVectorLength == 0) return; float xTilt=-5.0f*x/tVectorLength; accelerometerVelocity = (accelerometerVelocity * 4.0 + xTilt) / 5.0; if(accelerometerVelocity < 0) [self moveItemsLeftBy:accelerometerVelocity]; else if(accelerometerVelocity > 0) [self moveItemsRightBy:accelerometerVelocity]; } #pragma mark - #pragma mark Touches -(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event { if([[event allTouches] count] != 1) return false; touchDown = true; moving = false; selectedItem_ = [super itemForTouch:touch]; [selectedItem_ selected]; state_ = kCCMenuStateTrackingTouch; return true; } -(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event { if([[event allTouches] count] != 1) { [self ccTouchCancelled:touch withEvent:event]; return; } if(!moving && state_ == kCCMenuStateTrackingTouch) [super ccTouchEnded:touch withEvent:event]; else if(state_ == kCCMenuStateTrackingTouch) [self ccTouchCancelled:touch withEvent:event]; moving = false; touchDown = false; } -(void) ccTouchCancelled:(UITouch *)touch withEvent:(UIEvent *)event { [selectedItem_ unselected]; touchDown = false; state_ = kCCMenuStateWaiting; moving = false; } -(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event { if([[event allTouches] count] != 1) { [self ccTouchCancelled:touch withEvent:event]; return; } NSMutableSet* touches = [[[NSMutableSet alloc] initWithObjects:touch, nil] autorelease]; CGPoint distance = icDistance(1, touches, event); if(icWasSwipeLeft(touches, event) && distance.y < distance.x) { moving = true; [self moveItemsLeftBy:-distance.x]; } else if(icWasSwipeRight(touches, event) && distance.y < distance.x) { moving = true; [self moveItemsRightBy:distance.x]; } else if(!moving && state_ == kCCMenuStateTrackingTouch) { [super ccTouchMoved:touch withEvent:event]; } } @end @implementation LoopingMenu (Animation) -(void) moveItemsLeftBy:(float) offset { [selectedItem_ unselected]; for(CCMenuItem<CCRGBAProtocol>* item in children_) { [item setPosition:ccpAdd([item position], ccp(offset, 0))]; } CCMenuItem* leftItem = [children_ objectAtIndex:0]; if([leftItem position].x + [self position].x + [leftItem contentSize].width / 2.0 < 0) { //[[SimpleAudioEngine sharedEngine] playEffect:@"dragteam.caf"]; [leftItem retain]; [children_ removeObjectAtIndex:0]; CCMenuItem* lastItem = [children_ objectAtIndex:[children_ count] - 1]; [leftItem setPosition:ccpAdd([lastItem position], ccp([lastItem contentSize].width / 2.0 + [leftItem contentSize].width / 2.0 + hPadding, 0))]; [children_ addObject:leftItem]; [leftItem autorelease]; } [self updateAnimation]; } -(void) moveItemsRightBy:(float) offset { [selectedItem_ unselected]; for(CCMenuItem<CCRGBAProtocol>* item in children_) { [item setPosition:ccpAdd([item position], ccp(offset, 0))]; } CCMenuItem* lastItem = [children_ objectAtIndex:[children_ count] - 1]; if([lastItem position].x + [self position].x - [lastItem contentSize].width / 2.0 > 480) { //[[SimpleAudioEngine sharedEngine] playEffect:@"dragteam.caf"]; [lastItem retain]; [children_ removeObjectAtIndex:[children_ count] - 1]; CCMenuItem* firstItem = [children_ objectAtIndex:0]; [lastItem setPosition:ccpSub([firstItem position], ccp([firstItem contentSize].width / 2.0 + [lastItem contentSize].width / 2.0 + hPadding, 0))]; [children_ insertObject:lastItem atIndex:0]; [lastItem autorelease]; } [self updateAnimation]; } -(void) updateAnimation { static float quadraticCoefficient = -1.0/90000.0; //1/300^ for(CCMenuItem<CCRGBAProtocol>* item in children_) { float distance = fabsf([item position].x - 240.0 + [self position].x); if(distance > 240.0) distance = 240.0; else if(distance < 0.0) distance = 0.0; float ratio = quadraticCoefficient * (distance*distance) + 1; [item setScale: ratio]; [item setOpacity:ratio * 255.0]; [item setPosition:ccp([item position].x, yOffset - (lowerBound - [item contentSize].height * ratio / 2.0))]; } } @endLoopingMenu.h
/* * LoopingMenu.h * Banzai * * Created by João Caxaria on 5/29/09. * Copyright 2009 Imaginary Factory. All rights reserved. * */ #import "cocos2d.h" #import "SimpleAudioEngine.h" /* typedef enum { kCCMenuStateWaiting, kCCMenuStateTrackingTouch } tCCMenuState; enum { //* priority used by the menu kCCMenuTouchPriority = -128, }; */ @interface LoopingMenu : CCMenu { float hPadding; float lowerBound; float yOffset; bool moving; bool touchDown; float accelerometerVelocity; //int state; //CCMenuItem *selectedItem; //tCCMenuState state_; //CCMenuItem *selectedItem_; //GLubyte opacity_; //ccColor3B color_; } @property float yOffset; @endInputController.h
/* * InputController.h * SweetDreams * * Created by João Caxaria on 4/28/09. * Copyright 2009 Feel Fine Games. All rights reserved. * */ #ifdef __cplusplus extern "C" { #endif static inline double _icPointLineComparison(CGPoint point, CGPoint lineA, CGPoint lineB) { return (0.5) * (lineA.x*lineB.y - lineA.y*lineB.x -point.x*lineB.y + point.y*lineB.x + point.x*lineA.y - point.y*lineA.x); } static inline CGPoint _icRotateRealWorld(CGPoint location) { return [[CCDirector sharedDirector] convertToGL:location]; } static inline CGFloat icDistanceBetweenTwoPoints(CGPoint fromPoint, CGPoint toPoint) { return ccpDistance(fromPoint, toPoint); } static inline bool icIsPointInside(CGPoint point, CGRect rect) { return CGRectContainsPoint(rect, point); } static inline int icFingerCount(NSSet * touches, UIEvent * event) { return [[event allTouches] count]; } static inline CGPoint icFingerLocation(int finger, NSSet * touches, UIEvent* event) { NSSet *allTouches = [event allTouches]; if(finger == 0 || finger > [allTouches count]) { #ifdef ASSERT_DEBUG { @throw [[[NSException alloc] initWithName:@"InputController::fingerLocation" reason:@"No such finger" userInfo:nil] autorelease]; } #endif return CGPointZero; } UITouch *touch = [[allTouches allObjects] objectAtIndex:finger - 1]; CGPoint location = [touch locationInView:[touch view]]; return _icRotateRealWorld(location); } static inline CGPoint icPreviousFingerLocation(int finger, NSSet * touches, UIEvent* event) { NSSet *allTouches = [event allTouches]; if(finger == 0 || finger > [allTouches count]) { #ifdef ASSERT_DEBUG { @throw [[[NSException alloc] initWithName:@"InputController::previousFingerLocation" reason:@"No such finger" userInfo:nil] autorelease]; } #endif return CGPointZero; } UITouch *touch = [[allTouches allObjects] objectAtIndex:finger - 1]; CGPoint location = [touch previousLocationInView:[touch view]]; return _icRotateRealWorld(location); } static inline bool icWasSwipeLeft(NSSet * touches, UIEvent *event) { NSSet *allTouches = [event allTouches]; if(1 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start = [touch previousLocationInView:[touch view]]; CGPoint end = [touch locationInView:[touch view]]; start = _icRotateRealWorld(start); end = _icRotateRealWorld(end); if(start.x > end.x) { return true; } return false; } static inline bool icWasSwipeRight(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(1 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start = [touch previousLocationInView:[touch view]]; CGPoint end = [touch locationInView:[touch view]]; start = _icRotateRealWorld(start); end = _icRotateRealWorld(end); if(start.x < end.x) { return true; } return false; } static inline bool icWasSwipeUp(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(1 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start = [touch previousLocationInView:[touch view]]; CGPoint end = [touch locationInView:[touch view]]; start = _icRotateRealWorld(start); end = _icRotateRealWorld(end); if(start.y < end.y) { return true; } return false; } static inline bool icWasSwipeDown(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(1 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start = [touch previousLocationInView:[touch view]]; CGPoint end = [touch locationInView:[touch view]]; start = _icRotateRealWorld(start); end = _icRotateRealWorld(end); if(start.y > end.y) { return true; } return false; } static inline bool icWasDragLeft(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(2 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start1 = [touch previousLocationInView:[touch view]]; CGPoint end1 = [touch locationInView:[touch view]]; start1 = _icRotateRealWorld(start1); end1 = _icRotateRealWorld(end1); touch = [[allTouches allObjects] objectAtIndex:1]; CGPoint start2 = [touch previousLocationInView:[touch view]]; CGPoint end2 = [touch locationInView:[touch view]]; start2 = _icRotateRealWorld(start2); end2 = _icRotateRealWorld(end2); if(start1.x > end1.x && start2.x > end2.x) { return true; } return false; } static inline bool icWasDragRight(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(2 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start1 = [touch previousLocationInView:[touch view]]; CGPoint end1 = [touch locationInView:[touch view]]; start1 = _icRotateRealWorld(start1); end1 = _icRotateRealWorld(end1); touch = [[allTouches allObjects] objectAtIndex:1]; CGPoint start2 = [touch previousLocationInView:[touch view]]; CGPoint end2 = [touch locationInView:[touch view]]; start2 = _icRotateRealWorld(start2); end2 = _icRotateRealWorld(end2); if(start1.x < end1.x && start2.x < end2.x) { return true; } return false; } static inline bool icWasDragUp(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(2 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start1 = [touch previousLocationInView:[touch view]]; CGPoint end1 = [touch locationInView:[touch view]]; start1 = _icRotateRealWorld(start1); end1 = _icRotateRealWorld(end1); touch = [[allTouches allObjects] objectAtIndex:1]; CGPoint start2 = [touch previousLocationInView:[touch view]]; CGPoint end2 = [touch locationInView:[touch view]]; start2 = _icRotateRealWorld(start2); end2 = _icRotateRealWorld(end2); if(start1.y < end1.y && start2.y < end2.y) { return true; } return false; } static inline bool icWasDragDown(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(2 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start1 = [touch previousLocationInView:[touch view]]; CGPoint end1 = [touch locationInView:[touch view]]; start1 = _icRotateRealWorld(start1); end1 = _icRotateRealWorld(end1); touch = [[allTouches allObjects] objectAtIndex:1]; CGPoint start2 = [touch previousLocationInView:[touch view]]; CGPoint end2 = [touch locationInView:[touch view]]; start2 = _icRotateRealWorld(start2); end2 = _icRotateRealWorld(end2); if(start1.y > end1.y && start2.y > end2.y) { return true; } return false; } static inline bool icWasZoomIn(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(2 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start1 = [touch previousLocationInView:[touch view]]; CGPoint end1 = [touch locationInView:[touch view]]; start1 = _icRotateRealWorld(start1); end1 = _icRotateRealWorld(end1); touch = [[allTouches allObjects] objectAtIndex:1]; CGPoint start2 = [touch previousLocationInView:[touch view]]; CGPoint end2 = [touch locationInView:[touch view]]; start2 = _icRotateRealWorld(start2); end2 = _icRotateRealWorld(end2); float initialDistance = icDistanceBetweenTwoPoints(start1, start2); float endDistance = icDistanceBetweenTwoPoints(end1, end2); if(endDistance > initialDistance) { return true; } return false; } static inline bool icWasZoomOut(NSSet * touches ,UIEvent * event) { NSSet *allTouches = [event allTouches]; if(2 != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; CGPoint start1 = [touch previousLocationInView:[touch view]]; CGPoint end1 = [touch locationInView:[touch view]]; start1 = _icRotateRealWorld(start1); end1 = _icRotateRealWorld(end1); touch = [[allTouches allObjects] objectAtIndex:1]; CGPoint start2 = [touch previousLocationInView:[touch view]]; CGPoint end2 = [touch locationInView:[touch view]]; start2 = _icRotateRealWorld(start2); end2 = _icRotateRealWorld(end2); float initialDistance = icDistanceBetweenTwoPoints(start1, start2); float endDistance = icDistanceBetweenTwoPoints(end1, end2); if(endDistance < initialDistance) { return true; } return false; } static inline bool icWasAClickGeneric(NSSet * touches, UIEvent *event, int fingers, int taps) { NSSet *allTouches = [event allTouches]; if(fingers != [allTouches count]) return false; UITouch *touch = [[allTouches allObjects] objectAtIndex:0]; return [touch phase] == UITouchPhaseEnded && [touch tapCount] == taps; } static inline bool icWasAClick(NSSet * touches ,UIEvent * event) { return icWasAClickGeneric(touches, event, 1, 1); } static inline bool icWasADoubleClick(NSSet * touches ,UIEvent * event) { return icWasAClickGeneric(touches, event, 1, 2); } static inline CGPoint icDistance(int finger, NSSet* touches, UIEvent* event) { NSSet *allTouches = [event allTouches]; if(finger == 0 || finger > [allTouches count]) return CGPointZero; UITouch *touch = [[allTouches allObjects] objectAtIndex:finger - 1]; CGPoint start1 = [touch previousLocationInView:[touch view]]; CGPoint end1 = [touch locationInView:[touch view]]; start1 = _icRotateRealWorld(start1); end1 = _icRotateRealWorld(end1); float xDistance = ( fabs(start1.x - end1.x)); float yDistance = ( fabs(start1.y - end1.y)); return CGPointMake(xDistance, yDistance); } #ifdef __cplusplus } #endifand usage example:
CCMenuItem *item1 = [CCMenuItemFont itemFromString:@"item1" target: self selector: @selector(doSomethingOne:)]; CCMenuItem *item2 = [CCMenuItemFont itemFromString:@"item2" target: self selector: @selector(doSomethingOne:)]; CCMenuItem *item3 = [CCMenuItemFont itemFromString:@"item3" target: self selector: @selector(doSomethingOne:)]; CCMenuItem *item4 = [CCMenuItemFont itemFromString:@"item4" target: self selector: @selector(doSomethingOne:)]; CCMenuItem *item5 = [CCMenuItemFont itemFromString:@"item5" target: self selector: @selector(doSomethingOne:)]; LoopingMenu *menu = [LoopingMenu menuWithItems:item1, item2, item3, item4, item5, nil]; menu.position = ccp(240, 270); [menu alignItemsHorizontallyWithPadding:20]; [self addChild:menu];Posted 1 year ago # -
http://dl.dropbox.com/u/19330475/looping.zip
here is packed classes for the latest cocos2d version, usage example 2 posts upperPosted 1 year ago # -
Isn't InputController.h doing the same thing as the native Gesture Recognizers?
Posted 1 year ago # -
I don't know if anyone has tried this using the latest cocos2d or even 0.99.5, but using the looping menu code seems to randomly crash - with not much detail at all to the console. Anyone else experience this? It only happens sometimes, not easy to reproduce.
Posted 11 months ago # -
I found out it crashes if it holds only one MenuItem.
Theres a bad access on children_.[children_ removeObjectAtIndex:0]; CCMenuItem* lastItem = [children_ objectAtIndex:[children_ count] - 1]; --> !objectAtIndex:-1!Something like this should fix it and the item will be repeated.
-(void) moveItemsLeftBy:(float) offset { [selectedItem_ unselected]; for(CCMenuItem<CCRGBAProtocol>* item in children_) { [item setPosition:ccpAdd([item position], ccp(offset, 0))]; } CCMenuItem* leftItem = [children_ objectAtIndex:0]; if([leftItem position].x + [self position].x + [leftItem contentSize].width / 2.0 < 0) { [[SimpleAudioEngine sharedEngine] playEffect:@"dragteam.caf"]; [leftItem retain]; [children_ removeObjectAtIndex:0]; CCMenuItem* lastItem; if ([children_ count] > 0) { lastItem = [children_ objectAtIndex:[children_ count] - 1]; } else { lastItem = leftItem; } [leftItem setPosition:ccpAdd([lastItem position], ccp([lastItem contentSize].width / 2.0 + [leftItem contentSize].width / 2.0 + hPadding, 0))]; [children_ addObject:leftItem]; [leftItem autorelease]; } [self updateAnimation]; } -(void) moveItemsRightBy:(float) offset { [selectedItem_ unselected]; for(CCMenuItem<CCRGBAProtocol>* item in children_) { [item setPosition:ccpAdd([item position], ccp(offset, 0))]; } CCMenuItem* lastItem = [children_ objectAtIndex:[children_ count] - 1]; if([lastItem position].x + [self position].x - [lastItem contentSize].width / 2.0 > 480) { [[SimpleAudioEngine sharedEngine] playEffect:@"dragteam.caf"]; [lastItem retain]; [children_ removeObjectAtIndex:[children_ count] - 1]; CCMenuItem* firstItem; if ([children_ count]>0) { firstItem = [children_ objectAtIndex:0]; } else { firstItem = lastItem; } [lastItem setPosition:ccpSub([firstItem position], ccp([firstItem contentSize].width / 2.0 + [lastItem contentSize].width / 2.0 + hPadding, 0))]; [children_ insertObject:lastItem atIndex:0]; [lastItem autorelease]; } [self updateAnimation]; }Posted 10 months ago # -
this one is very useful article...
but I am working on Cocos2d-X, I port most of the InputController.h contents, but I got struct at UIEvent parameter in funtions. there is no UIEvent in cocos2d-x it replaced with CCEvent, can u help me out of it?for Example:
Inside InputController.h
static inline CGPoint icDistance(int finger, UIEvent* event)
{
NSSet *allTouches = [event allTouches];if(finger == 0 || finger > [allTouches count])
return ccp(CGPointZero.x,CGPointZero.y);UITouch *touch = [[allTouches allObjects] objectAtIndex:finger - 1];
CGPoint start1 = ccp([touch previousLocationInView:[touch view]].x,[touch previousLocationInView:[touch view]].y);
CGPoint end1 = ccp([touch locationInView:[touch view]].x,[touch locationInView:[touch view]].y);
start1 = _icRotateRealWorld(start1);
end1 = _icRotateRealWorld(end1);float xDistance = ( fabs(start1.x - end1.x));
float yDistance = ( fabs(start1.y - end1.y));
return CGPointMake(xDistance, yDistance);
}//inside your main layer class
void FenceLayer::ccTouchMoved(CCTouch* touch, CCEvent* event)
{NSMutableSet* touches = [[[NSMutableSet alloc] initWithObjects:touch, nil] autorelease]; //error Cannot initialize a parameter of type "id" with an lvalue of type 'cocos2d:ccTouch*'
CGPoint distance = icDistance(1, touches, event); //error No matching function call to icDistance -- here it is CCEvent in parameter
if(icWasSwipeLeft(touches, event) && distance.y < distance.x)//error
{
CCLog("Swipe Left......");
}
else if(icWasSwipeRight(touches, event) && distance.y < distance.x)//error
{
CCLog("Swipe Right......");
}}
Posted 1 month ago #
Reply
You must log in to post.