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

DennisBlah

macrumors 6502
Original poster
Hey all, for my private project (not work related) I'm working with collisons with enemies. Since I got multiple enemies, and basicly the collisoncheck should stay the same. I wonder if its possible to take over an 'object' into an function.

For my gamestate timer I would like to use something like this:
Code:
-(void)gamePlay {
//...
 [self collisonCheck:troll]; //troll wud be an synthesized UIImageView.
}

//-(void)collisonCheck:theObject:(id)object { //How wud I make the parameter theObject contain the 'actual object' in this cass troll
-(void)collisonCheck:(UIImageView *)theObject {
  if(!theObject.hidden) {
    //doing the collison check from player to 'theObject'
  }
}

Any help wud be appriciated!
 
Last edited:
Ok.. Say stated as above it works.
Now I added all the moving objects in an array, and I'm going through the array like this:

Code:
for(int b = 0; b < [allObjects count]; b++) {
                theObjects = [allObjects objectAtIndex: b];
                theObjects.center = CGPointMake(theObjects.center.x, theObjects.center.y - gameSpeed);
                
                if(theObjects.frame.origin.y + theObjects.frame.size.height <= 0) {
                    if(b < 4 || (b == 4 && theObjects.hidden)) {
                        theObjects.center = CGPointMake(theObjects.center.x, playing.frame.size.height + (theObjects.frame.size.height / 2));
                    } else {
                        float x = (random() % ((int)playing.frame.size.width) - (treeLeft1.frame.size.width * 1.5));
                        theObjects.center = CGPointMake(x + (treeLeft1.frame.size.width / 4), playing.frame.size.width + (theObjects.frame.size.height / 2));
                    }
                }
            }

This is the final code I'm up with now.

Sorry for the inconvenient.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.