在android中添加cocos2d菜单
我是 android 新手。我正在使用 cocos2d 添加菜单。我可以成功添加菜单。但无法识别选择了哪个菜单项。我在下面给出了我的代码。请帮助。
for(int i=0;i<len;i++){
asn = CCMenuItemImage.item("ans_btn.png", "ans_btn_glow.png", "ans_btn.png", this, "check");
asn.setTag(i+1);
CCMenuItem[]item={asn};
menu = CCMenu.menu(item);
menu.setPosition(CGPoint.ccp(170,val));
addChild(menu);
val+=60;
}
public void check(){
// CCMenuItem answ=(CCMenuItem)sender;
String allert= null;
//CCMenuItem answ = sender;
//int check = answ.getTag();
int i =asn.getTag();
String str = Integer.toString(i);
String str1 = Integer.toString(rans);
if(i== rans)
allert = "right";
else
allert= "wrong";
CCLabel pop = CCLabel.makeLabel(str1, "DroidSans", 18);
pop.setPosition(CGPoint.ccp(200, 50));
addChild(pop);
CCLabel pop1 = CCLabel.makeLabel(str, "DroidSans", 18);
pop1.setPosition(CGPoint.ccp(200, 100));
addChild(pop1);
}
I am new in android.I am working with cocos2d for adding a menu.I can successfully add the menu. But can not identify which menu item is selected.I have given my code below.Plz help.
for(int i=0;i<len;i++){
asn = CCMenuItemImage.item("ans_btn.png", "ans_btn_glow.png", "ans_btn.png", this, "check");
asn.setTag(i+1);
CCMenuItem[]item={asn};
menu = CCMenu.menu(item);
menu.setPosition(CGPoint.ccp(170,val));
addChild(menu);
val+=60;
}
public void check(){
// CCMenuItem answ=(CCMenuItem)sender;
String allert= null;
//CCMenuItem answ = sender;
//int check = answ.getTag();
int i =asn.getTag();
String str = Integer.toString(i);
String str1 = Integer.toString(rans);
if(i== rans)
allert = "right";
else
allert= "wrong";
CCLabel pop = CCLabel.makeLabel(str1, "DroidSans", 18);
pop.setPosition(CGPoint.ccp(200, 50));
addChild(pop);
CCLabel pop1 = CCLabel.makeLabel(str, "DroidSans", 18);
pop1.setPosition(CGPoint.ccp(200, 100));
addChild(pop1);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我解决了。这个问题是因为cocos2d的版本问题。后来的cocos2d版本解决了这个问题。
I solved it .The problem arises because of the version of cocos2d.The later version of cocos2d solves the problem.
您可以使用菜单并在其中分配一个选择器,因此您无需检查计划方法中的单击
我已经使用了菜单,因为
您可以在适当的位置使用菜单
,
或者
现在添加菜单
定义为:
,方法 单击菜单时自动调用
You can use the menu and assign a selector in that, so you have not need to check click in scheduled method
I have used the menues as
you can use menu in proper location as
or
or
now add menu
and methods are defined as:
the methods auto called when menu clicked