cocos2d-iphone 编程问题

请各位大神解释一下,我想在窗口建一个可以点击变色的小方块,可为什么每次点击小方块变色后程序就停止出现错误了,感激不尽啊,

以下是代码:

-(id) init

{

// always call "super" init

// Apple recommends to re-assign "self" with the "super's" return value

if( (self=super init]) ){

CGSize size=CCDirector sharedDirector] winSize];

CCSprite*turnleftsprite=CCSprite spriteWithFile:@"turnleft.png"];

CCSprite*turnleftsprite2=CCSprite spriteWithFile:@"turnleft.png"];

turnleftsprite2.color=ccBLUE;

CCMenuItemSprite*item2=

CCMenuItemSprite itemFromNormalSprite:turnleftsprite selectedSprite:turnleftsprite2 target:self selector:@selector(menu: item2Touched: )];

CCMenu*menu=CCMenu menuWithItems:item2, nil];

menu.position=CGPointMake(size.width/2,size.height/2);

self addChild:menu];

}

return self;

}

以下是debug结果:

cocos2d: cocos2d-iphone v2.1-rc0a

cocos2d: compiled with Profiling Support: NO

cocos2d: OS version: 6.1 (0x06010000)

cocos2d: GL_VENDOR: Apple Computer, Inc.

cocos2d: GL_RENDERER: Apple Software Renderer

cocos2d: GL_VERSION: OpenGL ES 2.0 APPLE

cocos2d: GL_MAX_TEXTURE_SIZE: 4096

cocos2d: GL_MAX_TEXTURE_UNITS: 8

cocos2d: GL_MAX_SAMPLES: 4

cocos2d: GL supports PVRTC: YES

cocos2d: GL supports BGRA8888 textures: YES

cocos2d: GL supports NPOT textures: YES

cocos2d: GL supports discard_framebuffer: YES

cocos2d: GL supports shareable VAO: NO

2013-03-20 21:29:24.843 anjian Retina Display Not supported

2013-03-20 21:29:24.849 anjian cocos2d: animation started with frame interval: 60.00

2013-03-20 21:29:24.851 anjian cocos2d: surface size: 480x320

2013-03-20 21:29:24.854 anjian cocos2d: CCTexture2D: Using RGB565 texture since image has no alpha

2013-03-20 21:29:27.034 anjian -: unrecognized selector sent to instance 0x93382c0

2013-03-20 21:29:27.036 anjian *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-: unrecognized selector sent to instance 0x93382c0'

*** First throw call stack:

(0x2507012 0x1ee4e7e 0x25924bd 0x24f6bbc 0x24f694e 0x1ef86b0 0x54ac5 0x524bc 0x4fc49 0x1ef8705 0xba8cf 0xbb463 0xb846e 0xae6cef 0xae6f02 0xac4d4a 0xab6698 0x320fdf9 0x320fad0 0x247cbf5 0x247c962 0x24adbb6 0x24acf44 0x24ace1b 0x320e7e3 0x320e668 0xab3ffc 0xdcd76 0x23c5)

libc++abi.dylib: terminate called throwing an exception

(lldb)


HelloWorldLayer menu:item2Touched: 找不到这个办法。

貌似selector只支持一个参数的。 或者你这拼写方式不对,用xcode的自动完成方式看看是怎么拼写的。

谢谢,可xcode自动完成方式怎么用

在代码里打menu,弹出下拉列表。

亲,,咋就带了 倆参数函数呢… 一起响应会出错吧

可是我把参数写成menuitem2touched:连颜色都变不了啊

CCMenuItem的selector只能是-(void)action:(id)sender这种类型的SEL对象

那么请问一下您怎么修改该代码呢?