how to use a component in a project of Silverlight+XNA-template?

Dec 10, 2011 at 9:11 AM
Hi!
I am designing a UI for my XNA program, therefore I switched to a
project generated using Windows Phone Rich Graphics Application
template under XNA Game Studio 4.0 Templates framework. However,
I am stuck with how to add components, e.g. input component, or FrameRate=20
in such project. Any idea how I can use these components in this project?=20
Thanks!
Yajie.
Coordinator
Dec 10, 2011 at 9:46 AM
Actually you don't need a component collection to work with FrameRate and InputConponent. Just create a FrameRate or InputComponent, store it in the GamePage, and call the Update and Draw method where appropriate.

Dec 10, 2011 at 9:56 AM
Thanks! I just noticed this, too~
From: [email removed]
Sent: Saturday, December 10, 2011 5:46 PM
To: [email removed]
Subject: Re: how to use a component in a project of Silverlight+XNA-template? [nine:282471]

From: yufeih

Actually you don't need a component collection to work with FrameRate and InputConponent. Just create a FrameRate or InputComponent, store it in the GamePage, and call the Update and Draw method where appropriate.

Dec 10, 2011 at 9:58 AM
Another thing: without using the components, will the ModelViewCamera work properly?
From: [email removed]
Sent: Saturday, December 10, 2011 5:46 PM
To: [email removed]
Subject: Re: how to use a component in a project of Silverlight+XNA-template? [nine:282471]

From: yufeih

Actually you don't need a component collection to work with FrameRate and InputConponent. Just create a FrameRate or InputComponent, store it in the GamePage, and call the Update and Draw method where appropriate.

Coordinator
Dec 10, 2011 at 12:28 PM
Yes, as long as you manually create and update an InputComponent.
Dec 10, 2011 at 12:41 PM
OK! THX!
From: [email removed]
Sent: Saturday, December 10, 2011 8:29 PM
To: [email removed]
Subject: Re: how to use a component in a project of Silverlight+XNA-template? [nine:282471]

From: yufeih

Yes, as long as you manually create and update an InputComponent.
Dec 11, 2011 at 3:08 PM
Hi,
I manually created an InputComponent in the GamePage of the project,
but since this is not a Game, I couldn’t provide the window handle to the
InputComponent constructor, which makes the Input events unable to be
raised. Is there other way to query the handle in the silverlight+XNA project?
From: [email removed]
Sent: Saturday, December 10, 2011 8:29 PM
To: [email removed]
Subject: Re: how to use a component in a project of Silverlight+XNA-template? [nine:282471]

From: yufeih

Yes, as long as you manually create and update an InputComponent.
Coordinator
Dec 12, 2011 at 2:41 AM
You can just pass null instead, in that case, it will use the default Xna Keyboard and Mouse to handle input. Hope it works.
Dec 12, 2011 at 4:55 AM
No... it doesn’t work... Does that mean I don’t have access to the input detection when switching to
the GamePage? Can I obtain the handle through some API of SilverLight??
From: [email removed]
Sent: Monday, December 12, 2011 10:41 AM
To: [email removed]
Subject: Re: how to use a component in a project of Silverlight+XNA-template? [nine:282471]

From: yufeih

You can just pass null instead, in that case, it will use the default Xna Keyboard and Mouse to handle input. Hope it works.
Coordinator
Dec 12, 2011 at 6:40 AM
Hmm, in that case you can trap the silverlight input events and direct it to the InputComponent. But I haven't implemented a way to do that. I'll go and check the silverlight + xna programming model on the phone.

Thanks.
Dec 12, 2011 at 3:19 PM
Wow, thank you for your attention on this problem. I’m sure finding out the
solution to this problem will make Nine more usable!
Yajie.
From: [email removed]
Sent: Monday, December 12, 2011 2:40 PM
To: [email removed]
Subject: Re: how to use a component in a project of Silverlight+XNA-template? [nine:282471]

From: yufeih

Hmm, in that case you can trap the silverlight input events and direct it to the InputComponent. But I haven't implemented a way to do that. I'll go and check the silverlight + xna programming model on the phone.

Thanks.
Dec 13, 2011 at 2:42 PM
Hi yufeih,
I have found an alternative to obtain the window handle to construct InputComponent: TouchPanel.WindowHandle. Before this, several desired gestures need first be enabled. Then, the ModelViewCamera responds well to gestures like FreeDrag or Pinch.
I hear from another guy (ID: Konaju Games in MSDN forum) that it is not appropriate to use
handle in a WP7 program. He said “Nothing in any Windows Phone API uses a window handle”. Do you know
why he states so?
Yajie.
From: [email removed]
Sent: Monday, December 12, 2011 2:40 PM
To: [email removed]
Subject: Re: how to use a component in a project of Silverlight+XNA-template? [nine:282471]

From: yufeih

Hmm, in that case you can trap the silverlight input events and direct it to the InputComponent. But I haven't implemented a way to do that. I'll go and check the silverlight + xna programming model on the phone.

Thanks.
Coordinator
Dec 14, 2011 at 3:05 AM
I also don't recommand using "Window handles" on the phone. Handle is a legacy Win32 term that is used to identify a window. I think Xna exposes the handle on Windows for the possibility to interop with Windows Forms or Win32.
Down to the implementation of InputComponent, when a handle is specified and the target platform is Windows, InputComponent will find the Windows Form from that handle, and listen to mouse and keyboard events using Windows Form. These input events are queued and is independent of the game frame rate. So even when the game is running extremely slow, it is unlikely to lose any input events. This has an advantage over the polled model, where you get the mouse state this frame and compare it with the last frame, if the frame rate is low, there's a great change that some mouse clicks in between the frames are missed.
Dec 14, 2011 at 3:32 AM
Thanks for explaining!
I find that in the type of project I’m using (silverlight+xna) when the TouchPanel’s enabledgestures is assigned, the modelviewcamera responds to input events well even null is passed to the InputComponent. However in regular XNA game project I don’t need to explicitly assign the enabledgestures. Is it because in XNA Game this property has already been assigned proper value?
From: [email removed]
Sent: Wednesday, December 14, 2011 11:05 AM
To: [email removed]
Subject: Re: how to use a component in a project of Silverlight+XNA-template? [nine:282471]

From: yufeih

I also don't recommand using "Window handles" on the phone. Handle is a legacy Win32 term that is used to identify a window. I think Xna exposes the handle on Windows for the possibility to interop with Windows Forms or Win32.
Down to the implementation of InputComponent, when a handle is specified and the target platform is Windows, InputComponent will find the Windows Form from that handle, and listen to mouse and keyboard events using Windows Form. These input events are queued and is independent of the game frame rate. So even when the game is running extremely slow, it is unlikely to lose any input events. This has an advantage over the polled model, where you get the mouse state this frame and compare it with the last frame, if the frame rate is low, there's a great change that some mouse clicks in between the frames are missed.