Topic:   My iPhone Game Tutorials for Beginners   (Read 351037 times)


0 Members and 1 Guest are viewing this topic.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #285 on: September 24, 2011, 08:40:50 PM »
I'm pretty sure I'll use Core Graphics.

alright I'll google it. ;)

EDIT: didn't find it in google, but in one of my books. looks a bit complicated, but I should hope to get it. It'd just require experimentation, and'd be something to build up to (the sprite sheet)
« Last Edit: September 27, 2011, 05:01:36 PM by KurtManion »
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #286 on: December 02, 2011, 05:28:41 PM »
How do you draw a Sprite?
I've been experimenting with UIImage, but can't get anything to actually apear on the screen. I've googled it, but can't get anything that specifically shows that.

Even just a small code sample would be fine, I"m desperate at this point  [smiley=dankk2.gif]
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #287 on: December 03, 2011, 02:57:07 AM »
Code: [Select]
UIImage* cow = [UIImage imageNamed:@"cow.png"];
[cow retain];
UIImageView* sprite = [[UIImageView alloc] init];
sprite.image = cow:
[myView addSubview:sprite];
sprite.center = CGPointMake(50,50);


GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #288 on: December 03, 2011, 05:06:27 PM »
Code: [Select]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
   
    // Override point for customization after application launch.

      // Set the view controller as the window's root view controller and display.
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
      
      UIImage* player = [UIImage imageNamed:@"Sprite.gif"];
      UIImageView* Sprite = [[UIImageView alloc] initWithImage:player];
      [viewController addSubveiw:Sprite]; /*****problematic code*****/
      Sprite.center = CGPointMake(50, 50);
      
      
      
    return YES;
}

Without the line marked problematic code it open and showed a blank grey screen. When I put that in, it says the build was successful, and then opens, and immediately crashes.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #289 on: December 03, 2011, 05:59:41 PM »
[viewController.view addSubview: sprite];

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #290 on: December 06, 2011, 04:08:39 PM »
oh I see. I was using -addSubveiw with a UIVeiwController, when I was supposed to used it with a UIVeiw.

While I was sick I re-read the sections in the books about these, so just so I'm clear:

UIImage is an object container for an image
UIVeiwController manipulates, and checks the UIVeiws
UIWindow is like a card in GM, and encapsulates everything

are thoes right, or am I still off?Ā  :-?
also what the heck is the difference between a UIImage and a UIImageVeiw. sorry for asking all these n00b questions, but I can't seem to find anything specifically on my query.  [smiley=embarassed.gif]
« Last Edit: December 06, 2011, 05:10:59 PM by KurtManion »
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #291 on: December 06, 2011, 05:35:51 PM »
A UIImage is the image. A UIImageView is a view that displays the UIImage.
Besides that everything's correct.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #292 on: December 08, 2011, 05:43:21 PM »
Obj-C is hellĀ  [smiley=angry.gif]

I finally found a sample application simple enough I could understand it, but it doesn't use any UIImageVeiws, it uses something called a UIVeiw. from the UIVeiw reference (in the documentation) it sounds like UIImageVeiw is a subclass, but why use it if you can fully function with a UIVeiw? What added benefit does it have?

http://developer.apple.com/library/ios/#samplecode/MoveMe/Introduction/Intro.html
« Last Edit: December 08, 2011, 05:43:47 PM by KurtManion »
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #293 on: December 08, 2011, 08:15:19 PM »
You can display images on a UIView by drawing with CoreGraphics. Or you can choose to use a UIImageView, just set the Image property and it draws it for you.

UIImageViews are a bit easier and don't take as much CPU as CoreGraphics.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #294 on: December 10, 2011, 07:32:21 PM »
Thanks so much Gan, I've finally got the hang of Objective-C, and yes you were right there was a beautiful princess at the end, now I just have to conquer the Dragon.  ;D

p.s. this metaphor is perfect.
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Connors


  • ^ This guy is amazing.

  • ****


  • Posts: 2374

  • It's a secret to everyone...
Re: My iPhone Game Tutorials for Beginners
« Reply #295 on: December 10, 2011, 07:42:51 PM »
Hey Gan I know it seems like I waited a long time to look at this again but now I'm really interested...
How similar is Obj-C to C?  Will I be able to look at your early tutorials and learn what I need?
Warning: The above post may have been modified multiple times.

