Hey there. I was just wondering if there is support for landscape mode?
x = 0->480, y = 0->320?
landsape support?
(15 posts) (5 voices)-
Posted 2 years ago #
-
Hi Mike!
Yes there is! It's quite simple, actually. Just add one Sprite to your game's main class (the one that is a subclass of SPStage), and rotate it by 90 degrees (see below). Now, just add all other content to that Sprite instead of the stage.
// mContents is the main sprite, all the game's displayObjects // are children of it. Since the game is played in landscape // format, it is rotated by 90 degrees. mContents = [[SPSprite alloc] init]; mContents.rotation = SP_D2R(90); mContents.x = 320; [self addChild:mContents]; // 'self' is your stage [mContents release];This sprite will have exactly the properties you want: when you hold your iPhone in landscape mode, the point (0|0) will be at the top left, (480|320) will be at the bottom right.
BTW, to automatically start the iPhone simulator in landscape mode, add the following key-value pair to your "Application-Info.plist":
<key>UIInterfaceOrientation</key> <string>UIInterfaceOrientationLandscapeRight</string>I hope that helps!
Posted 2 years ago # -
thanks Daniel that's really great!
I love how easy it isPosted 2 years ago # -
Hi Daniel
It works great! But I can't figure out how it works..If you have time can you explain what it's doing?
Thanks!Posted 2 years ago # -
Hi Mike!
No problem =)
Just recall the analogy I made in the Sparrow introduction document, the one with the pin board:
Imagine a big pin board, hanging on the wall in portrait mode, just like the default iPhone orientation. Let's say that pin board is 320mm wide and 480mm high. It represents your iPhone screen, or, in Sparrow-speak: the stage. If you draw a coordinate system on that board, the origin will be at the top left position, the x-axis points right, the y-axis down. So far, no problem.
Now, take a piece of paper that has the same size as the pin board, and lay it down before you in landscape (!) mode. Draw the origin at the top left, and the axes (the x-axis going right for 480mm, the y-axis going down for 320mm). That paper represents the coordinate system we want: one that is in landscape mode.
When you add that sprite to the stage, it will be added at the point (0|0). In our analogy, pierce the pin first through the origin of the sheet of paper, and then through the origin of the pin board. Step back and have a look at pin board and paper:
- The two coordinate systems are the same: x- and y-axis of pin board and paper lie exactly over each other.
- However, the paper exceeds the pin board at the right, and fills it only for about two thirds down.
What we have to do now is to move the sheet of paper around so that it takes exactly the space of the pin board. Then we would have the coordinate system we need: one that is in landscape mode and takes up our screen.Look back at the (portrait mode) pin board and the (landscape mode) sheet of paper. It's easy to realign it: first we rotate it by 90 degrees about its origin (clockwise). That makes the x-axis point down, and the y-axis point left -- just as we want it to. But now, the positive y-axis is outside of the pin board! To rectify that, we remove the pin, move the paper to the right (so that its origin is directly above the top right corner of the pin board), and re-anchor it with the pin.
In other words:
mContents.rotation = SP_D2R(90); // rotate paper by 90 degrees mContents.x = 320; // move paper to the rightNow, our paper is attached just like we want it to: x-axis goes down, y-axis goes left, the origin is in the top right position. VoilĂ , that paper is in portrait mode!
I hope I could explain it well enough -- it's far easier to explain with a pencil and a sheet of paper than with words alone
Best regards,
DanielPosted 2 years ago # -
ah I think I'm understanding
the only thing confusing is after you move it to the right by 320 if you use
a piece of paper the pinboard is still in portrait mode so some of the paper ends up outside
of the stage which would seem to make things in the sprite not visible at the edges?Posted 2 years ago # -
Hi Mike!
I just edited the text of my last post -- I think it should be clearer now! Please tell me if this explanation is better than the last one; I might create a "Frequently asked questions" page and add that explanation there, as well
Best regards,
DanielPosted 2 years ago # -
Thanks Daniel
That's perfect! I see exactly now how that works. That would be a great FAQ answer. Just curious does this make
the whole game a little slower? If it does it's probably not by much I'm guessing.
Thanks again!
MikePosted 2 years ago # -
Hi Mike!
Don't worry about it. That adds too little overhead to speak about it. Group your game in as many sprites as you want -- if it makes the code cleaner, it's always a win.
Daniel
Posted 2 years ago # -
Sorry to dredge up an old post, but I wanted to ask something. I have been playing around with the default and icon file ideas so that Ican try to have a stylish image and icon for the game. But I have run into a snag and I was wondering if the same thing was happeniong to other people.
I have a Default.png file which is a green screen with the words 'Now Loading...' on it, done in landscape mode. I set things up so that this file was added to the mContents sprite after it had been made up, but before the normal title screen was added.
My problem now is that whenever I boot up, instead of landscape, the Default pops up but in 'Normal' mode and the letters are squashed, written from bottom to top.Has this happened to anyone else?
Posted 1 year ago # -
Hi!
I guess you are talking about the "Default.png" image file that is displayed by the system during startup? Apple expects this file to be in portrait mode always -- so you'll just have to rotate it in your graphics editor.
Posted 1 year ago # -
understood. Managed to suss it out, but thanks for the message!
Posted 1 year ago # -
Is there any chance for SPStage orientation? Should be easier. While you initialising SPStage with size, you can chose orientation. Maybe some method for flipping between home right and left when landscape? Anyone?
Posted 1 year ago # -
Actually by using InterfaceBuilder you can just have the Stage itself in landscape, but i don't think you can do it with the UIWindow itself directly. I think you'll have to add a UIViewController to it set that to landscape and then set the SPView to 480 * 320 and the Game object to width 480 height 320.
It's slightly more work but if you have a UIKit menu setup already it should be very easy.
Posted 1 year ago # -
And how about switching home left/home right?
Posted 1 year ago #
Reply
You must log in to post.