PDA

View Full Version : Can someon help me please with Xcode and Interface Builder?




markhtfc
Jan 30, 2007, 03:01 PM
Hey,

Well let me start of by saying this is my first post and my name is Mark and I am 17 years old. Now how I came about programming? Well I wanted to do it when I was younger but never really took it up, I am in my second year at college and we are currently doing C++ and HTML. Since doing programming at college it has really got me wanting to do programming as a proffesion. I am really advanced in C++ (compared to other students)though as the teacher would like to set me some more challenging tasks. So maybe I have a brain for programming heh.

Well onto the purpose of my post. I have not had a Mac that long. Not long before Christmas. I am looking at creating a Managing Game, I am using Xcode and Interface Builder. At the moment before I make the whole background and everything first I want to try and understand how to make action buttons work. (if I knew how to provide screenshots from a Mac I would do so you can understand easier). Well anyway what I have got so far is a title, Start New game button and a Quit button. I also have a screen that I want my New Game button to connect to.

The question I have is how do I get my new game button to go to that screen? and how do I get my Quit button to quit the program? I have tried a few times but had no luck.

I hope that someone will be able to help me as I would really be able to make a game, I would love to be a programmer. I am looking at going to uni to do a course maybe but I don't want it to turn out as a lost cause. As I have known a few people who has had to move away to do work in that area.

Thank your for listening and I hope you can help.

Thank you

Mark



robbieduncan
Jan 30, 2007, 03:30 PM
Are you using Carbon or Cocoa? I assume Carbon as you are talking about C++ but without knowing we can't really help you (and if it's Carbon I can't help you)...

markhtfc
Jan 30, 2007, 03:35 PM
Sorry about that. I am using Cocoa as that is what I was reccomended to use.

gauchogolfer
Jan 30, 2007, 03:37 PM
I'm no programmer, but I can help with the taking screenshots part. Here's a summary (http://guides.macrumors.com/Taking_Screenshots_in_Mac_OS_X).

robbieduncan
Jan 30, 2007, 03:43 PM
OK great. Cocoa is easy. But we need to agree on the normal terminology... What is this "screen"? Is it an NSWindow? An NSView? Something else?

Have you read up at all in the documentation on how the action messages get passed down the responder chain?

The simplest way to get this to work is to create a new object to use as the controller, instansiate that in IB and create the actions in there to deal with the windows.

markhtfc
Jan 30, 2007, 03:45 PM
Thank you for that gauchogolfer.

This screenshot is of my main Menu, As you can see it is very basic, this is because it is my first attempt at using it so I want to get used to it first.

http://img67.imageshack.us/my.php?image=picture3ug3.png

Then from the main menu what I am wanting to do is when I click Start New Game, i am wanting this screen to apear.

http://img264.imageshack.us/my.php?image=picture4oo6.png

Lovesong
Jan 30, 2007, 03:45 PM
One thing to remember is that programming in Cocoa uses Objective-C, and not C or C++. Is that what you're writing in?

markhtfc
Jan 30, 2007, 03:48 PM
yeah I am using Objective C. I am using C++ at college, I gatherd with it being on a Mac it would be a different code to Windows.

robbieduncan
Jan 30, 2007, 03:48 PM
Ok. There is no such thing as a screen. That's a Window. Do you want to allow multiple games at once or not? If the answer is yes then you need to use a Document Based app, otherwise not.

If the answer is a single game at once then why not just have the window appear on startup?

robbieduncan
Jan 30, 2007, 03:49 PM
Ok I see what you are trying to do. But why? This is not anything like a Mac user interface. You should not have a Quit button. Or a new game button like that. You need to use the actual menus.

markhtfc
Jan 30, 2007, 03:50 PM
Sorry about that, I should explain with the proper terminology. Sorry again.

About the multiple games not really know, As this is my first attempt.

I don't quite understand your last question, I would like a main menu so I can then move onto the Create manager Screen and so on.

robbieduncan
Jan 30, 2007, 03:52 PM
My point is that's not a menu. A menu is the thing at the top of the screen. It has a pre-populated perfectly functioning quit item. I understand a welcome view within the main window though. Give me 15 minutes: I'm knocking up a demo project...

markhtfc
Jan 30, 2007, 03:52 PM
Ok I see what you are trying to do. But why? This is not anything like a Mac user interface. You should not have a Quit button. Or a new game button like that. You need to use the actual menus.

I am not generally looking for a Mac user interface right at this minute. I am mainly looking at how I can make them do actions as I would like them to do seen as this is my first attempt.

markhtfc
Jan 30, 2007, 03:54 PM
Ok thank you. like I say programming is all new to me, The Mac is still new also. I am hoping to do programming though at a decent level so if I do go to Uni I will know what i am doing. Plus I find it very intresting and a great hobbie.

robbieduncan
Jan 30, 2007, 04:01 PM
So attached is an XCode project to demonstrate one of the possible ways of doing this. What we have is a single window that contains a NSTabView. This currently has 2 tabs one for each "screen" you want to display. The tabs themselves are hidden.

There is also an NSObject subclass that is our "controller" object. It has the action code in it to start the game. When the button is pressed this is called. All it does is select the next tab.

If this is all greek to you then you need to buy a book, or at the very least run through the guided, step by step demos on the Apple site that will take you through the basic design patterns you need to know, primarily MVC and how to connect the outlets and actions of objects in IB.

markhtfc
Jan 30, 2007, 04:10 PM
Ok thank you for that. So by what you are saying what I am trying to do I can't actually do it?

I will have a look at the step by step guides tomorrow as I will have more time then.

Thank you for your help and producing the Demo for me. :)

robbieduncan
Jan 30, 2007, 04:17 PM
No the demo does what you want to do (apart from the Quit button but that's really easy). I'm suggesting that you will need read up on the documentation to get anywhere.

kainjow
Jan 30, 2007, 05:02 PM
There is no such thing as a screen.

What about NSScreen (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSScreen_Class/Reference/Reference.html)? :confused:

:p ;)

robbieduncan
Jan 30, 2007, 05:04 PM
What about NSScreen (http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSScreen_Class/Reference/Reference.html)? :confused:

:p ;)

Yes OK, as in a whole screen, but not as in a view displayed in a window!

And :p :p to you too!

I'm just glad the OP hasn't been asking about going full screen for the game yet as that's a pain...

cazlar
Jan 30, 2007, 05:32 PM
I'll just mention that the MacDevCenter articles (especially the early ones) are quite good for Cocoa beginners in that they go through how to link buttons in IB to your code, IIRC. It's a fairly simple concept once you get it, but it is necessary before anything will actually work!

http://www.macdevcenter.com/pub/ct/37

lazydog
Jan 30, 2007, 05:48 PM
One thing to remember is that programming in Cocoa uses Objective-C, and not C or C++. Is that what you're writing in?

Not true, you can mix Objective-C and C++, just give your source files a .cpp extension. This will run them through the Objective-C++ compiler. I do this all the time as I much prefer C++ to Objective-C, but prefer to use Cocoa than Carbon.

b e n

markhtfc
Jan 31, 2007, 06:39 AM
Thanks for your help everyone.

Thank you for the link Cazlar, I had a look at that this morning and I read the first article. It looks intrsesting. Going to go through each article to see if it will help me out more.
Mark