We’re always on the lookout for the word “cross” within I.T. circles (not because we have any anger management issues, but), because it might mean some relief from “platform fatigue”. By that, we mean that the number of different devices and platforms you write code for, and hope to achieve just the one codebase, makes you pay attention, especially when working in an IDE when the word “cross” is prominent.
And so it was as we upgraded our MacBook Pro’s Xcode to version 8.3.1, and that set into play a revisit of this great IDE and a revisit of one of the great anticipatory parts of a good upgrade, the revisit to an IDE’s File -> New Project functionality. Xcode did not disappoint, offering templates for Apple platforms …
- iOS … Apple iPhones and iPads and iPods
- watchOS … Apple watch
- tvOS … Apple TV
- macOS … Apple Mac OS X … as with this MacBook Pro … and … da, da da da da da, da da da …
- Cross-platform … yay!!!! … feature today’s project of choice …
Cross-platform SpriteKit Game
Now the test using “Cross-platform SpriteKit Game” would be, for us, is integrating with all those other (albeit, only, Apple) platforms be seamless and easy? And turn away now in both a horizontal and vertical direction to avoid spoiler alert … you were warned … yes, as long as you have an Apple Developer Signup going if you might send your game to the Apple Store, otherwise you can do unit testing with device simulators. And that is where, for us, those Apple white leads become so important for real device testing with the MacBook Pro’s USB ports (hang on to your older version MacBook Pros?!) interfacing hardwarewise with the Apple white leads and softwarewise with the MacBook Pro’s iTunes desktop application, first up, where any Syncing and/or Ejecting of those real devices can take place, and be the springboard for Xcode projects to Product -> Destination (or via some much more self-explanatory “top of screen” ways, now, with Xcode 8.3.1) to manage lots of device scenarios. And you’ll want that using Xcode’s File -> New Project -> Cross-platform -> Cross-platform SpriteKit Game work, because you’ll get a lot of work done fast. By the way, we pick Objective-C as the language of project rather than the newer Swift for today.
Which brings us to today’s “Cross-platform SpriteKit Game” work. Yes, you guessed it … Hello World … but we do a few easy embellishments, which we’ll outline below, but we also say that you may get from our PDF slideshow presentation today …
- Open Xcode (IDE) desktop application (now 8.3.1 for us) on MacBook Pro
- File -> New Project -> Cross-platform -> Cross-platform SpriteKit Game … see slide 3 … etcetera etcetera etcetera
- ensure Project -> General (tab) -> Signing -> Team involves a real option, if you intend to do more than unit testing and debugging in Simulators
- ensure Project -> General (tab) -> Deployment Info -> Deployment Target involves a version low enough to cover the operating system of all your devices … we lowered it to 10.0 to cater for our iPad … see slide 7
- we add some Emojis into the Share folder’s GameScene.sks “scene”‘s “helloLabel”‘s Attribute Inspector’s “Text” field via Edit -> Emoji and Symbols submenu … see slide 6
- we change the Share folder’s GameScene.sks “scene”‘s “helloLabel”‘s Attribute Inspector’s we change “Rotation”, “Color”, “font” fields (which is pretty intuitive) for some variety … see slide 10
- we start to look at the Share folder’s Actions.sks “scene”‘s “Pulse”‘s Attribute Inspector’s “Fade In”, “Fade Out”, “Scale” actions … see slide 11 and slide 12 (to see its context in total time)
- we want to add code to introduce audio to application and start looking at GameScene.h and GameScene.m where code changes will take place … see slide 15 and slide 16 and slide 17 and slide 18 … so, what we do for …
- adding audio “notes of a piano” (that we had floating around) into the project… and, before we forget, thanks to this very usefiul link here …
under iOS -> Support Files (group) TwoFinger->Gesture New Group … call it ‘resource’ …
agree to any Bundle Group relationships … that makes this Group permeate to all the different Target platform apps when building …
drag those audio files to the ‘resource’ Group …
check in Project -> Build Phases -> Copy Bundle Resources that those audio files happen that (anticipated) way … otherwise … Gooooooooogggggggggllllleee! - low sound at a touch down or mouse down event …
GameScene.h changes as per …
//
// GameScene.h
// Cross Two
//
// Created by pgAgent on 12/4/17.
// Copyright © 2017 RJM Programming. All rights reserved.
//
#import <SpriteKit/SpriteKit.h>
#import <AVFoundation/AVFoundation.h>
@interface GameScene : SKScene
+ (GameScene *)newGameScene;
@end
GameScene.m changes up the top as per …
//
// GameScene.m
// Cross Two
//
// Created by pgAgent on 12/4/17.
// Copyright © 2017 RJM Programming. All rights reserved.
//
#import "GameScene.h"
@implementation GameScene {
SKShapeNode *_spinnyNode;
SKLabelNode *_label;
AVAudioPlayer *player;
}
// ... more code below
GameScene.m changes up the top of (void)setUpScene as per us making that sound be the lowest A on your normal piano (ie. A0.mp3) …
// ... more code above
- (void)setUpScene {
// Set up play sound
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/A0.mp3", [[NSBundle mainBundle] resourcePath]]];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
player.numberOfLoops = 0;
// Get label node from scene and store it for use later
_label = (SKLabelNode *)[self childNodeWithName:@"//helloLabel"];
_label.alpha = 0.0;
[_label runAction:[SKAction fadeInWithDuration:2.0]];
// ... more code below
GameScene.m changes bottom of (void)touchesBegan as per …
// ... more code above
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[_label runAction:[SKAction actionNamed:@"Pulse"] withKey:@"fadeInOut"];
for (UITouch *t in touches) {
[self makeSpinnyAtPoint:[t locationInNode:self] color:[SKColor greenColor]];
}
[player play];
}
// ... more code below
GameScene.m changes bottom of (void)mouseDown as per …
// ... more code above
- (void)mouseDown:(NSEvent *)event {
[_label runAction:[SKAction actionNamed:@"Pulse"] withKey:@"fadeInOut"];
[player play];
[self makeSpinnyAtPoint:[event locationInNode:self] color:[SKColor greenColor]];
}
// ... more code below
- some higher sound Actions.sks actions … which requires only GUI style work …
at the Share folder’s Actions.sks “scene”‘s “Pulse”‘s Attribute Inspector’s Object Library’s “PlaySoundFileNamed Action” drag into the desired timeslot and fill out “Start Time”, “Duration” and “Filename” (from a dropdown that should contain entries for each of those *.mp3 files you added into the project earlier) …
repeat at different times for some “bird chirping” feeling randomosity, as required
- adding audio “notes of a piano” (that we had floating around) into the project… and, before we forget, thanks to this very usefiul link here …
- to prepare the ground for the next run USB plug in any real device you want to test run, via USB port and Apple lead …
- to further prepare the ground for the next run, visit Product -> Destination and pick appropriate Simulator or real device …
- to test a device whether simulated or real Product -> Run … and on a real device it will leave an installed version should it build correctly, and that you can revisit and run separate to being hooked up to the MacBook Pro, after you use the MacBook Pro’s iTunes device button Eject option, when you’ve finished testing, and want to unplug the real device … and “let it be mobile”,
manpersonage
Get a few real devices and simulators going … and … “Weird Forest Sounds” (was the vision, but)“an instructional Xcode 8.3.1 Cross-platform SpriteKit Game project tutorial” YouTube video follows (above the MacBook Pro’s fan problems today … cut, cut!).
If this was interesting you may be interested in this too.