hello. Im new to game development and im just starting whit cocos 2d
I want to add a button to my scene, but im not sure how to do it.
Also to give it an action when it is pressed, but i think i know how to do it
Thanks
A fast, easy to use, free, and community supported 2D game engine
hello. Im new to game development and im just starting whit cocos 2d
I want to add a button to my scene, but im not sure how to do it.
Also to give it an action when it is pressed, but i think i know how to do it
Thanks
Oh, and sorry for my bad english. Is not my native language
Search the Forum for "MenuItem" and you will find examples...
Thanks, but thats not what im looking for.
I just want a button to be displayed, not a menu item
A MenuItem is for all intents and purposes a button. You don't need a full menu with multiple items or anything like that, it's just text or a graphic that you touch and then it does something.
If you want to use UIButton from UIKit specifically for whatever reason, you will find a lot of information searching for "UIKit" on the forums. The important part is to add the button's view like this:
[[[[Director sharedDirector] openGLView] window] addSubview:myButtonView];
Okay, now it shows the button. Know i have two questions
1) How do i add a selector to the button so i can make the button perform actions when prssed
2)The button displays the title i gave him in the incorrect orientation. The app is in landscape but it shows the title in portrait mode
Thanks in advance
1)
[myButton addTarget:self action:@selector(whatever:) forControlEvents:UIControlEventTouchUpInside];
2)
use CGAffineTransformRotate
Thanks. Now it works perfectly
A question. The part of the CGAffineTransform should be like this?
button.transform = CGAffineTransformRotate(theView.transform, degreesToRadians(45));
Forget the last post. Now i managed it to work
You should explain how you got it to work, thanks!
button.transform = CGAffineTransformRotate(theView.transform, degreesToRadians(90));
You must log in to post.