newbie needs help with image background.

Discussion in 'iOS Programming' started by newbRacer, Jul 30, 2009.

  1. newbRacer macrumors newbie

    Joined:
    Jul 30, 2009
    Location:
    Singapore
    #1
    Hi, I am new to the iPhone SDK and I want to add in an image background using UIKit or OpenGL (are they the same thing?).:confused:

    Basically it is a static image that is going to be the bottommost layer.

    What is the easiest method to load the image and render it out?

    Please help me out. Thank you.
     
  2. rossipoo macrumors regular

    Joined:
    Jun 7, 2009
    #2
    UIImageView is what you use for an image layer in the UIKit.
    You can simply set load the image with the setImage method.
    Code:
    UIImageView *imageView = [[UIImageView alloc] init];
    [imageView setImage: [UIImage imageNamed:@"imageInBundle.png"]];
    [viewToAddImageTo addSubview: imageView];
    
    Loading a texture is a bit more complex in OpenGL. Apple has an example project creating a texture for OpenGL. It is for mac but the code would be nearly identical for iPhone. CoreImageGLTextureFBO
     
  3. newbRacer thread starter macrumors newbie

    Joined:
    Jul 30, 2009
    Location:
    Singapore
    #3
    I see... so means by using the above 3 lines, I will already be loading and rendering the graphics. Am I right to say that?

    Thank you for your help. :D
     
  4. rossipoo macrumors regular

    Joined:
    Jun 7, 2009
    #4
    You can also add a UIImageLayer using Interface Builder. If the image is already part of your project, the image will appear under the Media list in the Library window. You can simply drag the image to your window and resize it how you like. Note that it will be stretched to fit, so you should resize the image beforehand to exactly the size you need.
     
  5. newbRacer thread starter macrumors newbie

    Joined:
    Jul 30, 2009
    Location:
    Singapore
    #5
    Thank you for the other suggestion. It would be very helpful if you could link me to a tutorial or give me tips on how I could do it the Interface builder method.

    Thank you once again. Really appreciate your help.
     
  6. simplymuzik3 macrumors 6502a

    Joined:
    Jan 29, 2009
    #6
    Here's a good tutorial that shows you how to add a background for your entire game!

    http://www.youtube.com/watch?v=S3h8hwP_l24

    It also shows you how to work with layers and transparency! It really helped me when I was trying to do what you are doing now. Hope this helps you!
     
  7. newbRacer thread starter macrumors newbie

    Joined:
    Jul 30, 2009
    Location:
    Singapore
    #7
    thank you for your help. =)
     

Share This Page