HTML5 Game for the Mac App Store
This evening I took a break from tinkering with my HTML5 game to see
if I could get it running as a native Cocoa app on OSX. I’d heard that I
should be able to create a desktop app, add a WebView, then build and
run it. I got it working and wanted to share my results!
In the AppDelegate.h file I added:
I added the WebKit Framework.
Finally, I added the content files for my game to the Supporting Files folder.
In order to get these to be copied correctly, I did have to make sure that they were set up in the Build Phases > Copy Bundle Resources for my app.
That’s all there is to it! I’ll post the code on github as soon as I get time, but it’s simple enough to follow along with my instructions above.
- Create a new Cocoa Application.
- Add a WebView and expand it to fit the entire app surface.
-(void)applicationDidFinishLaunching:( NSNotification * ) aNotification {
NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
[[self.webView mainFrame] loadRequest:[NSURLRequest requestWithURL:url]];
}
In the AppDelegate.h file I added:
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
@interface sudolinkAppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet WebView *webView;
@end
I added the WebKit Framework.
Finally, I added the content files for my game to the Supporting Files folder.
In order to get these to be copied correctly, I did have to make sure that they were set up in the Build Phases > Copy Bundle Resources for my app.
That’s all there is to it! I’ll post the code on github as soon as I get time, but it’s simple enough to follow along with my instructions above.
Comments
Post a Comment