Using native UI WP8

Topics: Windows Phone 8
Aug 13, 2013 at 8:25 AM
Edited Aug 13, 2013 at 8:44 AM
How can I use native UI WP8 in and out game?

Scenario:

Out Game: I have 3 screen use native UI WP8
  • Screen Login : Login to server game
  • Screen Group List: Show some groups list player in same area.
  • Screen Room List: Show some rooms are playing game.
    ( I want to use some native UI like: Textfield for input text, List View or Grid View, Dialog, MessageBox ...)
In Game: When user select a room list, the in game will start use Cocos2d XNA WP8 to render UI, Sence, v.v.. in game.

How can I combine both of them to buid this game (native UI, cocos2d) ?
Please suggest me, how to switch between native UI, and cocos2d ( RoomScreen.xaml <-> GamePage.xaml) and load assets for them.

Thanks so much.
Coordinator
Aug 13, 2013 at 5:00 PM
I am no expert on windows phone XAML apps. You don't have to construct the game object until you need it, so you should be able to do the native UI stuff and use a navigator to switch to the Game XAML. Once in the game the Game instance is created and you can play. When the user escapes from the game, just dispose of the game object and recreate it when they resume.
Aug 14, 2013 at 8:36 AM
Edited Aug 14, 2013 at 12:59 PM
Thank you Totallyevil

How can I generate .plist.xnb file for create CCSpriteFrameCache.. AddSpriteFrameName() form .plist file?
Coordinator
Aug 14, 2013 at 4:12 PM
Step 1 - Add the .plist file to your content project, e.g. Windows XNA project.

OR

Step 1. Add the .plist file to your main game project and mark it as an embedded resource. Then open it as a stream and feed it into the PlistDocument constructor.
Aug 15, 2013 at 4:59 AM
Edited Aug 23, 2013 at 8:42 AM
I am trying to dev for Windows phone 8 as WP8 Project Template. WP8 Project has no Content Project, I just import xnb file ?
Can you give me some line of code, to read blockz.plist and create CCSprite from blockz.png?
Both blockz.plis and blockz.png are mark embedded resource?
Aug 15, 2013 at 11:56 AM
Edited Aug 23, 2013 at 8:42 AM
I am creating a dialog when game running as below:
I want to reuse for many times?
Are have a solution for this?
Coordinator
Aug 15, 2013 at 9:11 PM
mitt9x

CCSprite s = new CCSprite("blockz.png")

-> Content/blockz.png : build action = None and copy = CopyIfNewer

Plist is an embedded resource. You open it like any embedded resource in your assembly, and then once you have the stream, you send it to the ctor:
    public PlistDocument(Stream data)
    {
        LoadFromXmlFile(data);
    }
Coordinator
Aug 15, 2013 at 9:12 PM
tomblack = just make it a CCLayer and "new MyLayer()" any time you want to re-use it. Otherwise, keep the instance around and just remove it from the old parent and add it to the new parent.

CCLayer myLayer = new MyLayer()

AddChild(myLayer, 5)


myLayer.RemoveFromParent();
Aug 16, 2013 at 9:28 AM
Thanks, it got it!
Aug 20, 2013 at 9:44 PM
Hi, totallyevil.

I have tested your approach of creating new sprite with WP8 template, but I'm still getting nothing.
I'm using at the end of the constructor of IntroLayer class (the default one that comes with the template):
        CCSprite sprite = new CCSprite("test.png");
        sprite.Position = CCDirector.SharedDirector.WinSize.Center;
        AddChild(sprite);
And the test.png file is configured as following:
        Build Action: none
        Copy to Output Directory: Copy if newer
So, at this point, when I'm checking in "bin/WindowsPhone/x86/Debug/Content" folder, the file is loaded, but in properties of a sprite, most precisely in sprite.Texture, almost all values are equal to zero and XNATextute = null.

Have you any idea of what is happening?

Thanks in advice.
Best regards.
Aug 21, 2013 at 5:16 AM
Edited Aug 21, 2013 at 5:17 AM
Dear,

There a two screen that I describle as above #1

Screen: Outgame.xaml -> GamePage.xaml

Outgame have a Start button, click it, Navigate to GamePage.xaml and Init Game
I want to get back to Outgame screen from Ingame

At Game1.cs
        public delegate void DelegateBackToOutGame();
        public event DelegateBackToOutGame backToOutGame;
        private void ProcessBackClick()
        {
            if (CCDirector.SharedDirector.CanPopScene)
            {
                CCDirector.SharedDirector.PopScene();
            }
            else
            {
                //Exit();
                backToOutGame();
            }
        }
At GamePage.cs. Register event backtooutgame
 // Constructor
        public GamePage()
        {
            InitializeComponent();

            _game = XamlGame<Game1>.Create("", this);

            _game.backToOutGame += _game_backToOutGame;
        }
        void _game_backToOutGame()
        {
            _game.Dispose();
            Dispatcher.BeginInvoke(() =>
            {
                NavigationService.GoBack();
            });
        }
What is game.Dispose() should be place?
How can I reCreate game object?

I can't return OutGame.xaml and recreate game object?

Sometime, there is error message: AssetsNotDisspose... is null.

:| Please support me Totallyevil.

Thanks so much!
Coordinator
Aug 21, 2013 at 9:18 PM
Hello,

Your game object will not be disposed until your GamePage is disposed. In that case, you want to extend your game class so that it can resume. When you navigate to the other service, you need to set the game on pause. You can do this with:
        CCDirector.SharedDirector.Pause();
Then when you navigate back to the game, you call:
        CCDirector.SharedDirector.Resume();
You may want to do other things in your pause/resume handling, but the two commands I listed above will pause and resume processing in the game.
Coordinator
Aug 21, 2013 at 9:20 PM
Andrey, make sure that you have the PNG file under your "Content" folder in your project.

Project
Game1.cs
Content
 MyAsset.png 
That will copy the png file to your output directory and under the Content folder.
Aug 23, 2013 at 8:48 AM
Edited Aug 30, 2013 at 8:14 AM
I want to dispose GamePage and free all object in it. When I switch between 2 screen OutGame.xaml <->GamePage.xaml, that GamePage will create. I dont want to use Pause()/Resume() because memory will release once I leave Ingame, and GamePage must be recreated when I return InGame?

Have you any solution for me?

Thanks so much!
Coordinator
Aug 25, 2013 at 5:25 PM
hello,

We don't have an immediate solution that works perfectly with this situation. One would likely run game.Dispose() and expect all of its objects to be collected or marked as such. The problem with this method is the static state maintained both by the XNA runtime (MonoGame) and the static state maintained by cocos2d-xna. We'll look into this and see if we can find a solution.

Thanks
Aug 28, 2013 at 10:14 AM
Could I call a "native View" in cocos2d XNA WP like Cocos2d for iOS ?
[[[CCDirector sharedDirector] view] addSubview:mainView];
Coordinator
Aug 28, 2013 at 10:28 PM
There's no reason why you could not invoke another view outside of the game. You just can't mix the game view system with any non-cocos2d-xna objects.