刚刚开始学COCOS2D,在CCMenu中的菜单按键事件中,有按下的效果,但是没有回调按键指定的函数,求教啊~~ 5
publicvoidmenuText(){removeChild(intro,true);CGSizewinSize=CCDirector.sharedDirector(...
public void menuText()
{
removeChild(intro, true);
CGSize winSize = CCDirector.sharedDirector().displaySize();
menu = CCSprite.sprite("menubg.png");
menu.setPosition(CGPoint.ccp(menu.getContentSize().width / 2.0f, winSize.height / 2.0f));
CCMenuItemFont.setFontSize(15);
CCMenuItemFont.setFontName("Marker Felt");
CCMenuItemFont newGame = CCMenuItemFont.item("New Game");
// CCMenuItemFont newGame = CCMenuItemFont.item("New Game", this, selector)
CCMenuItemFont InsGame = CCMenuItemFont.item("Instaction",this,"instr");
// CCLabel label, CCNode rec, String cb
CCMenuItemFont snd = CCMenuItemFont.item("Sound on");
CCMenuItemFont ab = CCMenuItemFont.item("About FuguMobile");
CCMenuItemFont exit = CCMenuItemFont.item("Exit");
CCMenu mu= CCMenu.menu(newGame,InsGame,snd,ab,exit);
mu.setPosition(CGPoint.ccp(130.0f,130.0f));
mu.alignItemsVertically(10.0f);
// mu.ccAccelerometerChanged(10.0f, 10.0f, 0.0f);
addChild(menu);
addChild(mu);
// menu.setTag(2);
}
public void instr()
{
inst = CCSprite.sprite("inst.png");
CGSize winSize = CCDirector.sharedDirector().displaySize();
inst.setPosition(CGPoint.ccp(inst.getContentSize().width / 2.0f, winSize.height / 2.0f));
addChild(inst);
// intro.setTag(3);
}
public boolean ccTouchesEnded(MotionEvent event)
{
intro.runAction(CCSequence.actions(CCCallFuncN.action(this, "spriteMoveFinished")));
return true;
}
public void spriteMoveFinished(Object sender)
{
CCSprite sprite = (CCSprite)sender;
if (sprite.getTag() == 1)
{
menuText();
}
// if(sprite.getTag() == 3)
// {
// menuText();
// }
this.removeChild(sprite, true);
}
这是原码,求教~~ 展开
{
removeChild(intro, true);
CGSize winSize = CCDirector.sharedDirector().displaySize();
menu = CCSprite.sprite("menubg.png");
menu.setPosition(CGPoint.ccp(menu.getContentSize().width / 2.0f, winSize.height / 2.0f));
CCMenuItemFont.setFontSize(15);
CCMenuItemFont.setFontName("Marker Felt");
CCMenuItemFont newGame = CCMenuItemFont.item("New Game");
// CCMenuItemFont newGame = CCMenuItemFont.item("New Game", this, selector)
CCMenuItemFont InsGame = CCMenuItemFont.item("Instaction",this,"instr");
// CCLabel label, CCNode rec, String cb
CCMenuItemFont snd = CCMenuItemFont.item("Sound on");
CCMenuItemFont ab = CCMenuItemFont.item("About FuguMobile");
CCMenuItemFont exit = CCMenuItemFont.item("Exit");
CCMenu mu= CCMenu.menu(newGame,InsGame,snd,ab,exit);
mu.setPosition(CGPoint.ccp(130.0f,130.0f));
mu.alignItemsVertically(10.0f);
// mu.ccAccelerometerChanged(10.0f, 10.0f, 0.0f);
addChild(menu);
addChild(mu);
// menu.setTag(2);
}
public void instr()
{
inst = CCSprite.sprite("inst.png");
CGSize winSize = CCDirector.sharedDirector().displaySize();
inst.setPosition(CGPoint.ccp(inst.getContentSize().width / 2.0f, winSize.height / 2.0f));
addChild(inst);
// intro.setTag(3);
}
public boolean ccTouchesEnded(MotionEvent event)
{
intro.runAction(CCSequence.actions(CCCallFuncN.action(this, "spriteMoveFinished")));
return true;
}
public void spriteMoveFinished(Object sender)
{
CCSprite sprite = (CCSprite)sender;
if (sprite.getTag() == 1)
{
menuText();
}
// if(sprite.getTag() == 3)
// {
// menuText();
// }
this.removeChild(sprite, true);
}
这是原码,求教~~ 展开
2个回答
展开全部
我着实没看懂你事歼物怎么写的。至少应该有:
CCMenuItemFont *font = [CCMenuItemFont itemWithTarget:self selector:@selector(myMethod:)];吧!现在没有selector添加的地方啊!
这里有一个CCMenu的例子;
CCMenuItem *starMenuItem = [CCMenuItemImage itemFromNormalImage:@"ButtonStar.png" selectedImage:@"ButtonStarSel.png" target:self
selector:@selector(starButtonTapped:)];
starMenuItem.position = ccp(60, 60);
CCMenu *starMenu = [CCMenu menuWithItems:starMenuItem, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];
然后敏伏相应函数starButtonTapped,就可以有氏拿液相应了。
CCMenuItemFont *font = [CCMenuItemFont itemWithTarget:self selector:@selector(myMethod:)];吧!现在没有selector添加的地方啊!
这里有一个CCMenu的例子;
CCMenuItem *starMenuItem = [CCMenuItemImage itemFromNormalImage:@"ButtonStar.png" selectedImage:@"ButtonStarSel.png" target:self
selector:@selector(starButtonTapped:)];
starMenuItem.position = ccp(60, 60);
CCMenu *starMenu = [CCMenu menuWithItems:starMenuItem, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];
然后敏伏相应函数starButtonTapped,就可以有氏拿液相应了。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询