Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-30-2009, 09:49 AM   #37 (permalink)
LeopardDevX
iPhone Developer
 
Join Date: Mar 2009
Posts: 222
Thumbs up Timer?

Quote:
Originally Posted by .mb View Post
Last post here, because I've sort of hijacked the thread, but here's my code.
Code:
@implementation SiegeViewController
@synthesize maxEnemies, newBall,origin,squaretest;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	[self touchesMoved:touches withEvent:event];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
	UITouch *touch = [[event allTouches] anyObject];
	CGPoint location = [touch locationInView:touch.view];
	newBall.center = location;
}

- (void)spawn1sec
{
	UIImage *enemyImage = [UIImage imageNamed:@"Green_Square.png"];
	newBall = [[UIImageView alloc] initWithImage: enemyImage];
	
	//add to array
	[enemies addObject:newBall];
	
	//add to the view, so it gets displayed.
	[self.view addSubview: newBall];
	newBall.center = CGPointMake(1, 1);
	newBall.userInteractionEnabled = YES;
	
}
- (void)gameLoop
{
	for (newBall in enemies)
	{
		int newX = newBall.center.x;
		int newY = newBall.center.y +1;
		newBall.center = CGPointMake(newX, newY);
	}
}
This doesn't work. I want to move the newBall object to the touchpoint, but it doesn't work. I probably haven't implemented the subclass properly.

That link was useful though. I've given it a read, and I think I know how to fix my problem.

Do you have a timer to call your gameloop and spawn1sec.....
PS. You need that....


And do you set newY and newX when the app starts....
like:
Code:
-(void)awakeFromNib {
speedX = 5.0;
speedY = 5.0;
// it may be speedX = 5; and speedY = 5;.........
and you need to set your timer.....
gametimer = [NSTimer schedueledTimer...ect..ect...ect..
//Im shure you know how to set a timer with a target and stuff...

}
Or you can do...
Code:
-(void)awakeFromNib {
speedX = 5.0;
speedY = 5.0;
// it may be speedX = 5; and speedY = 5;.........
and you need to set your timer.....
gametimer = [NSTimer schedueledTimer...ect..ect...ect..
//Im shure you know how to set a timer with a target and stuff...

}


OOOOOOPS sorry didnt read your question properly...
Ill let it stay to help other people.....


But in your case.. You dont need a touchesBegan.....
You need an touchesEnded!!!!!
__________________
Thank You.

Last edited by LeopardDevX; 03-30-2009 at 09:53 AM. Reason: didnt read his question....
LeopardDevX is offline   Reply With Quote
 

» Advertisements
» Online Users: 347
16 members and 331 guests
ADY, BdR, dacapo, fiftysixty, F_Bryant, john love, kampftrinker, ligerligerliger, mer10, mizzytheboy, nobre84, syver, themathminister, TheWebWizz, XRumerTest
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,876
Threads: 89,225
Posts: 380,701
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jorge599
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:30 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.