0
-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint location = [touch locationInView:[touch view]];
    CGPoint convertedlocation = [[CCDirector sharedDirector] convertToGL:location];  
    bb=[CCMenuItemImage itemFromNormalImage:@"Aqua-ball.png" selectedImage:@"Aqua-ball.png" target:self selector:@selector(move:)];
    menu1=[CCMenu menuWithItems:bb, nil];

    //ignore this.....

}

-(void) move:(CGPoint) touch{
    [character runAction:[CCMoveTo actionWithDuration:1 position:ccp(touch.x,touch.y)]];
}

我试图制作 CCmenuitem 选择器:@selector(move:converted location),但它似乎无法接受参数,是否有一些这样做我可以传递参数。

4

1 回答 1

0

我认为没有办法以这种方式传递参数。有很多方法可以做你想做的事。这就是我要做的:

首先添加一个实例变量,例如CGPoint lastTouchLocation实现。然后像这样使用它:

-(void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
    CGPoint location = [touch locationInView:[touch view]];
    CGPoint convertedlocation = [[CCDirector sharedDirector] convertToGL:location];

    lastTouchLocation = convertedLocation;
    bb=[CCMenuItemImage itemFromNormalImage:@"Aqua-ball.png" selectedImage:@"Aqua-ball.png" target:self selector:@selector(buttonTapped)];

    menu1=[CCMenu menuWithItems:bb, nil];    
}

-(void) buttonTapped {
    [character runAction:[CCMoveTo actionWithDuration:1 position:lastTouchLocation]];
}
于 2012-08-30T03:26:06.303 回答