Still learning- how do you force landscape?

Discussion in 'Public Game Developers Forum' started by wastedyuthe, Jan 28, 2009.

  1. Sorry- I am waiting for my book to arrive on learning ObjC and have been learning what I can from websites and podcasts, so I don't know all the ins and outs yet. I have done a couple of simple apps so far, but can't find any sample code which actually tells you how to force landscape mode instead of portrait. Could someone tell me please?
    Thank you.
     
  2. Mew2468

    Mew2468 Well-Known Member

    Oct 20, 2008
    1,652
    5
    0
    Vancouver, BC
    #2 Mew2468, Jan 28, 2009
    Last edited: Jan 28, 2009
    You have to change some code somewhere from UIOrientationPortrait to UIOrientationLandscapeLeft or UIOrientationLandscapeRight.

    That's all I really remember :).

    EDIT: Okay, I looked at one of my random useless apps, and in the (YourProjectName)ViewController.m, you need to change some code...

    /*
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);


    You need to change UIInterfaceOrientationPortrait to either LandscapeLeft or LandscapeRight.

    Hope that helped!
     
  3. #3 wastedyuthe, Jan 28, 2009
    Last edited: Jan 28, 2009
    Wow! Thanks a bunch! I will look into that. I have an idea for a first app, and I needed it landscape.
    I really want to add an option as to which side you want it facing (left or right). But by default, what is the general consensus? Is left or right facing preferable?

    [edit] Yes, tried the above "return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);" and it works a treat. Thank you :)
     
  4. Mew2468

    Mew2468 Well-Known Member

    Oct 20, 2008
    1,652
    5
    0
    Vancouver, BC
    #4 Mew2468, Jan 28, 2009
    Last edited: Jan 28, 2009
    Most games use left (which is home button on the right), but a couple of them use right (such as Trace), so its really up to you to decide. You can, although, code the orientation thing like this...

    *
    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

    And that way, they can use either orientation. Unless you want it to only work one way. I'd go with LandscapeLeft.

    (The space between UIIn and terface isn't intentional...the font did it XD - it should just be UIInterfaceOrientation)
     
  5. #5 wastedyuthe, Jan 28, 2009
    Last edited: Jan 28, 2009
    I put both in there as you did, and it starts off to the right (with the Home button on the left) in the simulator. And if I turn left a couple of times to left landscape, the picture doesn't orientate to the right way up (as it does if I'd just say "return YES;" in that same method (which orientates it to which ever way you hold it up). So even though both are listed, it only shows it the right way up when in Right landscape. Is that right? Do I need to tell it to swap orientation when turning to the left?

    [edit] I noticed if you swap them so Right is listed before Left, the app starts off with left orientation, so it starts with which ever is listed last.
     
  6. Diablohead

    Diablohead Well-Known Member

    Jan 19, 2009
    1,553
    1
    0
    Freelancer, PC game developer
    Information like this is extremely handy and you would think it would be noted somewhere online easy to find, it might be worth noting down stuff like this as I develop for all to read.
     
  7. Hippieman

    Hippieman Well-Known Member

    Nov 6, 2008
    433
    0
    0
    Senior Producer, Designer
    San Francisco
    Don't make a game upside down!

    Use the YouTube or Movie player as your guide.
     
  8. #8 wastedyuthe, Jan 28, 2009
    Last edited: Jan 29, 2009
    I hear ya. Landscape left it is ;)

    [edit] read later posts- should be LandscapeRight.
     
  9. InsertWittyName

    InsertWittyName Well-Known Member

    Nov 26, 2008
    202
    1
    0
    shouldAutorotateToInterfaceOrientation only allows the view to rotate, it doesn't force a landscape orientation.

    To force a landscape orientation add a new entry to your Info.plist file with a key of UIInterfaceOrientation and a value of UIInterfaceOrientationLandscapeLeft or UIInterfaceOrientationLandscapeRight.
     
  10. #10 wastedyuthe, Jan 28, 2009
    Last edited: Jan 28, 2009
    Ahh! Thanks for that. This property list command works together with the 'shouldautorotate...' command I see. Interesting.

    But say I want to add an option in my games settings, so the user can choose which way they want- left landscape or right landscape. There is no way for that property list command to be over-ridden is there?

    (perhaps I am getting in way over my head here :rolleyes: )

    [edit] "Most games use left (which is home button on the right)"
    I set it to LandscapeLeft in the property list, and the Home button is on the left not the right. So, if people prefer the Home button on the right, then I should set it to LandscapeRight.
     
  11. Mew2468

    Mew2468 Well-Known Member

    Oct 20, 2008
    1,652
    5
    0
    Vancouver, BC
    Ahh...more stuff I should know - sorry if I gave any wrong information; I'm not really an experienced dev :rolleyes:...but I will be :D.
     
  12. Rocketman919

    Rocketman919 Well-Known Member

    Aug 8, 2008
    2,302
    25
    38
    Cali-forn-i-a
    damn i need to get an intel mac soon...
     
  13. #13 wastedyuthe, Jan 29, 2009
    Last edited: Jan 29, 2009
    The property list is very helpful. So far, I have been able to force landscape, remove the bar at the top of the window which shows the time and battery etc, and even managed to remove the reflection from the apps Home screen icon. Groovy!

    [​IMG]

    I feel for ya buddy! Thought you already had one.
     
  14. cgriffin

    cgriffin New Member

    Jan 29, 2009
    1
    0
    0
    Not the main app view?

    I have a need for landscape orientation as well. Except I need it for a view that isn't the main app view. Searching the web tells me that I need to rotate the view myself. The problem is that no matter what I set the 'origin' to I can't get the view to rotate correctly, it always rotates off the screen. If anyone has an example on how to do this I would appreciate it greatly.

    Thanks,
    Chris
     
  15. spiffyone

    spiffyone Well-Known Member

    Dec 7, 2008
    2,562
    0
    0
    I'd use both.

    Pet peeve: if you set it one way and one way only, you end up making it a wee bit uncomfortable for iTouch or iPhone users to play the game (depending on which way you set landscape orientation).

    Remember, the headphone jack is in different places on the iTouch and the iPhone. When in portrait (with home button on the lower portion), on iTouch the jack is on the lower right hand side, and on iPhone the lower left hand side. If you don't allow for screen orientation toggle when in landscape mode, inevitably the jack will be on the lower portion of one or the other style of device.

    This is NOT comfortable at all. You've got to keep BOTH style of hardware in mind, as doing so will keep the total amount of end users in mind. And, y'know...we kinda appreciate those little things. :D
     
  16. InsertWittyName

    InsertWittyName Well-Known Member

    Nov 26, 2008
    202
    1
    0
    You cannot override the property list value, no.

    You can however call the function to force an orientation in your applicationDidFinishLaunching or similar method, a quick Google for 'UIInterfaceOrientation force landscape' will give you a few options.

    To actually save the user's preferences from one launch to the next Google for 'NSUserDefaults tutorial'.

    Half the battle of learning is know the key words on what to search for.
     
  17. #17 wastedyuthe, Jan 29, 2009
    Last edited: Jan 29, 2009
    Thank you very much. You are most helpful. You are right about knowing the keywords. I am sure It'll all be a bit clearer when I get my book (hopefully next week). I'm not doing too badly though- done my first app, copying a simple calculator app from a podcast. But I changed it to add a nice background picture of a demon embracing a naked lady, and I changed a button so you have to tap her bum (which turns red when you do so) to get the sum to appear. Hehe!
    I have been working on the title screen of my first proper game today (which will be a simple 2D affair), and am looking forward to getting stuck in.

    [edit] Here's yet another way to do it (from a Google search):

    "Open up your App Delegate M file.

    Put This:

    application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

    Into the:

    - (void)applicationDidFinishLaunchingUIApplication *)application {

    Method.
    "
     
  18. Mew2468

    Mew2468 Well-Known Member

    Oct 20, 2008
    1,652
    5
    0
    Vancouver, BC
    Can't wait to see your final products :)!
     
  19. Thanks, but it's going to be a bit of a wait. Drawing the Main Menu screen graphics is one thing (which I finished last night- looking groovy!)- programming the game mechanics is another, as well as all the animation I'll have to draw. Luckily I have already been writing my own instrumental music for the past couple of years with GarageBand, so I'll just stick some of my already-created music in there. That'll save a bit of work.
     

Share This Page