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

  • Home
  • SEARCH
  • 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 669339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:08:26+00:00 2026-05-14T00:08:26+00:00

i usually develop for iPhone. But now trying to make a pong game in

  • 0

i usually develop for iPhone. But now trying to make a pong game in Cocoa desktop application. Working out pretty well, but i can’t find a way to capture key events.

Here’s my code:

#import "PongAppDelegate.h"

#define GameStateRunning 1
#define GameStatePause 2

#define BallSpeedX 10
#define BallSpeedY 15

@implementation PongAppDelegate

@synthesize window, leftPaddle, rightPaddle, ball;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

    gameState = GameStateRunning;
    ballVelocity = CGPointMake(BallSpeedX, BallSpeedY);
    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(gameLoop) userInfo:nil repeats:YES];
}


- (void)gameLoop {
    if(gameState == GameStateRunning) {
        [ball setFrameOrigin:CGPointMake(ball.frame.origin.x + ballVelocity.x, ball.frame.origin.y + ballVelocity.y)];

        if(ball.frame.origin.x + 15 > window.frame.size.width || ball.frame.origin.x < 0) {
            ballVelocity.x =- ballVelocity.x;
        }

        if(ball.frame.origin.y + 35 > window.frame.size.height || ball.frame.origin.y < 0) {
            ballVelocity.y =- ballVelocity.y;
        }
    }
}


- (void)keyDown:(NSEvent *)theEvent {
    NSLog(@"habba");
    // Arrow keys are associated with the numeric keypad
    if ([theEvent modifierFlags] & NSNumericPadKeyMask) {
        [window interpretKeyEvents:[NSArray arrayWithObject:theEvent]];
    } else {
        [window keyDown:theEvent];
    }
}

- (void)dealloc {
    [ball release];
    [rightPaddle release];
    [leftPaddle release];
    [super dealloc];
 }

@end

  • 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-14T00:08:26+00:00Added an answer on May 14, 2026 at 12:08 am

    If your PongAppDelegate class doesn’t inherent from NSResponder, it will not respond to a -keyDown event.

    Even in a small app you want to use a controller subclass instead of dumping functionality in the app delegate.

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

Sidebar

Related Questions

Usually I develop in Java but now I need to write an app that
I recently started working on a small CMS. I usually develop .NET applications in
Usually i need to develop the mobile website for different platforms, like iphone 3
=I am trying to develop a simple drag/drop UI in my web application. An
I usually store my connectionstring in web.config or in the application settings of my
I usually develop websites on the WAMP/XAMPP and host it on Linux servers. All
I know this is kind of an odd question. Since I usually develop applications
I have to develop a CRUD application, that will be coded in php. I
I want to develop a application on Android platform to connect to salesforce. From
We are currently using SVN to develop an internal application that has most of

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.