XNA Displaying splash screen while content is loading - windows

I'm trying to include splash screen into my XNA project while content is loading. I tried few tutorials but none has helped me. I was trying load content in update method, forcing draw method etc. Since I'm doing my project on Windows PC only I'm looking for a solution to display splash screen (propably animated) in the center of desktop. When content is loaded splash screen should disappear and the game screen should pop up.
I'm looking for some advices and tips how do it since I can't find any help on the Internet.
Personally I was thinking about using Forms but I don't know it well to use it properly.
Thanks in advance.

Since you are loading content, you are probably making a method call that spans over many frames. If you make that call on the GUI thread, you will freeze the game, which isn't what you want.
Instead, call the method inside a Task, and set your game's state as 'loading', and when the task is done, set a state that indicates the task is done.
Then, in your drawing method, you can do something like this:
if (state == State.Loading)
// draw loading screen
else if (State == .....

Extending on what Kendall Fray said, You could use game states like so:
public static GameState currentGameState = GameState.Loading;
public enum GameState
{
Loading, Whatever
}
and on Update or draw:
switch (currentGameState)
{
case (GameState.Loading):
//draw load screen
break;
case (GameState.Whatever):
break;
}

Related

Animating page navigation in WP 8.1 while the current page stays still

In WP 8.1 Store app, how can I change page animation upon navigating to another page within the frame such that the current page stays still while the new page is animating on top of it by moving from the top of the screen to the bottom?
I'm currently animating my navigation like so:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
Frame.ContentTransitions = new TransitionCollection
{
new PaneThemeTransition{Edge = EdgeTransitionLocation.Top}
};
}
But this is animating both pages by moving the current one from bottom to top while the second one simultaneously moves from top to bottom. I'm also seeing a black background while the pages are moving for screen area that's not occupied by any content.
You unfortunately can not navigate to a different page and keep the previous page visible during the animation. That is why all page Transitions right now only support an In-Transition and an Out-Transition. We discussed the issue with Microsoft developers during this years //Build so I'm certain of this information.
If you really need that effect you can perhaps achieve it using a workaround. Instead of placing your content on separate pages you would create user controls and animate those while staying on a single page. This however can be a little tricky due to you manually having to manage "navigation" between the user controls instead of having the system deal with it for regular pages.
More information on how to implement animations in Windows Phone Silverlight Apps can be found in this article: http://msdn.microsoft.com/en-us/library/windows/apps/jj206955%28v=vs.105%29.aspx
I had a similar problem a while ago and it is kind of a workaround as well but it might do the trick for you.
You can place a Frame object taking all the available space on your current page. Then, instead of navigating from your current Page Frame, you navigate from the Frame object you put on top of your actual page.
The problem with this approach is that you would really "get rid" of the first page.
But this can work for you, or at least give you another insight of the problem.

Prevent activating the application when clicking on NSWindow/NSView

I'm working on a screenshot Mac app. I'm trying to rebuilt what happens when you press Cmd-Ctrl-Shift-4: the cross hair cursor and the selection rectangle for the screenshot.
I'm using a custom borderless NSWindow on top of all other windows. I disabled the cursor to draw my own along with the selection rectangle.
My problem is that as soon as I click & drag to capture a screenshot, my app gets activated (because the click is intercepted by my shielding window).
Is there a way how I can receive the click in my custom view/window without having my app get activated?
I tried using an NSPanel with the NSNonactivatingPanelMask flag, but in this case, I have a problem with the cursor: I can't draw my own when another app is active, because I can't hide the cursor for other apps...
Actually, I have a new, better answer to this question involving more undocumented goodies. Here it is for future posterity:
There is an undocumented method on NSWindow that does exactly what you want:
#interface NSWindow (Private)
- (void )_setPreventsActivation:(bool)preventsActivation;
#end
[myWindow _setPreventsActivation:true];
This stops the window from activating both itself and its application when the user clicks on it.
The standard warnings about using undocumented APIs of course apply: Apple may change this at some point (although it's been around for many OS X versions so there's a good chance they won't) and using this may get your app rejected from the Mac app store.
For what it's worth, there's another way to make the cursor invisible globally other than creating a giant window. It involves some undocumented APIs if that's something you can use:
extern "C" {
typedef int CGSConnection;
void CGSSetConnectionProperty(int, int, const void *, const void *);
int CGSMainConnectionID();
}
void allowHidingCursorForBackgroundOnlyApp()
{
CFStringRef propertyString = CFStringCreateCopy(NULL, CFSTR("SetsCursorInBackground"));
CGSSetConnectionProperty(CGSMainConnectionID(), CGSMainConnectionID(), propertyString, kCFBooleanTrue);
CFRelease((CFTypeRef)propertyString);
}
Combine that with judicious use of event taps to capture and filter out mouse clicks, and you can create the same effect as the built-in screen shot feature.
I pray that there is a better way to do this now, but when I had to do something similar I ended up letting my window/view ignore all mouse input, then I used a CGEventTap (see Quarts Event Services documentation) to capture mouse events globally(without removing them from the event queue). I them mapped them manually to my window, created a custom copy NSEvent and manually dispatched it to my window.
The huge downside here (aside from complexity) is that I recall needing to run as root to be able to install the event tap. However, I think there is a way to get permission though universal access.
I'm completely unsure if dispatching a custom NSEvent directly to the window will have the same side effect of activating your application; especially since many things have changed since 10.6... I would suggest a simple test to see if this is feasible before pursuing it.
One more idea, you can override - (BOOL)_isNonactivatingPanel private method in NSWindow subclass:
#implementation MyWindow
- (BOOL)_isNonactivatingPanel
{
return YES;
}
#end
Voila, you got behaviour similar to NSPanel :)

