Add a UIButton

This topic contains 11 replies, has 4 voices, and was last updated by  jpv123 4 years, 3 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
Author Posts
Author Posts
December 25, 2009 at 8:37 pm #219003

jpv123
@jpv123

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

December 25, 2009 at 8:37 pm #269141

jpv123
@jpv123

Oh, and sorry for my bad english. Is not my native language

December 25, 2009 at 11:29 pm #269142

goldplated
@goldplated

Search the Forum for “MenuItem” and you will find examples…

December 26, 2009 at 12:30 am #269143

jpv123
@jpv123

Thanks, but thats not what im looking for.

I just want a button to be displayed, not a menu item

December 26, 2009 at 12:39 am #269144

DetectiveCakes
Participant
@detectivecakes

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];

December 26, 2009 at 2:26 am #269145

jpv123
@jpv123

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

December 26, 2009 at 2:55 am #269146

DetectiveCakes
Participant
@detectivecakes

1)

[myButton addTarget:self action:@selector(whatever:) forControlEvents:UIControlEventTouchUpInside];

2)

use CGAffineTransformRotate

December 26, 2009 at 3:33 pm #269147

jpv123
@jpv123

Thanks. Now it works perfectly

December 26, 2009 at 7:50 pm #269148

jpv123
@jpv123

A question. The part of the CGAffineTransform should be like this?

button.transform = CGAffineTransformRotate(theView.transform, degreesToRadians(45));

December 26, 2009 at 7:56 pm #269149

jpv123
@jpv123

Forget the last post. Now i managed it to work

January 10, 2010 at 5:45 pm #269150

refried
Participant
@refried

You should explain how you got it to work, thanks!

January 10, 2010 at 10:35 pm #269151

jpv123
@jpv123

button.transform = CGAffineTransformRotate(theView.transform, degreesToRadians(90));

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.