views:

85

answers:

2

What would be the best way to have a vertical scrolling screen? My game will consume two screens high, the user should be able to move between the two screens by a simple drag or swipe action. The background is not tiled and sprites will be placed on it. What would be the best way to go about such screen management?

A: 

It depends on whether you want users to be able to see half of the top and half of the bottom screen, or only ever the top or the bottom.

You could try placing the two screens worth of content into a ScrollViewer, and setting the ScrollViewer.VerticalScrollbarVisibility to False; this would allow users to drag/swipe easily between the "screens".

Something like:

<ScrollViewer VerticalScrollBarVisibility="Hidden">
    <my:FirstScreen/>
    <my:SecondtScreen/>
</ScrollViewer>

One thing to consider would be whether you want to handle the user changing the phone orientation, or whether you'll lock the phone into Portrait/Horizontal orientations. I also believe that phones with different resolutions will eventually be released and any applications in the Windows Marketplace will need to be able to handle both full and half resolutions.

Blakomen
I was planning on locking the phone in Portrait orientation.Handling different resolutions should not really be an issue. Rob Miles has a nice article here:http://www.robmiles.com/journal/2010/8/15/understanding-windows-phone-orientation-in-xna.html
anonymouse
This answer seems to apply to Silverlight, not XNA.
Andrew Russell
Thats what I was just about to write. Is it even possible to use common controls whilst in an XNA project.
anonymouse
Hmm - I don't think you can mix Silverlight and XNA UI controls in the same project so you might have to find some other alternative; I know you can access XNA apis for things like touch gesture, microphone input etc in a Silverlight phone project but not sure if it works the other way around. Might be worth explicitly stating in your question that you're looking to do so in an XNA project :)
Blakomen
+1  A: 

You have asked two questions here. The fist of which is how to respond to touch gestures (like a swipe). This blog post and associated sample is a good starting point.

The second of which is how to have two screens. This is also simple. Pass a translation matrix (Matrix.CreateTranslate) into SpriteBatch.Begin. How you want to do this is up to you. If you want both screens to have (0,0) be the top left of the screen, give each of them a translation matrix and translate one downwards by the display's height below the other. (While a screen is out of view, you could skip drawing it entirely.)

When the user swipes, simply animate the translation such that one screen moves out of view, and the other moves into view.

Andrew Russell