Welcome, Guest. Please login or register.
Did you miss your activation email?
July 25, 2016, 07:38:21 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Recent Posts
Pages: 1 2 [3] 4 5 ... 10

 21 
 on: May 06, 2016, 06:31:01 PM 
Started by catonkeyboardjsjsjsj - Last post by cary_W
You can use the [self reduce] in the print: method, that would be more concise and easy to read. Smiley

 22 
 on: May 05, 2016, 03:59:07 AM 
Started by magickirbyz - Last post by cary_W
Thanks, I have learned how to use the bool type in your post. Smiley Smiley Smiley Smiley Smiley
(if it's the 6 edition, you missed the "if it's 0 entered" part.)

 23 
 on: April 21, 2016, 01:49:44 AM 
Started by steven huang - Last post by steven huang
hey guy's ,  i wonder know where can download or copy the source code (example ...etc) of the book

please help~~

 24 
 on: April 12, 2016, 10:01:54 AM 
Started by KingAG - Last post by KingAG
I try to make pong like game were on one side is player and on other side computer, because I want to in future add many game scenes with different gamefields I create ball node, paddle node etc.files separately, to make it easier to insert in gamefields and I don't have them create on every scenes from scratch. 
The Problem Now when I try everything put together player paddle works, ball node works, but computer paddle shows up for second and then disappears. Here are what I got in :
GameScene.m
Code: (Objective-C)
    @implementation GameScene

    -(void)didMoveToView:(SKView *)view {
   
    self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
    self.physicsBody.categoryBitMask = gamefieldCategory;
    self.physicsBody.contactTestBitMask = emptyCategory;
    self.physicsWorld.contactDelegate = self;
   
    BallNode *ball = [[BallNode alloc] init];
    [self addChild:ball];
    ball = (BallNode *) [self childNodeWithName:@"ball"];
    [ball resetPosition];
 
    PlayerNode *leftPlayer = [[PlayerNode alloc] initOnLeftSide];
    [self addChild:leftPlayer];
    leftPlayer = (PlayerNode *) [self childNodeWithName:@"leftPlayer"];
    [leftPlayer positionOnLeftSide];
   
    ComputerNode *rightPlayer = [[ComputerNode alloc] initOnRightSide];
    [self addChild:rightPlayer];
    rightPlayer = (ComputerNode *) [self childNodeWithName:@"rightPlayer"];
    [rightPlayer positionOnRightSide];   
    }
    -(void)computer{
    BallNode *ball = (BallNode *) [self childNodeWithName:@"ball"];
    ComputerNode *rightPlayer = (ComputerNode *) [self childNodeWithName:@"rightPlayer"];   
    if (ball.position.x > CGRectGetMidX(self.frame)) {
        if (rightPlayer.position.y > ball.position.y) {
            rightPlayer.position = CGPointMake(self.frame.origin.x - 50 + self.frame.size.width, rightPlayer.position.y -1.5f);
       //there is a very long text, thats why i cut it off
        }
      }
    - (void)update:(CFTimeInterval)currentTime{
          [self computer]; // calling computer paddle movement.
     }
ComputerPaddleNode.m

Code: (Objective-C)
    @implementation ComputerPaddleNode
    - (id)init
     {
    return [self initWithName:@"paddleaddle"];
     }

     - (id)initWithName:(NSString *)name
     {
      self = [super init];
      if (self) {
       
        self = [ComputerPaddleNode spriteNodeWithImageNamed: @"board.png"];
        self.userInteractionEnabled = YES;
        self.name = name;
        self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size];
        self.physicsBody.dynamic = NO;
        self.physicsBody.usesPreciseCollisionDetection = YES;
        self.physicsBody.categoryBitMask = paddleCategory;
        self.physicsBody.collisionBitMask = emptyCategory;
       
    }
   
    return self;
    }

    - (BOOL)withinParentFrame:(CGPoint)point
     {
    CGFloat offset = self.size.height / 2;
    if (point.y >= offset && point.y <= self.scene.frame.size.height - offset)
        return YES;
    else
        return NO;
    }
     - (CGPoint)normalisePoint:(CGPoint)point
    {
    CGFloat x = point.x / (self.size.width / 2);
    if (x > 1.0)
        x = 1.0;
    else if (x < -1.0)
        x = -1.0;
   
    CGFloat y = point.y / (self.size.height / 2);
    if (y > 1.0)
        y = 1.0;
    else if (y < -1.0)
        y = -1.0;
   
    return CGPointMake(x,y);
      }
    @end
ComputerNode.m
Code: (Objective-C)
    @implementation ComputerNode
    -(id)init
     {
        return [self initOnRightSide];
      }
     - (id)initOnRightSide
      {
      self = [super init];
         if (self) {
          self.name = @"rightPlayer";
        ComputerPaddleNode *rightPaddle = [[ComputerPaddleNode alloc] initWithName:@"rightPaddle"];
        [self addChild:rightPaddle];
        ScoreNode *score = [[ScoreNode alloc] initWithName:@"rightScore"];
        [self addChild:score];
        }
      return self;
       }
      - (void)positionOnRightSide
       {
    SKNode *paddle = [self childNodeWithName:@"rightPaddle"];
    paddle.position = CGPointMake(CGRectGetMaxX(self.parent.frame) -50, CGRectGetMidY(self.parent.frame)); 
    }
    @end

Why Computer node disappears and what do I need to change that? (Sorry for my bad enghlish)

 25 
 on: April 03, 2016, 03:27:46 AM 
Started by Miul - Last post by Miul
Here is my solution.
Code: (Objective-C)
#import "XYPoint.h"

@interface Rectangle : NSObject

@property CGFloat width, height;
@property XYPoint *origin;

- (void)setWidth:(CGFloat)w height:(CGFloat)h;

- (BOOL)containsPoint:(XYPoint *)aPoint;
- (Rectangle *)intersect:(Rectangle *)rect;

@end

Code: (Objective-C)
#import "Rectangle.h"

@implementation Rectangle

@synthesize width, height, origin;

- (void)setWidth:(CGFloat)w height:(CGFloat)h
{
    width = w;
    height = h;
}

- (BOOL)containsPoint:(XYPoint *)aPoint
{
    if ( (aPoint.x >= origin.x && aPoint.x <= origin.x + width) &&
        (aPoint.y >= origin.y && aPoint.y <= origin.y + height) )
        return YES;
    else
        return NO;
}

- (Rectangle *)intersect:(Rectangle *)rect
{
    Rectangle *result = [[Rectangle alloc] init];
    [result setWidth:0.0 height:0.0];
    XYPoint *pt = [[XYPoint alloc] init];
    pt.x = 0.0;
    pt.y = 0.0;
    result.origin = pt;
   
    if ( (rect.origin.x + rect.width >= origin.x && rect.origin.x <= origin.x + width) &&
         (rect.origin.y + rect.height >= origin.y && rect.origin.y <= origin.y + height) )
    {
        if (rect.origin.x <= origin.x)
            result.origin.x = origin.x;
        else
            result.origin.x = rect.origin.x;
       
        if (rect.origin.y <= origin.y)
            result.origin.y = origin.y;
        else
            result.origin.y = rect.origin.y;
       
        if (rect.origin.x + rect.width <= origin.x + width)
            result.width = rect.origin.x + rect.width - result.origin.x;
        else
            result.width = origin.x + width - result.origin.x;
       
        if (rect.origin.y + rect.height <= origin.y + height)
            result.height = rect.origin.y + rect.height - result.origin.y;
        else
            result.height = origin.y + height - result.origin.y;
    }
   
    return result;
}

@end

Code: (Objective-C)
#import <Foundation/Foundation.h>

@interface XYPoint : NSObject

@property CGFloat x, y;

@end

Code: (Objective-C)
#import "XYPoint.h"

@implementation XYPoint

@synthesize x, y;

@end

Code: (Objective-C)
#import "Rectangle.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Rectangle *aRect = [[Rectangle alloc] init];
        [aRect setWidth:250 height:75];
        XYPoint *aPt = [[XYPoint alloc] init];
        aPt.x = 200.0;
        aPt.y = 420.0;
        aRect.origin = aPt;
       
        Rectangle *bRect = [[Rectangle alloc] init];
        [bRect setWidth:700.0 height:880.0];
        XYPoint *bPt = [[XYPoint alloc] init];
        bPt.x = 100.0;
        bPt.y = 200.0;
        bRect.origin = bPt;
       
        Rectangle *result = [aRect intersect:bRect];
        NSLog(@"Origin is (%g, %g), width  = %g, height = %g", result.origin.x, result.origin.y, result.width, result.height);
       
    }
    return 0;
}

 26 
 on: March 25, 2016, 04:24:30 AM 
