Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3808832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T15:12:37+00:00 2026-05-19T15:12:37+00:00

I am experimenting with a simple game. Just a few buttons and text being

  • 0

I am experimenting with a simple game. Just a few buttons and text being displayed.
I wanted to completely separate the game engine from views, view controllers, etc. As such, I defined it in a separate file and class called GameEngine.

I declare and intialize a GameEngine instance in the AppDelegate like this:

#import "GameEngine.h"

GameEngine *this_game;  //It's global!

@interface ...{
...
// this_game is not declared here at all
...
}

//No getter/setter defined for this_game

The AppDelegate implementation looks something like this:

#import "MyGameAppDelegate.h"

@implementation ...

// this_game not synthesized

- (void)applicationDidFinishLaunching:(UIApplication *)application {    

    // Override point for customization after app launch    
    this_game = [[GameEngine alloc] init];
    this_game.managedObjectContext = self.managedObjectContext;
    [this_game initialize_data];

    [window addSubview:game_vc.view]; // Display the primary application view
    [window makeKeyAndVisible];
}

...

-(void)dealloc{
...
[this_game release];
...
}

OK, with that out of the way, this is what happens in the primary view controller’s header file:

#import "GameEngine.h"

extern GameEngine *this_game;

// No other reference to this_game in the .h file

And now the code in .m:

-(void)viewDidLoad{

...
NSLog([this_game test], nil); //Just a quick "I am here" test
...

}

This is all well end fine and I can call methods from the global this_game object all day long from various points in the program. It works.

The question really is about how “proper” or proper in the context of accepted practice for Objective-C, if you will, this approach might be?

Is this a bad idea? Why?
Is there a better way? Why is it better?

My intent, BTW, is to separate GameEngine code in order to make it easier to reuse for both this platform and other mobile platforms. All the native windowing and UI stuff needs to stay away from game logic.

Thanks,

-Martin

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T15:12:38+00:00Added an answer on May 19, 2026 at 3:12 pm

    I totally agree with you in separating game logic code from all GUI related stuff is alway a good idea 🙂 I think your approach seems fine at first view, but 2 questions come into my mind:

    1.) Why don’t you use a singleton? So you don’t have to use C code in your Obj-C project and you can always extend your application if you need to care about special situations when running on simulator or you want to use mock ups for testing or what ever. Have a look at Singletons, AppDelegates…. There is a nice little header file SynthesizeSingleton.h I used in my projects quite often.

    2.) If your answer to 1.) is “as mentioned because I want to run it on different systems…”, then I suggest to implement your GameEngine class as C or C++. Thus migration to other platforms will be easier.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok so I am experimenting with making a simple game. I have a struct
I have been experimenting with a simple XOR-based text obfuscation algorithm. Supposedly, when the
I'm writing a simple REST service in Node.js (just experimenting), trying to figure out
I was experimenting with mod-rewrite. I thought what I wanted was simple but I
I've been experimenting with a simple project that essentially just stores the number of
I am experimenting with various responses from a simple NodeJS HTTP server. The effect
I have been experimenting with Lambda expressions in Oxygene. Very simple recursive lambda expression
Experiencing jquery in rails through .js.erb templates; but completely puzzled by a simple problem
While experimenting a bit with C++ templates I managed to produce this simple code,
I wrote a simple HTTP client and server in Python for experimenting. The first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.