android
  #1  
Old 03-28-2011, 05:24 PM
jbgrzy's Avatar
jbgrzy jbgrzy is offline
Junior Member
 
Join Date: Feb 2011
Location: Allendale, Michigan
Posts: 84
Default DaveMac - Help!

DaveMac,

Since you are trying to bring the highest quality apps to the Zune HD, could you tell me where (or just give it to me) I could find documentation and other related resources on developing for the Zune HD.

There used to be some stuff on create.msdn.com, but it has all been removed for WP7 stuff.

Could you help?

Thanks,
jbgrzy

(p.s. I am trying to make an app worthy of being in the marketplace, and I know many Zune HD users would be happy to have it, but I keep getting stuck on the specifics of how to accept input from the touch panel. The documentation on the msdn library is not helpful at all.)
Reply With Quote

Advertisement [Remove Advertisement]

  #2  
Old 03-28-2011, 05:39 PM
shakermaker41 shakermaker41 is offline
Junior Member
 
Join Date: Sep 2009
Location: colorado
Posts: 80
Default

WP7 and Zune both use the same exact interfaces in the XNA framework (for the most part)

Anything you find for manipulating the touchscreen on WP7 will be exactly what you need for the Zune.
Reply With Quote

  #3  
Old 03-29-2011, 10:19 AM
jbgrzy's Avatar
jbgrzy jbgrzy is offline
Junior Member
 
Join Date: Feb 2011
Location: Allendale, Michigan
Posts: 84
Default

Quote:
Originally Posted by shakermaker41 View Post
WP7 and Zune both use the same exact interfaces in the XNA framework (for the most part)

Anything you find for manipulating the touchscreen on WP7 will be exactly what you need for the Zune.
Actually this is not true. (Trust me, I looked) XNA 4.0 (for WP7) has a set of predefined 'gestures'. For example, they have a gesture for a finger swipe. So the framework knows what a swipe is and then the code does what you tell it to when it recognizes a swipe.

XNA 3.1 (the version you need to use if you want to develop for the Zune HD) does not have predefined gestures. The only thing they have is TouchPanelState which has the values: pressed, moved, and released. Which is different than a predefined gesture.

Anyways, what I wanted was any documentation that used to be on the XNA Creators Club website (The name was recently changed to AppHub for WP7). For some reason they removed the documentation when they changed the name.

So, in short, XNA 4.0 is different from XNA 3.1 when it comes to handling screen touches.

Thanks,
jbgrzy
Reply With Quote

  #4  
Old 03-30-2011, 06:45 AM
roguemat roguemat is offline
Member
 
Join Date: Oct 2009
Posts: 263
Default

Yes, XNA's different versions and platforms vary slightly, but they are similar enough. I wrote a tutorial a while back for coding an XNA game for PC - after that to make it work on PC, I just had to change the mouse input to touch.
Yes, WP7 has gesture support, but that really isn't hard to do yourself.

A naively simple example: Record a Vector2 of their finger as the touch registers, then when it releases take another one and compare them. If it's moved more on the Y axis than the left, then its a swipe across and vice-versa.
You can then also take a DateTime of when they touch and then compare that to the current DateTime when they release to see how fast they moved.

So basically, read the MSDN docs and create.msdn.com tutorials on XNA for either WP7 or PC and then just change what you need to.
__________________
Follow me on twitter and check out my blog
Reply With Quote

  #5  
Old 03-30-2011, 09:51 AM
jbgrzy's Avatar
jbgrzy jbgrzy is offline
Junior Member
 
Join Date: Feb 2011
Location: Allendale, Michigan
Posts: 84
Default

Thanks roguemat,

