Cannot initialize CCSprite from Button event handler

I have a ball.png file in my Android project under Assets/Content/ball.png, and I want to use it like var sprite = new CCSprite("ball.png") and then add it to a layer, etc. It works fine whenever this code is run from within anything CocosSharpy, like a CCLayer's constructor or a touch event handler. But when I add a normal Android.Widget.Button to the UI, and I try to initialize the same exact CCSprite in the Click event handler, it freezes, hangs, does nothing, doesn't even throw a decent exception.

The debugger prints this to the Output window in VS:

12-28 21:03:12.857 D/Mono (28167): Image addref System.Xml[0x5d194f30] -> System.Xml.dll[0x5d1947b0]: 2
12-28 21:03:12.867 D/Mono (28167): Prepared to set up assembly 'System.Xml' (System.Xml.dll)
12-28 21:03:12.867 D/Mono (28167): Assembly System.Xml[0x5d194f30] added to domain RootDomain, ref_count=1
12-28 21:03:12.867 D/Mono (28167): AOT: image 'System.Xml.dll.so' not found: Cannot load library: load_library[1093]: Library '/data/data/MyLittleAppAndroid.MyLittleAppAndroid/lib/libaot-System.Xml.dll.so' not found
12-28 21:03:12.867 D/Mono (28167): AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Xml.dll.so' not found: Cannot load library: load_library[1093]: Library '/data/data/MyLittleAppAndroid.MyLittleAppAndroid/lib/libaot-System.Xml.dll.so' not found
12-28 21:03:12.867 D/Mono (28167): Config attempting to parse: 'System.Xml.dll.config'.
12-28 21:03:12.867 D/Mono (28167): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Xml/System.Xml.config'.
12-28 21:03:12.867 D/Mono (28167): Assembly Ref addref CocosSharp[0x581465c0] -> System.Xml[0x5d194f30]: 2
12-28 21:03:12.887 D/Mono (28167): Assembly Ref addref System.Xml[0x5d194f30] -> mscorlib[0x56bdfdd8]: 18
Loaded assembly: System.Xml.dll [External]
12-28 21:03:12.937 D/Mono (28167): Assembly Ref addref MonoGame.Framework[0x5c988af8] -> System[0x5c81ad50]: 4
12-28 21:03:13.188 D/Mono (28167): Assembly Ref addref MonoGame.Framework[0x5c988af8] -> System.Core[0x5b241840]: 4

I don't understand. What is exactly causing this, and how to solve it? And why the heck is it working when it's run in a CocosSharpy "context"?

Answers

  • LaetitiaLaetitia Member ✭✭

    Hello,

    I have the exact same issue.

    How can we run something in the CocosSharp context? I'm using Xamarin.forms with CocosSharp, and I'm looking for a way to create a sprite on a button click... is that even possible ?

    Thanks

  • LaetitiaLaetitia Member ✭✭

    Found the fix. Just run your sprite creation inside this:

    new CCCallFunc(new Action(() =>
    {
    // your code here
    }
    })

    or with Schedule( ...)

    That will run it inside the game thread

  • LaetitiaLaetitia Member ✭✭

    Found the fix. Just run your sprite creation inside this:

    new CCCallFunc(new Action(() =>
    {
    // your code here
    }
    })

    or with Schedule( ...)

    That will run it inside the game thread

Sign In or Register to comment.