I've been following this thread for a while, and I have a question. How would you only target once instance of the newEnemy? For instance if I wanted to just be able to touch one and delete that one.
So i found out how to get the enemies collidable...
But when i speed up my enemy spawn timer... and move timer..
to make more enemies show up and go faster.. if i collide with them when there speeded up..
The app crashes...
Any ideas???
Hi, I'm doing something similar. I'm trying to use CGRectIntersectsRect to determine when a Quartz animated object intersects with a CGRect object. Is this a bad thing to try to do? I've heard that Quartz stuff is on a different coord system. Do I need to apply a CGAffineTransformMakeRotation on initializing my Quarts objects to make the coord systems in sync?
So i found out how to get the enemies collidable...
But when i speed up my enemy spawn timer... and move timer..
to make more enemies show up and go faster.. if i collide with them when there speeded up..
The app crashes...
Any ideas???
Nothing special about collision that should cause crashes. Is there an error message in the console?
Use NSLog messages or breakpoints and the debugger to figure out what line it's crashing on. That should give you a clue what the problem is. You should also run instruments to see if you're using too much memory- that will crash the app too.
Nothing special about collision that should cause crashes. Is there an error message in the console?
Use NSLog messages or breakpoints and the debugger to figure out what line it's crashing on. That should give you a clue what the problem is. You should also run instruments to see if you're using too much memory- that will crash the app too.
How do i add those and where?
And.. i have checked the crash report and it says something like "image not found" or something....
What could this mean...?
I've been following this thread for a while, and I have a question. How would you only target once instance of the newEnemy? For instance if I wanted to just be able to touch one and delete that one.
Short question, long answer - to get the UIImageView to respond to touches, you'll have to subclass UIImageView. Inside your subclass, you'll want to do self.userInteractionEnabled=YES and implement the "touchesEnded:withEvent:" method from UIResponder.
You could also use UIButtons instead, which would let you define a button action - but long-term, subclassing UIImageView will allow you to add other variables you might need (like separate direction/velocity) to each enemy / ball / whatever.
EDIT: you don't have to subclass. Your viewController will get the touchesEnded:withEvent: message, and you could loop through the objects to see which one the touch intersects.
__________________
Free Games!
Last edited by smasher; 12-11-2009 at 01:42 AM.
Reason: touchesEnded:withEvent:
Ahh, that makes sense. One more question, if I could. I'm trying to destroy objects dynamically, but I'm drawing a blank on how to remove it from memory... Trying to use [object dealloc] just freezes the application, and removing it from the array does the same.
Ahh, that makes sense. One more question, if I could. I'm trying to destroy objects dynamically, but I'm drawing a blank on how to remove it from memory... Trying to use [object dealloc] just freezes the application, and removing it from the array does the same.
Objects get destroyed when their "retain count" hits zero. Usually, that means you intit the object (for a count of one) and it gets destroyed when you release it. You never call dealloc yourself.
The confusion comes in when you *don't* init the objects - many classes have "convenience methods" that give you "autorelease" objects, that will release themselves at the end of the current event. If you release an object you did not init, you usually get a crash.
Properties and arrays/dictionaries also retain objects when you add them, and release them once when you remove them.
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....
Agh. I feel stupid. It was working the whole time. The problem is that it was affecting the center of the object, which is used for spawning, not movement. So, how could I affect the already made object with my move to touch code?
Agh. I feel stupid. It was working the whole time. The problem is that it was affecting the center of the object, which is used for spawning, not movement. So, how could I affect the already made object with my move to touch code?
You want to touch an object an move it? Like dragging?
You can either set up the objects themselves to respond to touches, like I said above, or handle it all here in the SiegeViewController.
To handle it here in the SiegeViewController, you'll have to set up so:
(1)You have a pointer to store the currently selected object.
(2)on touchesBegan, you look through your array of objects and find the nearest one to the touch point (pythaorean theorem.) Make that the currently selected object.
(3)On touchesMoved, move the currently selected object to the touch point.
That's what I have now. It works, and it moves them to the touchpoint when released, but it moves all of them.
When your doing for(newBall in enemies)
all the newBalls on the screen moves.. i guess you spawn some enemies... and you spawn those with the name "newBall" then all they will move!!!
Yes, I know that. The problem is that I want to be able to create all these with the same name, for easy handling with collision and stuff, but I don't know how to target one specific instance of newBall.
I have made a game where a ball is bouncing around and to not loose you move a paddle at the bottom of the screen,, and i have bricks to hit at the top of the screen.....
Based on your description it sounds like you may be making a Breakout clone. You may find this interesting:
Yes, I know that. The problem is that I want to be able to create all these with the same name, for easy handling with collision and stuff, but I don't know how to target one specific instance of newBall.
"for(newBall in enemies)" is a loop - it loops through all of the enemies, one at a time, and the code between the brackets changes their position.
You need to do something like this - loop through the enemies and find the one closest to where the touch began. That's your selected enemy.
"selectedEnemy" should be declared in your .h file, so you can use it in the other two touch methods. The other two touch methods should just set selectedEnemy.center.
It's not clear yet, but It sounds like this request was because of trademark violations- Atari owns the trademark for the name "Breakout." If you call your game "Super Paddle Whack," and you don't use their trade dress, you are not in violation.