iDevGames Forums
Beginner - Objective-C/C++/Engines question - Printable Version

+- iDevGames Forums (
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Programming Languages & Scripting (/forum-8.html)
+--- Thread: Beginner - Objective-C/C++/Engines question (/thread-2923.html)

Beginner - Objective-C/C++/Engines question - LeChuck - Nov 25, 2007 06:10 PM


I have decided to look into game programming on the Mac. I do not have any C related language experience. I am a web developer and I am experienced with PHP, Javascript etc...including proprietary language, and familiar with development. I setup XCode and started looking into Objective-C and it seems that learning the language itself should be a no-brainer, the biggest trouble being of course learning how to build a game.

Anyway...I also looked into game engines, for example PTK, and this is when the confusion part comes in, a little.

If I go the Objective-C route, will that be exclusively to build Cocoa applications or will I also be able to use libraries from game engines should I need to do that? Should I go the C++ route instead? What is it that either of those paths would *not* allow me to do?

What of games that have no "system" interface (sorry about the newbyness)? I am not looking at card games but things a bit more ambitious sh as platformers, 2D arcade, eventually a bit of 3D etc...

Thanks for any pointers and please let me know if this wasn't very clear!

Beginner - Objective-C/C++/Engines question - OneSadCookie - Nov 25, 2007 07:00 PM

C, ObjC and C++ can be intermixed more or less freely.

Whatever language you choose for the bulk of your game, you'll have a bit of Cocoa code at the top to make a window, gather events, and a few other OS-level things.

Beginner - Objective-C/C++/Engines question - AnotherJake - Nov 25, 2007 07:24 PM

Since you mentioned you have experience with Javascript you could look into Unity, which is a nice commercial game engine. I haven't kept up with it but last I saw you could use Javascript or C# for scripting it.

Starting from scratch is real tough, but definitely doable if you have the tenacity and/or talent to do so. You'll have to learn C and Objective-C for all practical intents and purposes, which is not a walk in the park but not impossible. (well, you don't *have* to learn Objective-C, but like OSC mentioned, that's what most of us use for windowing nowadays)

Beginner - Objective-C/C++/Engines question - LeChuck - Nov 26, 2007 08:44 AM

Thanks for the replies!

I am not sure yet if I have the talent but tenacity, yes, without a doubt. I work on rather complex web sites and applications all day, and have developed a pretty solid experience with object development etc...

I looked into the various game engines. Right now I am not 100% sure about the game I'd work on and do not know if I'd code it all myself from scratch or go with an existing engine. I need to learn more before I am able to decide this, but I was looking to find out which road would not lead me to a dead-end after having invested precious time. I do like the idea of doing it myself better rather than relying too much on pre-existing code and routines (within reason), and as an Amiga/Atari/Amstrad old timer I have certain ideas about good games that are kinda different from what's on the market today. I still have the box of Blitz Basic 2, which I had bought for Amiga way back when. Didn't know they were still in business...

To get back to the subject (and after a lot of reading), it looks like Objective-C is what I'd like to go for, but what if the game I want to create does not need a system interface/window application? What if it has both a system/OS interface and a totally in-game, full screen interface (as most games do). In which cases would I need to use Cocoa, and in which cases would I *not* be using Cocoa, and in those cases where I would not be using Cocoa, is Objective-C still what I'd develop in?

This really is the part that confuses me and I'd like to understand. Which bits of a game call for what technology/language (for best results).

Although I'm not sure I got it 100%, you might have answered it: I would be able to use Objective-C efficiently for most of the game, then use the Cocoa API when I need it for any system-based interface/windows/events, and make my own engine or interface with a third-party game engine still using Objective-C? For that last part (interfacing with a game engine), would I need to actually learn C++ to link my Obj-C code and the engine's libraries or could I access them directly with Obj-C?

Thanks again.

Beginner - Objective-C/C++/Engines question - OneSadCookie - Nov 26, 2007 10:44 AM

Even if your only window is a full-screen window, you still need Cocoa to create it, and to handle mouse and keyboard events.

If you want to be cross-platform, you won't use ObjC for anything else. In that case you'll want some higher-level language (Ruby, Python, Java, C#, etc.) to write the majority of the code in, and some lower-level language (C or C++) to write the occasional bit that needs to be fast. If you don't care about being cross-platform, ObjC is an OK compromise between high- and low-level to use throughout the app.

Any third-party game engine you might use is likely to do the Cocoa bit at the top for you, and the "fast" bit for you, leaving some mid-level "details" for you to fill in yourself. What language you'll need for that is up to the engine to some degree, and you to some degree.

Beginner - Objective-C/C++/Engines question - LeChuck - Nov 26, 2007 11:04 AM

Thanks. Instead of engine, I think I should have said libraries. Discovering all that terminology. I think that I won't be worrying about going cross-platform for now, and what I'll be doing will probably never need the power of a souped-up PC gaming rig.

Beginner - Objective-C/C++/Engines question - AnotherJake - Nov 26, 2007 11:19 AM

It can be pretty complicated to figure out how it all comes together. I would still recommend going with Unity first.

As OSC pointed out, unless you go with some other third-party library like SDL or a full-fledged engine like Unity, you will still have to use Cocoa to interact with the OS on a basic level, which is what we call the "windowing code" or "windowing layer" around here.

You can easily continue to do the entire game in Obj-C without issue. That obviously also has the side-benefit of making Cocoa available at any point in the program if need be, which can be handy at times. That's the way I do it nowadays. I don't care about being cross platform and have found Obj-C to be everything I need and more in the speed department. I can always drop down to straight C function calls, but there really hasn't been any need for that yet (except for my little math library). I do also include a scripting language environment for convenience but have found that I don't use it as much as I thought I would.

It takes lots of effort to learn C and then Obj-C, but it's definitely a worthwhile investment since you can use those skills for so much other than just games. To recap: If you go with SDL for windowing then all you need to learn is C first. If you want to do your own windowing from scratch then you'll additionally have to learn Obj-C and learn some of the Cocoa API. We haven't even mentioned that you'll need to learn OpenGL either way for your graphics. If you stick with Unity you'll only need to know Javascript or C# and all the rest is handled for you.

Beginner - Objective-C/C++/Engines question - LeChuck - Nov 26, 2007 02:36 PM

Thanks Jake, this makes it clearer as well.

I do like the idea of learning what I need to learn (and I learn tons better by doing) in order to be more independent later and able to do what I need to do. I do plan on learning OpenGL too. I think I will try to get started by going the Objective-C route because I like what I've seen from that language, and also try to see what I can do with Unity and go from there. I'm pretty well aware that any of the components to learn will be complicated, but as you say, my current problem was to be able to see how it all needs to come together to code a game.

Beginner - Objective-C/C++/Engines question - Duane - Nov 26, 2007 04:26 PM

I'd learn C first. Just a suggestion, take random (small!) text projects and WRITE them. Write a guessing game (guess the number?), then a blackjack game, then a sudoku creater/solver. Then learn objective-c. convert your games to GUI. Then take the larger gaming plunge.