I'm a little stuck and wondering if anyone could point me in the right direction.
I have created a button using the menu item. I want to move a sprite up or down when the button is touched.
Here's the code sample that I'm working with:
enum {
kTagSprite = 1,
};
@implementation FourScene
-(id) init {
self = [super init];
if(self != nil) {
[self addChild: [FourLayer node] z:0];
[self addChild:[MenuLayerFour node] z:0];
}
return self;
}
@end
@implementation MenuLayerFour
- (id) init {
self = [super init];
if (self != nil) {
MenuItem *round = [MenuItemImage itemFromNormalImage:@"greySquare.png" selectedImage:@"redSquare.png" target:self selector:@selector(round:)];
Menu *menu = [Menu menuWithItems:round, nil];
//[menu alignItemsVertically];
round.position = ccp(0,-200);
[self addChild:menu];
}
return self;
}
<----I KNOW I NEED TO CHANGE THIS BELOW BUT AM UNSURE HOW---->
<----This is what I would use to load a new scene--------->
-(void)round: (id)sender {
Sprite * two = [ThreeScene node];
[[Director sharedDirector] replaceScene:two];
}
<-------------------------------------------------------->
@implementation FourLayer
-(id) init {
self = [super init];
if(self != nil) {
isTouchEnabled = YES;
Sprite *redstripe = [Sprite spriteWithFile:@"redStripe.png"];
redstripe.position = ccp(160,240);
[self addChild: redstripe z:1 tag:kTagSprite];
}
return self;
}
- (BOOL)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView: [touch view]];
CGPoint convertedLocation = [[Director sharedDirector] convertToGL:location];
CocosNode *s = [self getChildByTag:kTagSprite];
[s stopAllActions];
[s runAction: [MoveTo actionWithDuration:0.5f position:ccp(convertedLocation.x, convertedLocation.y)]];
return kEventHandled;
}
@end
Any help is always appreciated.
Demetrius