|
View Poll Results: Was this thread helpful to other than me?? (LeopardDevX)
|
|
Yes, it helped me to!!
|
  
|
4 |
57.14% |
|
No, it was a waste of space in the forum......
|
  
|
3 |
42.86% |
 |
|
 |
|
 |
03-27-2009, 06:48 PM
|
#26 (permalink)
|
|
iPhone Developer
Join Date: Mar 2009
Posts: 219
|
Yes, Yes, Yes!!
OMG.. It works..
Thank you so, so, so much..
Cant believe i missed that line of code...
Still learning...   
__________________
Thank You.
Last edited by LeopardDevX; 03-28-2009 at 04:07 AM.
|
|
|
03-27-2009, 07:06 PM
|
#27 (permalink)
|
|
iPhone Developer
Join Date: Mar 2009
Posts: 219
|
Wait...
Wait...
How do i get every newEnemy collideable??
Almost solved...
__________________
Thank You.
|
|
|
03-28-2009, 02:05 AM
|
#28 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 32
|
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.
|
|
|
03-28-2009, 05:51 PM
|
#29 (permalink)
|
|
iPhone Developer
Join Date: Mar 2009
Posts: 219
|
Ok..
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???
__________________
Thank You.
|
|
|
03-28-2009, 06:55 PM
|
#30 (permalink)
|
|
New Member
Join Date: Jan 2009
Location: Los Angeles
Posts: 13
|
Quote:
Originally Posted by LeopardDevX
Code:
Sorry.... dont have one...
Should i add one now??
|
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?
|
|
|
03-28-2009, 09:16 PM
|
#31 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,540
|
Quote:
Originally Posted by LeopardDevX
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.
__________________
|
|
|
03-28-2009, 09:27 PM
|
#32 (permalink)
|
|
iPhone Developer
Join Date: Mar 2009
Posts: 219
|
How??
Quote:
Originally Posted by smasher
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...?
__________________
Thank You.
|
|
|
03-29-2009, 01:20 PM
|
#33 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,540
|
Quote:
Originally Posted by .mb
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.
__________________
Last edited by smasher; 12-11-2009 at 01:42 AM.
Reason: touchesEnded:withEvent:
|
|
|
03-29-2009, 03:14 PM
|
#34 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 32
|
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.
|
|
|
03-29-2009, 03:53 PM
|
#35 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,540
|
Quote:
Originally Posted by .mb
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 is the page that put it all together for me:
Very simple rules for memory management in Cocoa
PS- views also retain their subviews. So you'll have to call [deadView removeFromSuperview] too, if it's a view.
__________________
|
|
|
03-29-2009, 07:15 PM
|
#36 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 32
|
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.
|
|
|
03-30-2009, 09:49 AM
|
#37 (permalink)
|
|
iPhone Developer
Join Date: Mar 2009
Posts: 219
|
Timer?
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!!!!!
__________________
Thank You.
Last edited by LeopardDevX; 03-30-2009 at 09:53 AM.
Reason: didnt read his question....
|
|
|
03-31-2009, 11:42 PM
|
#38 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 32
|
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?
|
|
|
04-01-2009, 01:36 AM
|
#39 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,540
|
Quote:
Originally Posted by .mb
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.
__________________
|
|
|
04-01-2009, 07:50 PM
|
#40 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 32
|
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
That's what I have now. It works, and it moves them to the touchpoint when released, but it moves all of them.
Last edited by .mb; 04-01-2009 at 07:52 PM.
|
|
|
04-02-2009, 10:44 AM
|
#41 (permalink)
|
|
iPhone Developer
Join Date: Mar 2009
Posts: 219
|
yes..
Quote:
Originally Posted by .mb
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
for(newBall in enemies)
{
newBall.center = CGPointMake(location.x,location.y);
}
}
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!!!
__________________
Thank You.
|
|
|
04-02-2009, 07:52 PM
|
#42 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 32
|
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.
|
|
|
04-02-2009, 08:08 PM
|
#43 (permalink)
|
|
Registered Member
Join Date: Jan 2009
Posts: 239
|
Quote:
Originally Posted by LeopardDevX
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:
Atari's Legal Team Attacking iPhone "Breakout" Clones | Touch Arcade
Hopefully it's not a deal breaker for you.
|
|
|
04-03-2009, 12:06 PM
|
#44 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,540
|
Quote:
Originally Posted by .mb
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.
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:touch.view];
float foundDistance=1000;
for(checkEnemy in enemies)
{
distanceToEnemy = //pythagorean theorem here (distance btwn two points)
if (distanceToEnemy<foundDistance){
selectedEnemy = checkEnemy;
foundDistance = distanceToEnemy;
}
}
}
"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.
How does that sound?
__________________
|
|
|
04-03-2009, 02:27 PM
|
#45 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 32
|
So I would use the standard
a2+b2 = c2
So.... distanceToEnemy = touchpoint + object center?
I get what your saying, but I'm just not sure what to measure.
|
|
|
04-03-2009, 06:33 PM
|
#46 (permalink)
|
|
New Member
Join Date: Mar 2009
Posts: 32
|
Success! I figured it out. I ended up subclassing the UIImageView and then finding the position like smasher recommended. Thanks a ton!
|
|
|
04-04-2009, 02:44 AM
|
#47 (permalink)
|
|
Senior Member
iPhone Dev SDK Supporter
Join Date: Jul 2008
Location: San Mateo, CA (San Fran)
Posts: 2,540
|
Quote:
Originally Posted by rpstro02
|
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.
__________________
|
|
|
12-11-2009, 12:35 AM
|
#48 (permalink)
|
|
Registered Member
Join Date: Aug 2009
Posts: 125
|
where to declare this
enemies = [[NSMutableArray alloc] init];
inside Spawn() or in move()??
|
|
|
12-11-2009, 04:15 AM
|
#49 (permalink)
|
|
Registered Member
Join Date: Aug 2009
Posts: 125
|
i am not much clear about collusion part
|
|
|
12-11-2009, 04:23 AM
|
#50 (permalink)
|
|
Registered Member
Join Date: Aug 2009
Posts: 125
|
i am doing this to check colslsion on touchBegan()
UITouch *toucha = [[event allTouches] anyObject];
CGPoint locationa = [toucha locationInView:toucha.view];
// rn d
if(CGRectContainsPoint(newEnemy.frame, locationa))
{
printf("HIT");
[newEnemy removeFromSuperview];
}
|
|
|
 |
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
» Advertisements |
» Online Users: 425 |
| 28 members and 397 guests |
| acegames, AlanTaylor, asimrs, audibles, bensj, chaoz1337, choron, DarthVader007, DevGroup, Duncster2k4, georgeburns, HagenaarsDotNu, headkaze, mixer555, mmww, mongeta, MrMattMac, nobre84, robertyang999, s0crates, salvah, saywake, suwimol, ThirtyOne, ugur, yunas, zenox |
| Most users ever online was 779, 05-11-2009 at 10:55 AM. |
» Stats |
Members: 23,659
Threads: 38,415
Posts: 168,799
Top Poster: smasher (2,540)
|
| Welcome to our newest member, suwimol |
|