Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Narcs

macrumors newbie
Original poster
Jan 19, 2012
10
0
I have created a method that sets this UIImageView's position to 35 pixels away from another UIImageView called mainSprite.

Code:
-(IBAction)hit{
    [self hitDummies];
    if (direction == 1) {
        [self hitDummies];
        hitBox.center = CGPointMake(mainSprite.center.x+30, mainSprite.center.y);
    }
    if (direction == 2) {
        [self hitDummies];
        hitBox.center= CGPointMake(mainSprite.center.x,mainSprite.center.y+30);
    }
    if (direction == 3) {
        [self hitDummies];
        hitBox.center = CGPointMake(mainSprite.center.x-30, mainSprite.center.y);
    }
    if (direction == 4) {
        [self hitDummies];
        hitBox.center = CGPointMake(mainSprite.center.x, mainSprite.center.y-30);
    }
It does move it where I want. But there is another void method that tests if this hitBox intersects with another UIImageView: dummies.

Code:
-(void)hitDummies{
    if (CGRectIntersectsRect(hitBox.frame, dummies.frame)) {
        nextConvoBut.enabled = YES;
        nextConvoBut.hidden = NO;
    }
}
As you can see I am calling this method in -(IBAction)hit. Keep in mind "hit" is linked with "touch down".
If you need to see any more code just ask :)
 
Last edited by a moderator:

Narcs

macrumors newbie
Original poster
Jan 19, 2012
10
0
The problem is that this is not working, sorry. It doesn't seem to be detecting the collision.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,544
6,042
What is "direction"?

What is happening? What should be happening?

Have you used breakpoints to determine what is getting called?

Also, why not use

Code:
switch (direction)
{
 case 1:... break;
 case 2:... break;
 default:... break;
}
Might look a little neater / cleaner / compact than a list of ifs.
 

Narcs

macrumors newbie
Original poster
Jan 19, 2012
10
0
"direction" is an integer. Whenever the character goes in a different direction the integer changes. I have it so that if the integer is equal a certain number, hitBox will move in a certain direction. What should be happening is that when "hit" is being held, it should check if "hitBox" intersects with "dummies". But it doesn't seem to realize the intersection.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.