WinPhone cross-platform font game code not working

Hi, First of all thanks for providing the new Visual Studio templates for CocosSharp v1.3 - I'd already got my Android and iOS projects up and working on my Mac and now I am creating the WinPhone project for my game (using Visual Studio 2013 Community Edition running under Parallels).

I have a problem with fonts though on WinPhone, I use the following in my shared PCL game code:
GameOverLabel.FntFile = "fonts" + GameGlobals.DirectorySeparatorChar + "helvetica-32.fnt";

... and this works just fine on Android and iOS but I get the following exception thrown on WinPhone:

Microsoft.Xna.Framework.Content.ContentLoadException was unhandled by user code
  HResult=-2146233088
  Message=Failed to load the asset file from fonts\helvetica-32.fnt
  Source=CocosSharp
  StackTrace:
       at CocosSharp.CCContentManager.Load[T](String assetName, Boolean weakReference)
       at CocosSharp.CCContentManager.Load[T](String assetName)
       at CocosSharp.CCBMFontConfiguration..ctor(String fntFile)
       at CocosSharp.CCBMFontConfiguration.FontConfigurationWithFile(String fntFile)
       at CocosSharp.CCLabelBMFont.FNTConfigLoadFile(String file)
       at CocosSharp.CCLabelBMFont.set_FntFile(String value)
       at Blueprint.Shared.CommonGameScene..ctor(CCWindow gameWindow, GameAppDelegate gameApp, String levelFilename, Int32 stageNumber)
       at Blueprint.Shared.StandardGameScene..ctor(CCWindow gameWindow, GameAppDelegate gameApp, String levelFilename, Int32 stageNumber)
       at Blueprint.Shared.GameAppDelegate.ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
       at CocosSharp.CCApplication.LoadContent()
       at Microsoft.Xna.Framework.DrawableGameComponent.Initialize()
       at CocosSharp.CCApplication.Initialize()
       at Microsoft.Xna.Framework.Game.InitializeExistingComponents()
       at Microsoft.Xna.Framework.Game.Initialize()
       at CocosSharp.CCGame.Initialize()
       at Microsoft.Xna.Framework.Game.DoInitialize()
       at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
       at MonoGame.Framework.WindowsPhone.SurfaceUpdateHandler.Draw(Device device, DeviceContext context, RenderTargetView renderTargetView)
       at MonoGame.Framework.WindowsPhone.DrawingSurfaceUpdateHandler.DrawingSurfaceContentProvider.GetTexture(Size2F surfaceSize, DrawingSurfaceSynchronizedTexture& synchronizedTexture, RectangleF& textureSubRectangle)
       at SharpDX.Direct3D11.DrawingSurfaceContentProviderShadow.DrawingSurfaceContentProviderVtbl.GetTexture(IntPtr thisPtr, IntPtr surfaceSize, IntPtr synchronizedTexture, IntPtr textureSubRectangle)
  InnerException: 

I've tried adding an additional search directory in my game app delegate like this:

application.ContentRootDirectory = "Content";
application.ContentSearchPaths.Add("fonts");

but this does not solve the problem.

Any help greatly appreciated, thanks.
Adrian

