Random Generation

Discussion in 'iOS Programming' started by JavaWizKid, Jul 15, 2009.

  1. JavaWizKid macrumors 6502a

    Joined:
    Sep 18, 2008
    #1
    How can I generate images to randomly appear on screen in multiple locations because with the interface builder you can only place a certain amount of images on screen?
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Is your question concerning the positioning of the individual images or with the number of images being displayed?
     
  3. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #3
    What I'm trying to do is hard to explain in words but its a sort of idea like cube runner. Random cubes generated in random locations and lots of them.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Well, I suspect Cube Runner is rendered using Open GL, since it's a 3D environment.

    I'm still not sure what exactly your question is.
     
  5. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #5
    I know it uses some sort of 3d rendering but what I want to know how to do is this: Since its only possible in the Interface Builder to place a certain number of images, how can I make my game generate lots of images and display them in random places?
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    You need to write some code that generates your views and addSubviews them to the main view. You could determine a frame rect or center randomly. You're right that IB can't really do this for you.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Although I think I understand your overall concern, this statement is not true. You can place as many images as you want with IB. There's no reason they can't overlap or even be hidden, one behind the other.

    Anyways, follow PhoneyDeveloper's suggestion.
     
  8. Kingbombs macrumors member

    Joined:
    Jun 24, 2009
    #8
    use arc4random()
    To get a random x value then call it again for a random y value
    then use those two points to place the image on the screen at that random location

    Then use arc4random() again to call how many random objects will be greated and run a for loop with that number calling the above code each time

    (i would use OpenGL if you want it like that game you mentioned)
     
  9. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #9
    Is there a way to look at the interface builder code to see how the images are placed?
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    What is your concern? Do you want to understand how views are added as subviews? Or how views are positioned within their super view? Or are you just wondering how a UIImageView is positioned using Interface Builder?

    My guess is you're still so new to this that you don't even have the basic concepts mastered enough to ask questions in the right way. If that's the case, I suggest you step back from the real coding for a bit and go review the basics before you continue.
     
  11. JavaWizKid thread starter macrumors 6502a

    Joined:
    Sep 18, 2008
    #11
    Yes I am fairly new and I'm getting a book soon. I'd just like to know how to add an image to the scene without using Interface Builder to pair the code with the actual displaying of the image.
     
  12. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State

Share This Page