"In a great game, the character must never perfectly obey the user's command"
 - Tim Rogers

http://connorspuzzles.tumblr.com/

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #296 on: December 10, 2011, 08:18:22 PM »
They are way different, Obj-C is way easier.

Yeah my older tutorials are still good to learn the basics.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #297 on: December 15, 2011, 06:43:14 PM »
I beg to differ, C is way easier for me, and I enjoy it more, except for larger programs, u need Object-Oriented programming for that.

OBj-C paradox! Do I have to allocate the AppDelegate object to use it's public properties and what not in other objects? Or is it automatically allocated somewhere?

EDIT:
nvm that was a retarded question, what I meant to ask was:
when is the main() function called in an Obj-C program.
« Last Edit: December 15, 2011, 06:54:17 PM by KurtManion »
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: My iPhone Game Tutorials for Beginners
« Reply #298 on: December 15, 2011, 07:13:53 PM »
It is in the main.m file. But it's best to follow the structure of Obj-C and have code work from the AppDelegate and other classes you've created.

GMG Kurt


  • GMG-er

  • **


  • Posts: 682

  • Sorry for being such a noob
Re: My iPhone Game Tutorials for Beginners
« Reply #299 on: December 16, 2011, 09:26:16 PM »
I'm trying to make a timer to handle game logic, but it won't even run GameTimer is an NSTimer, and mainloop is a NSRunLoop.

I finnaly found out what #pragma is  [smiley=WaveyWave2.gif]


[code c++]//
//  AdventureViewController.m
//  Adventure
//
//  Created by Kurt Manion on 12/10/11.
//  Copyright 2011 __Compleatly_Coded__. All rights reserved.
//

#import "Adventure_Prefix.pch"
#import "AdventureViewController.h"

@implementation AdventureViewController

@synthesize GameTimer;
@synthesize mainloop;


#pragma mark -
#pragma mark Touches

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      
      NSSet*            allTouches      = [event allTouches];
      UITouch*      touch            = [[allTouches allObjects] objectAtIndex:0];
  //UIView*            Frame            = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
      CGPoint       Location      = [touch locationInView:nil];
  //int                  *quadrants;
      
      NSLog(@"touch at location:%@",NSStringFromCGPoint(Location));
      

      
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

      //[GameTimer invalidate];
      NSLog(@"Touches ended");
      
}


#pragma mark -
#pragma mark CustomInitalizer

// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
            [self makeTimer];
            [self startTimer];
            
            UIImage* Sprite = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Sprite" ofType:@"gif"]];
            UIImageView* Hero = [[UIImageView alloc] initWithImage:Sprite];
            [self.view insertSubview:Hero atIndex:1];
            Hero.center = CGPointMake(CENTER);
            
            [Sprite retain];
            [Hero retain];
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
      [GameTimer release];
      [mainloop release];
}

#pragma mark -
#pragma mark SetUpTimer

- (void) makeTimer {

      NSLog(@"making timer");
      NSTimer* Timer = [NSTimer scheduledTimerWithTimeInterval:0.2
                                                                         target:nil
                                                                     selector:@selector(movehero)
                                                                     userInfo:nil
                                                                        repeats:YES];
      self.GameTimer = Timer;
}

- (void) startTimer {

      NSLog(@"starting timer");
      [mainloop addTimer:GameTimer forMode:NSDefaultRunLoopMode];
      [mainloop run];
      
}

- (void) movehero {

      NSLog(@"Move Hero");
      
}




/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
}
*/

#pragma mark -
#pragma mark CustomRules

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

/*
- (void)didReceiveMemoryWarning {
      // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
      
      // Release any cached data, images, etc that aren't in use.
}
*/

/*
- (void)viewDidUnload {
      // Release any retained subviews of the main view.
      // e.g. self.myOutlet = nil;
}
*/





@end
[/code]
Just your average Weekend Warrior.
Yes I know I have bad spelling, it's what makes me such a good programmer!

"Old art, weather magnificent or wretched, is always the raw material of new art. The artist's job, though, is to