Unity is the premier 2D/3D gaming platform out there. I've just started going through a series of tutorials from Stone River Learning. They're very nice.
Here's code for a 'constructor'. A constructor is when a class or struct is created, its constructor is called. Constructors have the same name as the class or struct, and they usually initialize the data members of the new object.
and here's a code snippet;
public struct Question
{
public string questionText;
public string[] answers;
public int correctAnswer;
// This is the constructor that initializes the Question struct/object
public Question(string questionText, string[] answers, int correctAnswer)
{
this.questionText = questionText;
this.answers = answers;
this.correctAnswer = correctAnswer;
}
}
public Question testQuestion = new Question ("What is your favorite color?", new string[]{"blue","green","yellow"}, 0);
Enumeration snippet;
foreach (GameObject p in TriviaPanels) {
p.SetActive (false);
Here's another note;
Try the search, it's linked to some great forums
Tuesday, January 19, 2016
Configuring a webView, MKMapView, UIAlertView
Another quickstart guide to various views;
webView
Here the code for viewDidLoad;
// Do any additional setup after loading the view, typically from a nib.
NSString *fullURL = @"http://cutthroatrobotics.com/";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.viewWeb loadRequest:requestObj];
UIAlertView
Here's a snippet ;
webView
Here the code for viewDidLoad;
// Do any additional setup after loading the view, typically from a nib.
NSString *fullURL = @"http://cutthroatrobotics.com/";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[self.viewWeb loadRequest:requestObj];
UIAlertView
Here's a snippet ;
Friday, November 13, 2015
NSUserDefaults - Persisting data & passing it around viewCOntrollers
This is a very simple way to pass parameters between various views.
1st in the appDelegate.m file add;
// NSUserDefault setup for passing info around the app the starting default values.
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"list_filtered"];
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"selected_spreadsheet"];
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"selected_map_type"];
[[NSUserDefaults standardUserDefaults] setObject:@"ALL" forKey:@"selected_driver"];
[[NSUserDefaults standardUserDefaults] setObject:@"initialString" forKey:@"selected_plist"];
[[NSUserDefaults standardUserDefaults] setObject:@"initialDictionary" forKey:@"selected_member"];
[[NSUserDefaults standardUserDefaults] setObject:@"selectedIndexPath" forKey:@"selected_indexPath"];
// sync the defaults to disk
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];
1st in the appDelegate.m file add;
// NSUserDefault setup for passing info around the app the starting default values.
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"list_filtered"];
[[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"selected_spreadsheet"];
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"selected_map_type"];
[[NSUserDefaults standardUserDefaults] setObject:@"ALL" forKey:@"selected_driver"];
[[NSUserDefaults standardUserDefaults] setObject:@"initialString" forKey:@"selected_plist"];
[[NSUserDefaults standardUserDefaults] setObject:@"initialDictionary" forKey:@"selected_member"];
[[NSUserDefaults standardUserDefaults] setObject:@"selectedIndexPath" forKey:@"selected_indexPath"];
// sync the defaults to disk
[[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
[[NSUserDefaults standardUserDefaults] synchronize];
Thursday, November 5, 2015
Plist notes
For reading a Plist you need to;
// Loads file locally from either sheet
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *fileURL = [[NSURL alloc] init];
fileURL = [mainBundle URLForResource:@"SCWaveDistributionListCurrent" withExtension:@"plist"];
or just read Apple's docs N:
- URLForResource:withExtension:
Returns the file URL for the resource identified by the specified name and file extension. And I think it will read CSV files directly & with lots less hastle.
// Loads file locally from either sheet
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *fileURL = [[NSURL alloc] init];
fileURL = [mainBundle URLForResource:@"SCWaveDistributionListCurrent" withExtension:@"plist"];
or just read Apple's docs N:
- URLForResource:withExtension:
Returns the file URL for the resource identified by the specified name and file extension. And I think it will read CSV files directly & with lots less hastle.
Thursday, October 22, 2015
Pushing & Popping View Controllers
Pushing (adding to the stack) and Popping (removing from the stack) is a key technique for displaying your views on an iOS app. Doing this incorrectly can create huge memory leaks & crashes. Doing it properly can lead to beautiful transitions and navigation thru your app.
Here's some reference articles;
Back to Basics - View Controllers
Here is a code sample demonstrating how to push a view controller on to the navigation stack.
In this example, we instantiate a new UIViewController subclass
called MyViewController and push it on to the view controller stack.
One very important detail to point out is, you must do this from inside
of a view controller that is contained inside of a navigation
controller, otherwise the “self.navigationController” property will be
nil. navigationController is a property of every UIViewController
subclass that gets set whenever it has been inserted into a
UINavigationController.
Another thing to note is, we release the controller after pushing it on to the stack (prior to iOS5 with ARC). This is because the navigation controller will retain your view controller therefore preventing it from being released from memory.
The following code will pop the view controller off of the view stack with an animation.
Here's some reference articles;
Back to Basics - View Controllers
Here is a code sample demonstrating how to push a view controller on to the navigation stack.
// Initialize MyViewController object MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle]]; // Pushes MyViewController object on the navigation stack [self.navigationController pushViewController:controller animated:YES]; [controller release];
|
Another thing to note is, we release the controller after pushing it on to the stack (prior to iOS5 with ARC). This is because the navigation controller will retain your view controller therefore preventing it from being released from memory.
The following code will pop the view controller off of the view stack with an animation.
[self.navigationController popViewControllerAnimated:YES];
|
Subscribe to:
Posts (Atom)