So unsurprisingly the initial version of Super Pong was rejected on a selection of grounds which means going back to deal with them one by one. Some of them have been small changes, while some have involved me learning new way of doing things.
Once I know I’ve solved the bugs and that my solutions have been approved I’ll talk about what I did to solve them, but their are a few thing I wanted to mention first; namely a website which has been a constant help for my fledgling attempts to get an app on the store, and the ability to use touch in my application.
The website which has been really helpful is http://blogs.msdn.com/b/bobfamiliar/archive/2012/08/07/windows-8-xna-and-monogame-part-3-code-migration-and-windows-8-feature-support.aspx. It’s a exceptional blog post for anyone trying to get a XNA game into Monogame and then into the store, with details about information that needs to go into trying to get an app on the store; from details about the Monogame content pipeline, to sizes of all the images that the store needs, to information on dealing with snapped apps in Windows 8. I highly recommend using this website if you’re thinking of developing apps for the Windows 8 store.
As far as touch goes, it was considerably simpler than I had anticipated. Following a misleading post I found which said mouse counted as touch (it doesn’t), I discovered that for XNA for Windows 8 using Monogame, firstly I had to add
using Microsoft.Xna.Framework.Input.Touch;
Which allows for the use of touch inputs for Windows Phones as well as tablets and desktops. Then I had to add a global variable:
TouchCollection touchCollection;
This “TouchCollection” holds all of the touches on screen, allowing coding for multiple touch inputs later in development, as well as just for one. To get the touches into the TouchCollection you need to call:
touchCollection = TouchPanel.GetState();
For the instances when I need to check if something has been touched, I use a simple foreach loop;
foreach (TouchLocation tl in touchCollection)
{
}
tl giving options such as State, Position, Pressure and ID. With this I built a method which I use to detect if a touch is within certain bounds, such as a button or just the screen:
bool touchSelect(Rectangle target)
{
foreach (TouchLocation tl in touchCollection)
{
if (tl.State == TouchLocationState.Pressed &&
tl.Position.X > target.Left &&
tl.Position.X < target.Right &&
tl.Position.Y > target.Top &&
tl.Position.Y < target.Bottom)
{
return true;
}
}
return false;
}
Certain situations need me to specify where the touch actually is and whether it is continuous or just pressed, but as a rule of thumb the above method works very well.
I hope this was helpful,
Adam
Good stuff. Bob Familiar does do some good stuff. One tip, you might like to format your code segments in Courier or some other monospaced font so that they stand out from the text. Not sure how you write your blog posts, but I use Live Writer, which has quite a nice code plugin which will format code samples and even does syntax highlighting.
Anyhoo, keep up the good work.
I had been using the built in one, I hadn’t thought of using an external writer. I’ll give live writer a go 🙂
this code are more helpfull!
private bool CheckRectangleTouch(Rectangle target, TouchCollection touchCollection)
{
if (touchCollection.Count > 0)
{
foreach (var touch in touchCollection)
{
if (target.Contains(touch.Position))
{
return true;
}
}
}
return false;
}