tags:

views:

52

answers:

2

I am just developing a simple iPhone application where a paddle moves left and right automatically.

My logic:

// First to determine the CGPoint of paddle
CGPoint detectXY = CGPointMake(paddle.center.x ,paddle.center.y);

// Second to determine the velocity of paddle
CGPoint paddleVelocity = CGPointMake(1,1);

// Adding velocity with X,Y cordinate
paddle.center = CGPointMake(paddle.center.x + paddleVelocity.x, 
                            paddle.center.y + paddleVelocity.y);

But the paddle is not moving...

Any ideas?

A: 

If you created the UIImageView in Interface Builder, make sure you connect it up to your IBOutlet or it won't respond to you setting the .center property. This has bitten me many times.

willc2
Oh my god!!!hw i m forget to connect the UIImageView ...Ok thnx for point it out .Now i am able to slide the image to one side But there still problem in it when paddle it reaches end point it is not moving right...i think i miss a condition for that .
raaz
A: 

my updated code

  • (void)viewDidLoad {

[super viewDidLoad];

[NSTimer scheduledTimerWithTimeInterval:0.9 target:self selector:@selector(game) userInfo:nil repeats:YES];

}

-(void)game{

CGPoint imgVelocity = CGPointMake(20,1); CGPoint detectXY = CGPointMake(imgViewPaddle.frame.origin.x , imgViewPaddle.frame.origin.y);

int x1= (int)detectXY.x;

CGRect rect=imgViewPaddle.frame;

if(x1>=0) { imgViewPaddle.frame=CGRectMake(imgViewPaddle.frame.origin.x-imgVelocity.x, imgViewPaddle.frame.origin.y, imgViewPaddle.frame.size.width, imgViewPaddle.frame.size.height);

} else //<0 { imgViewPaddle.frame=CGRectMake(imgViewPaddle.frame.origin.x+imgVelocity.x, imgViewPaddle.frame.origin.y, imgViewPaddle.frame.size.width, imgViewPaddle.frame.size.height);

}

rect=imgViewPaddle.frame; }

raaz
outis