Posts

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Adrian

    I suspect that it is because the WP8 requires the font to be in .xnb format built via a content project. Can you provide a copy of the .fnt and corresponding resources for us to verify.

  • I used one of the fonts from the CocosSharp Git repo... tests/testContent/fonts/helvetica-32.fnt which references helvetica-geneva-32.png

    As I said, it all works on iOS and Android.

    I've also read somewhere in a Cocos-2D question (not sure if it applies to CocosSharp) on the web somewhere that you have to load in the .fnt file first and then manually load in the .png file into a stream (if memory serves) and then it works on WinPhone.

    I was hoping to use the same assets, including fonts on multiple platforms without having to try and have branching code in my game PCL file that knows anything about the physical hardware/OS that it is running on.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Adrian

    It does not work that way for CocosSharp because the underlying resource loader is MonoGame so it is a little different.

    Can you try the .xnb from the content folder of the same .fnt

    https://github.com/mono/CocosSharp/blob/master/tests/tests/Content/fonts/

    https://github.com/mono/CocosSharp/blob/master/tests/tests/Content/fonts/helvetica-32.fnt.xnb

    Try it on all three and let me know how that works.

    With MonoGame only the non windows platforms load raw assets with any consistency. WP8 the last time I checked was only .xnb format.

  • I took that xnb file and added it to my Android and iOS solutions and changed my CCLabelBMFont creation to reference the .xnb instead of the .fnt and both iOS and Android throw an exception:

    System.NullReferenceException: Object reference not set to an instance of an object
      at at CocosSharp.CCBMFontConfiguration.ParseConfigFile (string,string) <IL 0x000eb, 0x003ea>
      at at CocosSharp.CCBMFontConfiguration..ctor (string,string) <IL 0x00041, 0x00173>
      at at CocosSharp.CCBMFontConfiguration..ctor (string) <IL 0x0000d, 0x0005b>
      at at CocosSharp.CCBMFontConfiguration.FontConfigurationWithFile (string) <IL 0x00010, 0x0008f>
      at at CocosSharp.CCLabelBMFont.FNTConfigLoadFile (string) <IL 0x00010, 0x00067>
      at at CocosSharp.CCLabelBMFont.set_FntFile (string) <IL 0x00012, 0x0006f>
      at Blueprint.Shared.CommonGameScene.CreateDefaultLabel () [0x00027] in /Users/user/Documents/F-Drive/AppsMobilis/Blueprint Game/Blueprint/Blueprint.Shared/GameModes/Common/CommonGameScene.cs:623
      at Blueprint.Shared.CommonGameScene..ctor (CocosSharp.CCWindow,Blueprint.Shared.GameAppDelegate,string,int) [0x0027c] in /Users/user/Documents/F-Drive/AppsMobilis/Blueprint Game/Blueprint/Blueprint.Shared/GameModes/Common/CommonGameScene.cs:142
      at Blueprint.Shared.StandardGameScene..ctor (CocosSharp.CCWindow,Blueprint.Shared.GameAppDelegate,string,int) [0x00000] in /Users/user/Documents/F-Drive/AppsMobilis/Blueprint Game/Blueprint/Blueprint.Shared/GameModes/StandardGameScene.cs:310
      at Blueprint.Shared.GameAppDelegate.ApplicationDidFinishLaunching (CocosSharp.CCApplication,CocosSharp.CCWindow) [0x0003b] in /Users/user/Documents/F-Drive/AppsMobilis/Blueprint Game/Blueprint/Blueprint.Shared/GameAppDelegate.cs:149
      at at CocosSharp.CCApplication.LoadContent () <IL 0x00048, 0x00168>
      at at Microsoft.Xna.Framework.DrawableGameComponent.Initialize () <IL 0x00010, 0x0004c>
      at at CocosSharp.CCApplication.Initialize () <IL 0x00008, 0x0003f>
      at at Microsoft.Xna.Framework.Game.InitializeExistingComponents () <IL 0x00029, 0x00104>
      at at Microsoft.Xna.Framework.Game.Initialize () <IL 0x0000d, 0x00063>
      at at CocosSharp.CCGame.Initialize () <IL 0x00001, 0x00027>
      at at Microsoft.Xna.Framework.Game.DoInitialize () <IL 0x00012, 0x00058>
      at at Microsoft.Xna.Framework.AndroidGamePlatform.BeforeUpdate (Microsoft.Xna.Framework.GameTime) <IL 0x0000e, 0x00053>
      at at Microsoft.Xna.Framework.Game.DoUpdate (Microsoft.Xna.Framework.GameTime) <IL 0x0000d, 0x00044>
      at at Microsoft.Xna.Framework.Game.Tick () <IL 0x000f5, 0x00693>
      at at Microsoft.Xna.Framework.AndroidGameWindow.OnUpdateFrame (object,OpenTK.FrameEventArgs) <IL 0x00059, 0x0014f>
      at OpenTK.GameViewBase.OnUpdateFrame (OpenTK.FrameEventArgs) [0x00014] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/opentk/Source/OpenTK/Platform/Android/GameViewBase.cs:313
      at OpenTK.Platform.Android.AndroidGameView.UpdateFrameInternal (OpenTK.FrameEventArgs) [0x00013] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:346
      at OpenTK.Platform.Android.AndroidGameView.RunIteration (System.Threading.CancellationToken) [0x00096] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:551
      at OpenTK.Platform.Android.AndroidGameView/<StartThread>c__AnonStorey0.<>m__0 (object) [0x0000d] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/opentk/Source/OpenTK/Platform/Android/AndroidGameView.cs:452
      at Android.App.SyncContext/<Send>c__AnonStorey1.<>m__0 () [0x00000] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Android.App/SyncContext.cs:32
      at Java.Lang.Thread/RunnableImplementor.Run () [0x0000b] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/src/Java.Lang/Thread.cs:36
      at Java.Lang.IRunnableInvoker.n_Run (intptr,intptr) [0x00009] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.20-series/ba9bbbdd/source/monodroid/src/Mono.Android/platforms/android-17/src/generated/Java.Lang.IRunnable.cs:71
      at at (wrapper dynamic-method) object.a0b1f323-d5b5-48d2-8afe-32cc381ea781 (intptr,intptr) <IL 0x00011, 0x0001b>
    

    Is the .xnb file different between WinPhone and iOS/Android? I would happily swap to .xnb if I could have one that works on all platforms.

    If this is an insurmountable problem then I'll have to use dependency injection (which will basically pass in the font file format to use, i.e. .fnt or .xnb) so that I can still make my game PCL completely standard across all platforms - to keep things simple I'd just ensure that all platforms have the .fnt and .xnb content resources even if some platforms don't use one of them.

    Thanks,
    Adrian

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Hello Adrian

    I am not sure what the problem is that you are having. I just created a new Windows Phone project using the Templates.

    Added the following two files to Content/fonts obtained from

    https://github.com/mono/CocosSharp/blob/master/tests/tests/Assets/Content/fonts/helvetica-32.fnt.xnb
    https://github.com/mono/CocosSharp/blob/master/tests/tests/Assets/Content/fonts/helvetica-geneva-32.xnb

    Marked them both as Content <- Very important

    Added the bitmap font label to the IntroLayer.cs as follows:

    using System;
    using System.Collections.Generic;
    using CocosSharp;
    using Microsoft.Xna.Framework;
    
    namespace CocosSharpGame8
    {
        public class IntroLayer : CCLayerColor
        {
            CCLabelTtf label;
            CCLabelBMFont bmLabel;
    
            public IntroLayer()
            {
    
                // create and initialize a Label
                label = new CCLabelTtf("Hello CocosSharp", "MarkerFelt", 22);
                label.AnchorPoint = CCPoint.AnchorMiddle;
    
                // add the label as a child to this Layer
                AddChild(label);
    
                bmLabel = new CCLabelBMFont("Hello CocosSharp", "fonts/helvetica-32.fnt");
                bmLabel.AnchorPoint = CCPoint.AnchorMiddle;
    
                // add the bitmap font label
                AddChild(bmLabel);
    
                // setup our color for the background
                Color = new CCColor3B(CCColor4B.Blue);
                Opacity = 255;
    
            }
    
            protected override void AddedToScene()
            {
                base.AddedToScene();
    
                // Use the bounds to layout the positioning of our drawable assets
                var bounds = VisibleBoundsWorldspace;
    
                // position the label on the center of the screen
                label.Position = bounds.Center;
    
                // position the bitmap label on the center of the screen above the ttf label
                bmLabel.Position = bounds.Center;
                bmLabel.PositionY -= 50;
    
                // Register for touch events
                var touchListener = new CCEventListenerTouchAllAtOnce();
                touchListener.OnTouchesEnded = OnTouchesEnded;
                AddEventListener(touchListener, this);
            }
    
            void OnTouchesEnded(List<CCTouch> touches, CCEvent touchEvent)
            {
                if (touches.Count > 0)
                {
                    // Perform touch handling here
                }
            }
        }
    }
    

    Here is a screen shot:

    image

    You may have to provide a very simple sample project for us to look at.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    @AdrianNelson.0022‌

    Did the same process for an Android Project from Xamarin Studio by creating a new Android project from the Templates.

    Same assets from above in the Assets/Content/fonts folder:

    https://github.com/mono/CocosSharp/blob/master/tests/tests/Assets/Content/fonts/helvetica-32.fnt.xnb https://github.com/mono/CocosSharp/blob/master/tests/tests/Assets/Content/fonts/helvetica-geneva-32.xnb

    Marked them both as Android Assets in the Build Action

    Added the bmLabel in the same fashion as described in the Windows Phone 8 project.

    bmLabel = new CCLabelBMFont("Hello CocosSharp", "fonts/helvetica-32.fnt");

    And the resulting screen shot is here.

    image

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    @AdrianNelson.0022‌

    Did the same process for an iOS from Xamarin Studio by creating a new iOS project from the Templates.

    Different assets this time than from WP and Android in the Content/fonts folder:

    The reason for the difference is that the helvetica-geneva-32.xnb of the graphic is compiled for iOS specifically. This is the only platform that is different.

    https://github.com/mono/CocosSharp/blob/master/tests/iOSContent/Content/fonts/helvetica-32.fnt.xnb
    https://github.com/mono/CocosSharp/blob/master/tests/iOSContent/Content/fonts/helvetica-geneva-32.xnb

    Marked them both as Content in the Build Action <- Very important

    Added the bmLabel in the same fashion as described in the Windows Phone 8 project.

    bmLabel = new CCLabelBMFont("Hello CocosSharp", "fonts/helvetica-32.fnt");

    Notice that nothing changed in the format for creating the Label on any of the platforms. This also means that you can mix and match native format and .xnb in the projects.

    And the resulting screen shot is here:

    image

  • Hi Kenneth, thanks a lot for your help and information, the problem was indeed because I had missed the important step of marking the .xnb font files as Content - doh!

    The fonts now load in for WinPhone (which was the first content I was loading) although my graphics are now causing a problem and I think this is down to me again...

    I had naively thought that I could take my content from iOS and Android (i.e. .png and .jpg images) and just include them (they do have a Content build action) but I think I've missed something (not being a WinPhone developer) in that do all content assets have to be converted into .xnb format as I note that this is how the graphics in the CocosSharp tests have been included?

    (I'd thought that MonoGame does know about .png and .jpg and will fall back to these formats if .xnb is not available?)

    Any pointers as to ho two convert the various content files into .xnb? Thanks in advance

    I will continue to use non-.xnb content for iOS and Android and just use .xnb content for WinPhone as and when needed.

    Many thanks,
    Adrian

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Adrian

    Yes, as I mentioned before Windows Phone may not recognize native formats. They will have to be converted to .xnb.

    There are two options (with a third experimental one that we have not announced yet)

    • Using XNA's content pipeline which you can find an example of setting that up in the forum here.
    • Using MonoGames pipeline How to use and Setup here.
    • Third (experimental) way that we have now where we can deliver the Pipeline tool by NuGet but have not documented any of this and was waiting for the next release which you can download here

    Install this NuGet into your project. You can then find the pipeline tool in (Project Directory)\packages\CocosSharp.ContentBuild.Windows.1.3.0.0\tools\Pipeline\Pipeline.exe

    Double click on Pipeline.exe and follow the directions here.

    So if you are willing to play guinea pig for us you can help test it out for us :-)

  • I'm quite happy to be a guinea pig. I'll try and use the Pipeline tool over the weekend and I'll report back.

    Many thanks for all your help, you certainly set a high standard of support for others to follow!

  • I've downloaded and installed the nugget package and when I run pipeline.exe I get an exception as below. BTW I'm using Windows 8.1 Pro 64 bit if that makes a difference.

    Log Name:      Application
    Source:        .NET Runtime
    Date:          16/01/2015 18:14:24
    Event ID:      1026
    Task Category: None
    Level:         Error
    Keywords:      Classic
    User:          N/A
    Computer:      ADRIAN1768
    Description:
    Application: Pipeline.exe
    Framework Version: v4.0.30319
    Description: The process was terminated due to an unhandled exception.
    Exception Info: System.ArgumentException
    Stack:
       at System.Drawing.Icon.ExtractAssociatedIcon(System.String, Int32)
       at MonoGame.Tools.Pipeline.MainView..ctor()
       at MonoGame.Tools.Pipeline.Program.Main(System.String[])
    
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name=".NET Runtime" />
        <EventID Qualifiers="0">1026</EventID>
        <Level>2</Level>
        <Task>0</Task>
        <Keywords>0x80000000000000</Keywords>
        <TimeCreated SystemTime="2015-01-16T18:14:24.000000000Z" />
        <EventRecordID>7656</EventRecordID>
        <Channel>Application</Channel>
        <Computer>ADRIAN1768</Computer>
        <Security />
      </System>
      <EventData>
        <Data>Application: Pipeline.exe
    Framework Version: v4.0.30319
    Description: The process was terminated due to an unhandled exception.
    Exception Info: System.ArgumentException
    Stack:
       at System.Drawing.Icon.ExtractAssociatedIcon(System.String, Int32)
       at MonoGame.Tools.Pipeline.MainView..ctor()
       at MonoGame.Tools.Pipeline.Program.Main(System.String[])
    </Data>
      </EventData>
    </Event>
    

    ...and a second slightly different event viewer entry:

    Log Name:      Application
    Source:        Application Error
    Date:          16/01/2015 18:14:24
    Event ID:      1000
    Task Category: (100)
    Level:         Error
    Keywords:      Classic
    User:          N/A
    Computer:      ADRIAN1768
    Description:
    Faulting application name: Pipeline.exe, version: 1.0.0.0, time stamp: 0x54b8a903
    Faulting module name: KERNELBASE.dll, version: 6.3.9600.17278, time stamp: 0x53eebf2e
    Exception code: 0xe0434352
    Fault offset: 0x000000000000606c
    Faulting process ID: 0xb48
    Faulting application start time: 0x01d031b842055b41
    Faulting application path: \\psf\Home\Documents\F-Drive\AppsMobilis\Blueprint Game\Blueprint\Blueprint.WinPhone\packages\CocosSharp.ContentBuild.Windows.1.3.0.0\tools\Pipeline\Pipeline.exe
    Faulting module path: C:\Windows\system32\KERNELBASE.dll
    Report ID: 7fed7ea5-9dab-11e4-826c-001c42e3aa37
    Faulting package full name: 
    Faulting package-relative application ID: 
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="Application Error" />
        <EventID Qualifiers="0">1000</EventID>
        <Level>2</Level>
        <Task>100</Task>
        <Keywords>0x80000000000000</Keywords>
        <TimeCreated SystemTime="2015-01-16T18:14:24.000000000Z" />
        <EventRecordID>7657</EventRecordID>
        <Channel>Application</Channel>
        <Computer>ADRIAN1768</Computer>
        <Security />
      </System>
      <EventData>
        <Data>Pipeline.exe</Data>
        <Data>1.0.0.0</Data>
        <Data>54b8a903</Data>
        <Data>KERNELBASE.dll</Data>
        <Data>6.3.9600.17278</Data>
        <Data>53eebf2e</Data>
        <Data>e0434352</Data>
        <Data>000000000000606c</Data>
        <Data>b48</Data>
        <Data>01d031b842055b41</Data>
        <Data>\\psf\Home\Documents\F-Drive\AppsMobilis\Blueprint Game\Blueprint\Blueprint.WinPhone\packages\CocosSharp.ContentBuild.Windows.1.3.0.0\tools\Pipeline\Pipeline.exe</Data>
        <Data>C:\Windows\system32\KERNELBASE.dll</Data>
        <Data>7fed7ea5-9dab-11e4-826c-001c42e3aa37</Data>
        <Data>
        </Data>
        <Data>
        </Data>
      </EventData>
    </Event>
    

    Thanks,
    Adrian

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Adrian are you running this from a network drive? Faulting application path: \psf\Home\Documents\F-Drive\A

    Try running from a non network drive. You can just copy the Pipeline directory over to a Windows machine and see if that works.

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai
    edited January 2015

    Also Adrian

    If you want to build on the Mac see here: https://forums.xamarin.com/discussion/30626/build-content-for-cocossharp-on-mac-is-now-possible#latest

    It is the same tool but for Mac

  • I'm actually running from a Parallels virtual machine on my Mac. You may have something about the network drive though.

    I'll try copying it outside of my Documents directory (which is shared with my Mac as it's a parallels shared folder - hence psf) to the C drive... yes that was it, it run's just fine from the root of my C drive. I'll use it properly later tonight.

    Thanks again for your suggestion!

    PS I may try building the Mac version anyway as it would be nice to create .xnb files on the Mac.

  • Hi Kenneth,

    I managed to run Pipeline.exe and converted all my content to .xnb files and the game now runs!!!

    Many thanks for helping me get to this point. My game code is 100% cross-platform using CocosSharp which is a BIG time saving an using Xamarin for Android and iOS is just fantastic.

    The bad news is that even with compression on in the pipeline tool the .jpg files are now extremely big as .xnb files. I am using a 1024x1024 .jpg which is about 82Kb but as a .xnb file it has ballooned to 1.7Mb.

    The .png files that I have suffer as well, but not by as much.

    This will be a problem for me as each level in my game uses two of these jpg images and I am planning on having around 200 levels in the final game. At that rate just the level graphics will require around 680Mb let alone the other incidental graphics and sounds. Hmmm, perhaps I could get away with using 512x512 images which would reduce the size to ¼ for these images but that would still mean that they take up around 170Mb - still quite a lot for a game.

    Anyway, not your problem.

    I'll have to rethink some of this - it's a shame that MonoGame cannot use the original PNG and JPG files on WinPhone as they work quite happily on Android and iOS.

    I did wonder if it were possible to convert the PNG and JPG files on the fly in my game into .xnb format using MemoryStreams and passing the MemoryStream through to CocosSharp but this does not seem to be supported.

    Best regards,
    Adrian

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Great to hear Adrian!! Not sure what to do about the sizes.

    We are working on getting the processes in place to convert Bitmap Font and Tilemaps to .xnb via CocosSharp's Custom processors. Which you have by the way in the NuGet that you installed in the CocosSharp directory of the Pipeline directory. The custom processors work as well. You just need to add the links to the Pipline Tool.

  • Thanks again Kenneth.

    It'll be interesting to see how my game comes along as I'm also aiming at desktop systems as well (I already have the content sized for them as I am supporting HD/Retina graphics and my base image size is 2048x2048 for these) and I am using my own custom sizes that automatically pick the highest resolution sizes according to the display size in use so I have sets of base image sizes in the various powers of two all the way from 256x256 to 2048x2048.

    Best regards,
    Adrian

  • I've just come across a problem with Pipeline.exe (or, more likely a problem of my own making) but I've just created some bitmap fonts using the excellent BMFont and the resultant .fnt and .png files work well on iOS and Android.

    While the .png files get converted into .xnb just fine by Pipeline.exe the .fnt ones are not, and when I look at the options there is no obvious importer for .fnt files (which are just text files after all).

    Can you give me any advice?

    Thanks, Adrian

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Hey Adrian

    The CocosSharp custom importers are in the CocosSharp directory under Pipeline - CocosSharp\CocosSharp.Content.Pipeline.Importers.dll.

    To register this .dll with the Pipeline tool click on the main project file within the Pipeline tool itself you will see a property for References. Click on that and you will be presented with an empty entry box. Place the full path to the .dll mentioned above. example C:\ (Full directory path of project) \packages\CocosSharp.ContentBuild.Windows.1.3.0.0\tools\Pipeline\CocosSharp\CocosSharp.Content.Pipeline.Importers.dll

    You have copied the Pipeline tool out to your directory so replace the above with the full path to the .dll.

    Click the OK button. You should now see the Importer and Processor changed to CocosSharp - Importer and Processor respectively when clicking on your Bitmap Font in the Pipeline tool. If not then you may need to restart the Pipeline tool to get the customer importer/processor to register.

    One thing with the importers and exporters is that the .fnt extension will be replaced with .xnb. You can rename them or keep them as they are but you will have to make allowances for that in your code or change the code of Android and iOS to be the same as Windows Phone without the .fnt and just use the xnb files. That also means that the .fnt file and supporting Bitmap Font graphics file will have to be named differently.

    Now after explaining all of that you can also just reference the XXXXX.fnt file in your code and as long as the supporting font graphics is converted to .xnb you should be able to load the Bitmap Font without changing the code.

    Depending on how you set that up you should be able to work correctly. We have some upcoming changes to this to take into account of some differences between the Pipeline tool and XNA content project.

    Let's see how this goes first and if not then I have an updated NuGet package that I can have you try out.

    Thanks for the testing.

  • Many thanks, the pipeline.exe now creates a .xnb file for my .fnt asset. (I did just try with a .fnt file as you suggest with a .xnb converted png but that didn't work).

    But... (there's always a but somewhere!)... I do get another exception being thrown (and I have ensured that both the font .xnb file and referenced png .xnb converted file are in the project with Content build action and Copy Always set on them.

    System.NullReferenceException was unhandled by user code
      HResult=-2147467261
      Message=Object reference not set to an instance of an object.
      Source=CocosSharp
      StackTrace:
           at CocosSharp.CCBMFontConfiguration.ParseConfigFile(String pBuffer, String fntFile)
           at CocosSharp.CCBMFontConfiguration..ctor(String data, String fntFile)
           at CocosSharp.CCBMFontConfiguration..ctor(String fntFile)
           at CocosSharp.CCBMFontConfiguration.FontConfigurationWithFile(String fntFile)
           at CocosSharp.CCLabelBMFont.FNTConfigLoadFile(String file)
           at CocosSharp.CCLabelBMFont.set_FntFile(String value)
           at Blueprint.Shared.GameAppDelegate.CreateDefaultLabel(FontSize labelSize)
           at Blueprint.Shared.MainMenu..ctor(CCWindow gameWindow, GameAppDelegate gameApp)
           at Blueprint.Shared.GameAppDelegate.ApplicationDidFinishLaunching(CCApplication application, CCWindow mainWindow)
           at CocosSharp.CCApplication.LoadContent()
           at Microsoft.Xna.Framework.DrawableGameComponent.Initialize()
           at CocosSharp.CCApplication.Initialize()
           at Microsoft.Xna.Framework.Game.InitializeExistingComponents()
           at Microsoft.Xna.Framework.Game.Initialize()
           at CocosSharp.CCGame.Initialize()
           at Microsoft.Xna.Framework.Game.DoInitialize()
           at Microsoft.Xna.Framework.Game.Run(GameRunBehavior runBehavior)
           at MonoGame.Framework.WindowsPhone.SurfaceUpdateHandler.Draw(Device device, DeviceContext context, RenderTargetView renderTargetView)
           at MonoGame.Framework.WindowsPhone.DrawingSurfaceUpdateHandler.DrawingSurfaceContentProvider.GetTexture(Size2F surfaceSize, DrawingSurfaceSynchronizedTexture& synchronizedTexture, RectangleF& textureSubRectangle)
           at SharpDX.Direct3D11.DrawingSurfaceContentProviderShadow.DrawingSurfaceContentProviderVtbl.GetTexture(IntPtr thisPtr, IntPtr surfaceSize, IntPtr synchronizedTexture, IntPtr textureSubRectangle)
      InnerException: 
    

    I have attached the original .fnt and .png as well as the .xnb versions. I'm hoping there's something obvious.

    Thanks as always, Adrian

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Adrian

    Will be looking at them. Trying to get next release ready.

  • OK, not a problem for now. I'm continuing with my game and run it on iOS and Android all the time so it's not slowing me down at the moment as Ive only just started writing my game. I was just trying to get it working immediately on all platforms, and learning what I have to do that is different to support additional platforms (and then supporting these differences in a cross-platform).

    The game code is 100% cross-platform and scales from small phones to desktop size screens (note this is not just using normal and hd graphics as I have the same four base sets of graphical assets baked into each platform and it chooses the most appropriate set based on the display size at run-time).

    I look forward to finding out what I am doing wrong so I can correct it and move on with WinPhone.

    Adrian

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Adrian

    We made some internal changes to the main code repo to support the pipeline tool over the weekend. The importers that you have work correctly but since it was "testing" you do not have the updates to the code in the current release you are using. When we have the next release out this should work with no problem.

  • Hi Kenneth, Thanks for the update - I take it this will be CocosSharp v1.4? What is the expected ETA for this next update?

    Thanks, Adrian

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    We are aiming for today or tomorrow.

  • That's fantastic, I'll give it a try pretty much immediately!

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai
    edited January 2015

    Adrian

    Can you try this again with the newest release. Please make note that the custom importers are now placed outside of the Pipeline directory and should be in

    The CocosSharp custom importers are in the CocosSharp directory under tools\CocosSharp.Importers\CocosSharp.Content.Pipeline.Importers.dll.

    New NuGet for this is here

  • Success! Using the updated CocosSharp v1.3.1 and the update Pipeline tool and referenced importer I've got my game running on Windows Phone as well as on Android and iOS - cool!

    Many thanks for your help with this, Adrian

  • zahikramerzahikramer ILMember ✭✭✭

    hi @kjpou1 -Kenneth .
    I have strange behavior.
    Why do we need the Pipeline tool of Cocossharp that comes with every build instead of the one of monogame here:
    as here monogame.net/downloads/
    as explained here: developer.xamarin.com/guides/cross-platform/game_development/cocossharp/content_pipeline/walkthrough/

    is there a difference?
    i see that in monogame pipeline tool there is also effect (which is absent on cocossharp pipeline tool).
    and do i need to add the importers you mentioned above?
    (on monogame pipeline tool it's not there and i still can make spritefont .xnb)

    i have strange issue with spritefont on ios.
    i'm making spritefont .xnb file from arial font with the new class CCLable and it only work as systemfont and not as spritefont . seems like cocossharp can't load spritefont of arial on ios. (???)

    is it depends on specific cocossharp build?
    If i take an .xnb for ios from older version on the tests of cocossharp, will it work on the new 1.5 build?

    thanks

  • zahikramerzahikramer ILMember ✭✭✭
    edited June 2015

    here
    i uploaded the GoneBananas ios project.
    changed the GameStartLayer.cs file
    on AddedToScene method :
    remove the native font to:
    //var label = new CCLabel ("Tap to Go Bananas!", "HelveticaNeue-Bold", 32 * (sx > sy ? sx : sy))
    var label = new CCLabel ("Tap to Go Bananas!", "fonts/arial", 32,CCLabelFormat.SpriteFont )

    not working.

    can you make it work?
    thanks @kjpou1

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    @zahikramer

    I just loaded this project up on my windows machine using Visual Studio and connection to the Mac. I did update to v1.5.0.0 package. https://www.nuget.org/packages/CocosSharp.PCL.Shared/ see release notes about the new version and only one NuGet package now.

    It ran first time. Not sure if it is because of the v1.5 or not but here it is running in the simulator. I changed the text in your project to "Tap to Go Bananas with sprite font", other than that no other modifications.

    image

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    Also, about your question with the pipeline. You should use what is in the walkthrough as it is more up to date. You only need the CocosSharp pipeline if you need an xnb for tilemap or bitmap font. It was basically delivered that way because at that time the pipeline tool was not available from MonoGame and needed to be built from source to be used. That is no longer the case with the recent releases of MonoGame.

  • zahikramerzahikramer ILMember ✭✭✭

    Thanks very much @kjpou1 .
    you are right. on build 1.5 it's working.
    but if you downgrade to 1.4 this is what you'll get:
    image

    good to know...(another reason to move to 1.5...)
    but....

  • zahikramerzahikramer ILMember ✭✭✭

    But now i think i finally find my problem (working on this over a week...)
    i'm attaching second test project.
    Even with build 1.5 , there is still a problem with multi language, localization.
    in the project i changed the string "Tap to go Bananas.." to some Hebrew words,
    and as you can see CCLable won't display them ... with SpriteFont.
    but with SystemFont it will!
    so i guess on systemFont it is all Unicode.
    but apparently , the spritefont is only in English (?)
    is that right?
    if so, how can i generate .xnb file with full unicode encoding to generate
    all languages. i want to localize my app and insert some font , single font
    which will behave as system font to display correctly on every local language.
    how to do it?

    p.s.
    thank you for your clarification regarding pipeline tool...
    (so now i don't need the importers that coming with the source code of cocossharp, right?)

  • zahikramerzahikramer ILMember ✭✭✭

    p.s.
    you can see in the project i have added few comments lines with systemfont and spritefont.
    play with them and see....

  • kjpou1kjpou1 LUMember, Xamarin Team Xamurai

    @zahikramer

    Here is a link to the sprite front definition.

    <CharacterRegions> and <CharacterRegion> should be what you are looking for. The .xnb sprite font file will then need to be generated.

    SpriteFonts are generated with a predefined set of characters and an image map is created that is used as an asset in your game. They really are just a Microsoft version of a Bitmap Font file. So if the sprite font was generated with the defaults, which are usually just the ASCII character range, then the Unicode Characters will not be included. See the example below for the sprite font default definition.

       <CharacterRegions>
          <CharacterRegion>
            <Start>32</Start>
            <End>127</End>
          </CharacterRegion>
        </CharacterRegions>
    

    The CCLabel that uses a SystemFont is generated on the fly so there is no predefined static image like there is with SpriteFont and BitmapFont files.

  • zahikramerzahikramer ILMember ✭✭✭

    Great @kjpou1 !
    Thank you very much kenneth!

  • zahikramerzahikramer ILMember ✭✭✭

    hi @kjpou1
    i suggest you mention this
    community.monogame.net/t/updated-localizationpipeline-not-working-with-the-monogame-pipeline-tool/975/2

    and this
    theinstructionlimit.com/common-kanji-character-ranges-for-xna-spritefont-rendering

    in you walkthrough of cocossharp / monogame
    (or integrate it yourself into the pipeline tool)
    to localize the game , especially for CJK characters.

    Regards.

Sign In or Register to comment.