How to make a seamless transition between WP7 splashscreen and first page with same splashscreen

I'm developing a Windows Phone application. When I launch, the splash screen is shown very shortly, and the MainPage.xaml is shown. However, in the MainPage, I setup the camera with the usual code:
if (PhotoCamera.IsCameraTypeSupported(CameraType.Primary))
{
_photoCamera.Initialized += OnCameraInitialized;
// And other event handling
viewfinderBrush.SetSource(_photoCamera);
}
This is simplified, but it all works. My problem is that this takes a while (mabye 0.5 - 1 seconds, I didn't time it exactly).
So what my user gets is a splashscreen that's so fast, he/she can't see it; and a first page that takes just that tiny fraction to experience it as slightly laggy/slow.
I'd like to change it. Have the splashscreen show until everything is initialized. This has the added benefit of branding for me, and a nice experience for the user.
I've tried this:
Add my splashscreen as image into my MainPage, on top of everything else and hide it when everything is initialized
Add my splashscreen in a popup on my MainPage, and hide the popup when everything is initialized (found that here)
This 'works', but I can see a black flash between the splashscreen and my image/popup. Is there a way to make this transition seamless? Or is this fairly normal behavior in WP7?
Your first option should work - but understand that in one trip through a UI-thread method, the UI doesn't actually update until all the code is executed. So break it up into pieces.
1) Load your MainPage.xaml, which has the splash image filling the screen by default
2) Add an event handler for both OnNavigatedTo and LayoutUpdated. When OnNavigatedTo is hit, set a flag to true. In LayoutUpdated, check for that flag to be true, set the flag to false, then run a Dispatcher.Invoke() call on the method you described above.
3) Remove the image or set it to collapsed after that method is completed.

how to detect touch on a sprite in windows phone 7?

Is there any touches began function in windows phone XNA?
Here I am using a Texture2D and I want to detect the tap on it.
How to do that in xna?
You need to use the TouchCollection class and set a TouchLocation for your Texture2D
Get it's state via:
TouchCollection touch = TouchPanel.GetState()
Then iterate over the TouchLocations in your collection, i guess this will be your texture2D's position:
foreach(TouchLocation tl in touch)
Then inside this loop you can check if the location was touched via the State property of tl e.g.
if(tl.State == TouchLocationState.Pressed)
{
//Execute your code here
}
We wrote our own button class and made certain sprites inherit from this button class. Pretty good way to go about it since the entire sprite then acts as a button.

How do YOU implement a setup screen?

As per the tags indicate I'm developing in Xcode for the iPad.
So, I have a New Game setup screen that sits between my main menu screen and the actual game screen. The new game setup screen is supposed to allow the user to customize their game by selecting the number of players, choosing an avatar for each and setting their names. What I've done is I've setup the continue button to write all the settings to a appData.plist file before moving onto the actual game screen. When the game screen appears (the viewDidLoad method) it reads from the plist to add the players to the table with their respective Avatars and so forth.
The question is, is this the right way to pass the data from a new game setup screen to the game screen? Should I use some method to gather the information from the screen and pass it along to the game screen without writting to some file? I guess the ultimate question is how you're supposed to pass data from one view controller to another? I'm using some plist file to write to and then read from when the board appears. I get a sneaking suspicion that this is not the right way to do this. However, I figure at some point I need to save this data to file anyway since I have to be able to restore the state of my app in the even that it gets closed or interrupted. But what is YOUR preferred method to accomplish this?
You can always use the built-in settings screen for your app by making use of the Settings.bundle too. This is very easy and allows you to use the default iPad settings screen for your application settings, rather than setting up a hand-made one.
For passing through information, the information I need is usually a single object (in your case maybe Player.m) and so I create a property in the next view to hold this. And before showing the view I then do (for instance):
GameViewController *gameView = [[GameViewController alloc] initWithNibName:#"GameViewController" bundle:[NSBundle mainBundle]];
gameView.player = player;
[self.navigationController pushViewController:gameView animated:YES];
[gameView release];

Resources