How to instruct initial actions on app launch (noob question)

Discussion in 'Mac Programming' started by Cbswe, Jan 12, 2010.

  1. Cbswe macrumors member

    Joined:
    Jan 11, 2010
    #1
    Hi!

    I recently picked up obj-c (started two days ago) and
    as suspected I'm running into a wall of problems.
    What I'm trying to achieve is simply an application which has the ability to display images (and videos) and I want to be able to control the flow of events
    somehow already from when the app is launched.

    Is there any method I can implemented and that will be run after the interface
    has loaded.. or can I somehow get the app to call upon a method after it's initialization?

    Any help is much appreciated and I'll gladly try to formulate the problem
    more clearly if there is any doubt of what I'm asking.

    //Carl
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    -awakeFromNib is what you're looking for.

    What you should probably be looking for, though, is an easier first project. Your expectations are awfully high if you are just starting to learn Objective-C and Cocoa.

    -Lee
     
  3. Cbswe thread starter macrumors member

    Joined:
    Jan 11, 2010
    #3
    Thanks a lot!

    Yes, I know I should start easier.. But I love a challenge :)

    I'm not completely new at OO though. I've worked with java for more then a
    year and I made a very simple FPS game with Java OpenGL.


    My ultimate long-term goal with cocoa atm, is to re-implement Myst.
    Being a huge myst-fan I'd love to see the original game running natively
    in OS X!

    I'd try to reverse-engineer it, but It's a little too hard.
    And the game being so small, a re-implementation seems easier.
     
  4. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    Good luck, then. My intention was not to discourage. We often see people that have just started programming, or have a little experience with other languages and are just starting Obj-C/Cocoa and they say they "just want to make a 2D game", etc. Setting the bar so high(even if they don't know they're setting the bar high) when they're just starting out tends to be discouraging for them because they won't see progress towards their ultimate goal for a long time. If you're already an adept programmer, than your goals may not be as far-fetched.

    -Lee
     
  5. Cbswe thread starter macrumors member

    Joined:
    Jan 11, 2010
    #5
    Ah I've myself met a lot of people who don't know much about how programming
    works and think it's a lot like painting. :)
    Of course it can be if you make it with certain "app-builders".

    I was actually a little surprised at the role of the interface builder.
    I thought building the interfaces in cocoa would be a lot like building
    interfaces in java swing. But in retrospect it makes a lot of sense to make
    the UI-builder graphical, especially when you write it for an OS where
    appealing looks is essential.

    By the way, I understand the majority of 3rd party cocoa apps is windowed.
    How hard would you say it is to get the application to run full-screen?

    //Carl
     
  6. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #6
  7. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    If that's your goal, and Cocoa + Obj-C isn't also a goal, then maybe you should consider a game engine, like Unity.

    See this current thread:
    http://forums.macrumors.com/showthread.php?t=847348
     
  8. Cbswe thread starter macrumors member

    Joined:
    Jan 11, 2010
    #8
    Thanks for the advice. I would agree. It's just that Myst is a very simple
    game and I don't know if I actually can use a game engine to my advantage
    for this particular task.

    My current main worries is recreating effects properly such as the card
    transition (you know when one images replaces the previous random pixel by
    pixel, though fast of course) or the scanning of the telescope machine at the
    observatorium on the main island.

    Other worries are the low-level stuff.. Such as creating proper forks for the
    images and sounds in the resources.

    I wouldn't know if a game engine could actually help out with this sort of objectives.
     
  9. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #9
    You should probably study Core Image. Mac OS 10.4+ has a very rich selection of filters for doing this kind of thing.
     
  10. Cbswe thread starter macrumors member

    Joined:
    Jan 11, 2010
    #10
    A new interesting complication has arisen.
    When I use a QTMovieView with a valid QTMovie and make the
    QTMovie play at the end of awakeFromNib, the movie stops when the interface
    has finished loading.

    I'm thinking of threading it and delaying a thread that after interface
    initialization plays the movie. But I'd love a more elegant solution.
     
  11. Cbswe thread starter macrumors member

    Joined:
    Jan 11, 2010
    #11
    Thanks a lot, I'll check it out!
     
  12. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #12
    Look at the delegate methods of NSApplication. Find something that's called when the app has finished launching. (Subtle keyword hints are included in prior 2 sentences.)

    I could be more specific, but I think it's important for you to:
    a) Search the docs yourself.
    b) Read more of a class's doc than just the one thing you're looking for.
     
  13. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #13
    Yeah, you do not want to do that. Do not start messing around with threads until you fully understand what you are dealing with. If there is a way to avoid threading (cf. NSTimer), take it and don't look back.
    </voice-of-experience>
     
  14. Cbswe thread starter macrumors member

    Joined:
    Jan 11, 2010
    #14
    Thanks. I'll make sure to do that! I'm thinking of buying a book on cocoa
    to really get a proper understanding of how the components are supposed
    to be used. Apple's cocoa introduction guide was way to shallow to go on..
    Then again I'm sure it really was only made to get the user familiar with the
    development environment more then anything else.

    Yes, threading is always a second hand solution in my book.
    One time I had used threading to make basis for an engine and
    after several weeks I suddenly realized I didn't have to thread it
    after all.. Took a bit of rewriting to fix it. In the end the total code
    decreased about a fifth in size. :)
     
  15. Cbswe thread starter macrumors member

    Joined:
    Jan 11, 2010
    #15
    Got the QT movie working!

    I used a applicationDidFinishLaunching in the AppDelegate-code.
     

Share This Page