Quote:
Originally Posted by .mb
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!!!!!