Started by azrael2000 - Last post by azrael2000
Hi All.

I hope this is the correct place to put this question. If not, please advise me and I will move it to another location.

I have a cocoa program that simply has a window and when you click a button, it opens an alertSheet.

Everything works, to that point, but I don't know how to handle the button presses.

I try to use this to see at least what buttons are being pressed, but in xcode 7.2 it is deprecated and I can't seem to figure the new syntax out.

#import "AppDelegate.h"

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application
}

- (void)applicationWillTerminate:(NSNotification *)aNotification {
    // Insert code here to tear down your application
}

- (IBAction)createAlertSheet:(id)sender
{
    NSAlert *alert = [[NSAlert alloc] init];
    [alert addButtonWithTitle:@"OK"];
    [alert addButtonWithTitle:@"Cancel"];
    [alert setMessageText:@"This is a sheet"];
    [alert setInformativeText:@"Hello SHEET Alert."];
   
    [alert setAlertStyle:NSCriticalAlertStyle];
   
    [alert beginSheetModalForWindow:_window
                  completionHandler:Nil];
   
    }

@end

This was how the buttons were handled previously:


- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo {
    NSLog(@"The return code was %li", returnCode);


Help is REALLY appreciated.  Even after going through xcode's documentation I am having an issue.

Regards

 27 
 on: March 09, 2016, 12:53:32 AM 
Started by jeegee - Last post by blur

http://www.amazon.com/Core-Developers-Cookbook-Edition-Library/dp/0321948106

Is a great book as is Steve's book. After you finish I highly recommend the book.

http://youtu.be/kEB4oHJ__0s link to a video of my app I'm working on.
 

 28 
 on: March 08, 2016, 02:52:38 AM 
Started by Uzair Lakhani - Last post by Uzair Lakhani
Dear Members,

Is it possible for two apps to simultaneously access microphone under iPhone. We want to develop a Skype recorder for iPhone but need to determine the possibility.

In Android we were getting problem in shared access of microphone but on Windows 7 desktop shared mode for microphone worked.

Thanks,

 29 
 on: March 04, 2016, 04:31:39 PM 
Started by skochan - Last post by rugvedj
I am unable to start the quiz. Is there anyway I can find a FAQ or Help manual. Thanks

 30 
 on: February 08, 2016, 09:56:12 AM 
Started by 星如雨 - Last post by mederafael
Code: (Objective-C)
//
//  MyDraw.m
//  Capitulo08
//
//  Created by Rafael Medeiros on 2/8/16.
//  Copyright 2016 Rafael Medeiros. All rights reserved.
//

#import "MyDraw.h"

@implementation MyDraw

@synthesize width,height;

- (void) printBlankLine
{
    printf(" ");
}

- (void) printTraceLine:(NSString *) typeChar
{
    if(typeChar == nil){
        printf("-");
    }else{
        printf("%s",[typeChar UTF8String]);
    }

}

- (long) printWidthLine:(long) w :(NSString *) typeChar
{
    if(w == 0){
        return 0;
    }

    if(w == width ){
        [self printTraceLine:typeChar];
    }else {
        [self printTraceLine:typeChar];
    }

    return [self printWidthLine:--w: typeChar];
}

- (long) printHeihtLine:(long) h
{
    if(h == 0 || h == height){
        [self printBlankLine];
        [self printWidthLine:width:nil];
        printf("\n");
        if( h == 0 ){
            return 0;
        }
    }
    [self printTraceLine:@"|"];
    [self printWidthLine:width:@" "];
    [self printTraceLine:@"|\n"];

    return [self printHeihtLine:--h];
}

- (void) draw
{
    [self printHeihtLine:height];
}

@end



Code: (Objective-C)
//
//  main.m
//  Capitulo08
//
//  Created by Rafael Medeiros on 2/8/16.
//  Copyright 2016 Rafael Medeiros. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "MyDraw.h"

int main(int argc, const char * argv[]) {
    @autoreleasepool {

        MyDraw *myDraw = [MyDraw new];
        [myDraw setWidth:10];
        [myDraw setHeight:2];
        [myDraw draw];

    }
    return 0;
}


 ----------
|            |
|            |
 ----------
Program ended with exit code: 0

Pages: 1 2 [3] 4 5 ... 10


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.