Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6948503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:49:53+00:00 2026-05-27T13:49:53+00:00

xcode 4.2 ios 5 single view template I am very new to this ios

  • 0

xcode 4.2 ios 5 single view template

I am very new to this ios format and these new features in xcode

Here is all of my code:

#import "SimpleGame2ViewController.h"

#define kStateRunning 1
#define kStateGameOver 2

#define kLeftDown 1
#define kRightDown 2
#define kTouchesEnded 3

#define kPlatformWidth 55
#define kPlatformHeight 16

#define kMaxBallSpeed 10

#define kJumpPower 9

#define kGravity 0.195

@ implementation SimpleGame2ViewController @ synthesize ball;
@synthesize platform1;
@synthesize platform2;
@synthesize platform3;
@synthesize platform4;
@synthesize platform5;
@synthesize bg;
@synthesize gameState;
@synthesize ballVelocity, gravity;
@synthesize touchState;

-(void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

-(void)viewDidLoad {
    [super viewDidLoad];
    gameState = kStateRunning;
    ballVelocity = CGPointMake(0, 0);
    gravity = CGPointMake(0, kGravity);

    [NSTimer scheduledTimerWithTimeInterval: 1.0 / 60
        target: self
        selector: @selector(gameloop)
        userInfo: nil
        repeats:YES];

    // Do any additional setup after loading the view, typically from a nib.
}

-(void)gameloop {
    if (gameState == kStateRunning) {
        [self gameStatePlayNormal];
    } else if (gameState == kStateGameOver) {
        ballVelocity.x = 0;
        ballVelocity.y = 0;

        ball.center = CGPointMake(152 + 16, 326 + 16);
        platform1.center =
            CGPointMake(129 + (kPlatformWidth / 2),
                414 + (kPlatformHeight / 2));
        platform2.center =
            CGPointMake(34 + (kPlatformWidth / 2),
                316 + (kPlatformHeight / 2));
        platform3.center =
            CGPointMake(192 + (kPlatformWidth / 2),
                261 + (kPlatformHeight / 2));
        platform4.center =
            CGPointMake(146 + (kPlatformWidth / 2),
                179 + (kPlatformHeight / 2));
        platform5.center =
            CGPointMake(8 + (kPlatformWidth / 2),
                81 + (kPlatformHeight / 2));
    }
}

-(void)gameStatePlayNormal {
    ballVelocity.y += gravity.y;

    if (touchState == kLeftDown) {
        ballVelocity.x -= 0.2;
    }
    if (touchState == kRightDown) {
        ballVelocity.x += 0.2;
    }
    if (ballVelocity.x > kMaxBallSpeed) {
        ballVelocity.x = kMaxBallSpeed;
    }
    if (ballVelocity.x < -kMaxBallSpeed) {
        ballVelocity.x = -kMaxBallSpeed;
    }

    if (ball.center.x > self.view.bounds.size.width) {
        ball.center = CGPointMake(0, ball.center.y);
    }

    if (ball.center.x < 0) {
        ball.center =
            CGPointMake(self.view.bounds.size.width, ball.center.y);
    }

    ball.center =
        CGPointMake(ball.center.x + ballVelocity.x,
            ball.center.y + ballVelocity.y);

    if (ball.center.y > self.view.bounds.size.height) {
        gameState = kStateGameOver;

    }
}

// Check for a bounce

if (CGRectIntersectsRect(ball.frame, platform1.frame)) {
    if (ball.center.y + 8 < platform1.center.y) {
        if (ballVelocity.y > 0) {
            ballVelocity.y = -kJumpPower;
        }
    }
}

if (CGRectIntersectsRect(ball.frame, platform2.frame)) {
    if (ball.center.y + 8 < platform2.center.y) {
        if (ballVelocity.y > 0) {
            ballVelocity.y = -kJumpPower;
        }
    }
}

if (CGRectIntersectsRect(ball.frame, platform3.frame)) {
    if (ball.center.y + 8 < platform3.center.y) {
        if (ballVelocity.y > 0) {
            ballVelocity.y = -kJumpPower;
        }
    }
}

if (CGRectIntersectsRect(ball.frame, platform4.frame)) {
    if (ball.center.y + 8 < platform4.center.y) {
        if (ballVelocity.y > 0) {
            ballVelocity.y = -kJumpPower;
        }
    }
}

if (CGRectIntersectsRect(ball.frame, platform5.frame)) {
    if (ball.center.y + 8 < platform5.center.y) {
        if (ballVelocity.y > 0) {
            ballVelocity.y = -kJumpPower;
        }
    }
}

-(void)touchesBegan:(NSSet *)
touches withEvent:(UIEvent *) event
{
    if (gameState == kStateRunning) {
        UITouch *touch =[[event allTouches] anyObject];
        CGPoint location =[touch locationInView:touch.view];
        if (location.x < (self.view.bounds.size.width / 2)) {
            touchState = kLeftDown;
            ballVelocity.x -= 0.2;
        } else {
            touchState = kRightDown;
            ballVelocity.x += 0.2;
        }

    }
}

-(void)touchesEnded:(NSSet *)
touches withEvent:(UIEvent *) event
{
    touchState = kTouchesEnded;
}

-(void)viewDidUnload {
    [self setBall:nil];
    [self setPlatform1:nil];
    [self setPlatform2:nil];
    [self setPlatform3:nil];
    [self setPlatform4:nil];
    [self setPlatform5:nil];
    [self setBg:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

-(void)viewWillAppear:(BOOL) animated {
    [super viewWillAppear:animated];
}

-(void)viewDidAppear:(BOOL) animated {
    [super viewDidAppear:animated];
}

-(void)viewWillDisappear:(BOOL) animated {
    [super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL) animated {
    [super viewDidDisappear:animated];
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation !=
        UIInterfaceOrientationPortraitUpsideDown);
}

@end

I have the error around

if (CGRectIntersectsRect(ball.frame, platform1.frame)) {
    if (ball.center.y + 8 < platform1.center.y) {
        if (ballVelocity.y > 0) {
            ballVelocity.y = -kJumpPower;
        }
    }
}

I dont know why this is happening

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:49:54+00:00Added an answer on May 27, 2026 at 1:49 pm

    I’ve run your code through Lindent (a small shell script around the indent(1) program with settings that the Linux kernel developers like; it isn’t perfect, but it’s a good start).

    Once I did this, it was far easier to spot that your series of if (CGRectIntersectsRect(..)) tests aren’t actually in any function. They’re at the top level of your source.

    All statements and expressions must be within a function. (Declarations and global definitions can be at top-level.)

    Figure out which function should “own” that series of routines and place them within the function body.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Xcode 4.2.1 iPad iOS 5.0.1, create a new Single View iPad project. In
I've made a new project as a Single View iOS Application in Xcode. I've
I create a brand new Single View Application iPhone app in Xcode 4.2, it
I'm still relatively unfamiliar with all the new features of iOS 5, and what
I'm writing an app in XCode 3.2.3 for iOS 4. In my code, I
First, I am super-new to Objective-C/iOS development and, in fact, this question is for
I am new to xcode/ios etc... and having a little trouble figuring out a
I am new to Xcode and iOS development. when I create a new project,
Im very new to Objective-C and am currently learning how to use Xcode and
Xcode 3.2.5, iOS 4.2 (Simulator), Cocos2D 0.99.5 Following this tutorial comes with a wonderful

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.