That gives me some pointers to work off of. Though I am still frustrated at the lack of documentation on programming for the Zune HD. There used to be stuff on create.msdn.com, (the remnant pages are still there, though the actual documentation isn't) but they must have decided that they didn't want that information there anymore because of WP7.

Thanks again,
jbgrzy

(p.s. when are you going to get your website completely up again?)
Reply With Quote

  #6  
Old 03-30-2011, 10:27 AM
FallenArms3 FallenArms3 is offline
Member
 
Join Date: Nov 2009
Posts: 259
Default

It's true that the Zune's touchscreen input could use more documentation. It's also unfortunately true that it's nowhere near as easy as WP7.

Here's a quick intro:

The first thing you want to do is create a TouchCollection. This class will store all the data from the touchscreen. Personally I usually make this a class variable (i.e., I don't instantiate it every Update. I don't know if this makes much of an efficiency difference).
Code:
TouchCollection touchCollection;
Now, in the Update method of either your main game or whatever class needs input, you give your touchCollection the current state of the touchscreen.
In the UPDATE:
Code:
touchCollection = TouchPanel.GetState()
Now all our data from the touchscreen for this frame is loaded. As far as we are concerned, the TouchCollection class acts as a list of TouchLocations, each of which stores any properties you would need to interpret input. The general format which I like for dissecting and interpreting the TouchCollection is like so:

Code:
foreach(TouchLocation location in touchCollection)
{
   switch(location.State)
   {
       case TouchLocationState.Pressed:
       {
           //What you want to do when a finger first touches the screen
           break;  //break is necessary in "switch" statements
       }
       case TouchLocationState.Moved:
       {
           //Contrary to what you might think, a TouchLocation does not only
           //switch state to Moved when it is moving.  Moved is EVERY frame
           //after the initial press, even if the finger is completely still.
           break;
       }
       case TouchLocationState.Released:
       {
           //This is the frame directly AFTER a finger is removed from the
           //screen.  When you're dealing with buttons, etc, you generally
           //want to make the button activate here, just like you can hold
           //your mouse on a button for as long as you want and it only
           //activates when you release.
           break;
        }
    }
}
Ok, so that's the foreach loop which you will run every Update when you want to check touch input. Everything else you put where the comments are. Here's a few helpful things you can do with touches:

Checking to see if a user touched in a certain area
Code:
Rectangle myRect = new Rectangle(x , y , width , height);
In the appropriate case section for when you want to detect the input:
Code:
if(myRect.Contains(new Point((int)location.Position.X, (int)location.Position.Y))
   //do something!
Now, what did we do there? We checked to see if the rectangle contains a Point which was created using the Position of the current location iterator in our foreach loop. Unfortunately, Rectangle.Contains() does not accept a Vector2 as a parameter, so we must convert to a Point. Optionally, if you have a lot of rectangle checking, you can create a Point right off the bat at the beginning of your foreach loop (before the switch statement).

Determining the velocity of a moving touch

In the TouchLocationState.Moved case:
Code:
TouchLocation previousLocation = location.TryGetPreviousLocation(out previousLocation);
float velocity = Vector2.Distance(location, previousLocation);
//OR
float realVelocity = velocity / gameTime.ElapsedRealTime.Seconds;
A little explanation: "velocity" is in pixels/frame, "realVelocity" is in pixels/second. Depending on how you've got your game set up, you might want one or the other. Most example code uses real time.

I'm actually a little shaky on my Vector math, but you could theoretically find all sorts of things from the previous location, such as a unit vector for direction, etc.

I hope this was helpful. If there's anything specific you'd like to know how to do, just ask. Once you understand the nature of TouchCollection and TouchLocation, you can understand the possibilities of what to do with them. For instance, did you know each TouchLocation has a Pressure property?
__________________
- Grant F

Last edited by FallenArms3; 03-30-2011 at 02:08 PM.
Reply With Quote

  #7  
Old 03-30-2011, 12:04 PM
jbgrzy's Avatar
jbgrzy jbgrzy is offline
Junior Member
 
Join Date: Feb 2011
Location: Allendale, Michigan
Posts: 84
Default

Thanks FallenArms3,

That will be tremendously helpful. Thanks for taking the time to write all that out.

Interestingly, I have gotten more help from this forum, then the forum dedicated to the xna framework at forums.xna.com.

Thanks again,
jbgrzy
Reply With Quote

  #8  
Old 03-30-2011, 02:11 PM
FallenArms3 FallenArms3 is offline
Member
 
Join Date: Nov 2009
Posts: 259
Default

Quote:
Originally Posted by jbgrzy View Post
Interestingly, I have gotten more help from this forum, then the forum dedicated to the xna framework at forums.xna.com.
The Creators' Club forums are overrun by WP7 developers who could care less about the poor old HD. Even back when the HD was new on the block, most XNA developers were only concerned with Xbox and PC.

I've found the Development Discussions section of ZuneBoards to be very helpful for Zune coding, though. I would highly recommend it as you move forward. Feel free to contact me, too.
__________________
- Grant F
Reply With Quote

  #9  
Old 03-31-2011, 01:59 PM
jbgrzy's Avatar
jbgrzy jbgrzy is offline
Junior Member
 
Join Date: Feb 2011
Location: Allendale, Michigan
Posts: 84
Default

Ok, so here is what I got.

Code:

TouchCollection touchCollection = TouchPanel.GetState();
TouchCollection touches = TouchPanel.GetState ();
foreach (TouchLocation location in touches)
{
switch (location.State)
{
caseTouchLocationState.Pressed:
{
loc1 = location.Position.Y;
}
break;
caseTouchLocationState.Moved:
{
TouchLocation prevLoc;
if (location.TryGetPreviousLocation(out prevLoc))
{
loc2 = prevLoc.Position.Y;
}

}
break;
caseTouchLocationState.Released:
{

}
break;
}

}


// check if touch moved up
if (loc2 < loc1)
{
distUp = loc1 - loc2;
isUP = true;
}
//check if touch moved down
if (loc1 < loc2)
{
distDown = loc2 - loc1;
isDown = true;
}
// if the touch moved up
if (isUP == true)
{
fontPos.Y = (fontPos.Y - distUp);
isUP = false;
}
// if the touch moved down
if (isDown == true)
{
fontPos.Y = (fontPos.Y + distDown);
isDown = false;
}
But whenever I just touch the screen, the text dissappears.
Does anyone know why?

Thanks,
jbgrzy
Reply With Quote

  #10  
Old 03-31-2011, 05:24 PM
roguemat roguemat is offline
Member
 
Join Date: Oct 2009
Posts: 263
Default

I don't have time to go through the code to see the problem, but what it looks like you are doing is just moving the text with the finger.
Instead of all that code you did you can instead just do this:
Quote:
fontPos.Y = touchCollection[0].Y; //after checking that touchCollection has atleast one value.
__________________
Follow me on twitter and check out my blog
Reply With Quote

  #11  
Old 03-31-2011, 07:44 PM
jbgrzy's Avatar
jbgrzy jbgrzy is offline
Junior Member
 
Join Date: Feb 2011
Location: Allendale, Michigan
Posts: 84
Default

Quote:
Originally Posted by roguemat View Post
I don't have time to go through the code to see the problem, but what it looks like you are doing is just moving the text with the finger.
Instead of all that code you did you can instead just do this:
When I do that, the font origin jumps to where my finger is, which doesn't help much for a long string of text.

Thanks though,
jbgrzy
Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 01:51 PM.