Resolved 'dynamic' objects in function

Discussion in 'iOS Programming' started by DennisBlah, Mar 16, 2014.

  1. DennisBlah, Mar 16, 2014
    Last edited: Mar 16, 2014

    DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    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!
     
  2. DennisBlah, Mar 16, 2014
    Last edited: Mar 16, 2014

    DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #2
    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.
     

Share This Page