首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cocossharp模板不工作

Cocossharp模板不工作
EN

Stack Overflow用户
提问于 2017-05-02 22:19:58
回答 1查看 213关注 0票数 0

我刚接触cocossharp。我为visual studio安装了cocossharp模板,当我选择一个新的cocossharp android游戏,并运行应用程序时,我得到的只是一个黑屏,上面有一个logo。从代码中,我相信我应该得到一个蓝屏,上面写着一个标签

代码语言:javascript
复制
 protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        // Get our game view from the layout resource,
        // and attach the view created event to it
        CCGameView gameView = (CCGameView)FindViewById(Resource.Id.GameView);
        gameView.ViewCreated += LoadGame;
    }

    void LoadGame(object sender, EventArgs e)
    {
        CCGameView gameView = sender as CCGameView;

        if (gameView != null)
        {
            var contentSearchPaths = new List<string>() { "Fonts", "Sounds" };
            CCSizeI viewSize = gameView.ViewSize;

            int width = 1024;
            int height = 768;

            // Set world dimensions
            gameView.DesignResolution = new CCSizeI(width, height);

            // Determine whether to use the high or low def versions of our images
            // Make sure the default texel to content size ratio is set correctly
            // Of course you're free to have a finer set of image resolutions e.g (ld, hd, super-hd)
            if (width < viewSize.Width)
            {
                contentSearchPaths.Add("Images/Hd");
                CCSprite.DefaultTexelToContentSizeRatio = 2.0f;
            }
            else
            {
                contentSearchPaths.Add("Images/Ld");
                CCSprite.DefaultTexelToContentSizeRatio = 1.0f;
            }

            gameView.ContentManager.SearchPaths = contentSearchPaths;

            CCScene gameScene = new CCScene(gameView);
            gameScene.AddLayer(new GameLayer());
            gameView.RunWithScene(gameScene);
        }
    }
 public class GameLayer : CCLayerColor
{

    // Define a label variable
    CCLabel label;

    public GameLayer() : base(CCColor4B.Blue)
    {

        // create and initialize a Label
        label = new CCLabel("Hello CocosSharp", "Fonts/MarkerFelt", 22, CCLabelFormat.SpriteFont);

        // add the label as a child to this Layer
        AddChild(label);

    }

    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;

        // 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
        }
    }
}

我在方法中设置了一个断点,当事件ViewCreated被触发时,这个断点永远不会命中。我先尝试创建CCGameView,然后再注册eventhandler,因为我认为在注册之前事件已经触发

代码语言:javascript
复制
CCGameView gameView = new CCGameView(this);
gameView.ViewCreated += LoadGame;
gameView = (CCGameView)FindViewById(Resource.Id.GameView);

然后,我尝试直接调用LoadGame方法

代码语言:javascript
复制
CCGameView gameView = (CCGameView)FindViewById(Resource.Id.GameView);
gameView.ViewCreated += LoadGame;
LoadGame(gameView, EventArgs.Empty);

但这会导致gameView.ContentManager出现空异常。

我唯一的怀疑是模拟器本身,也许它需要额外安装一些东西,但是对于一个普通的xamarin android项目来说,它工作得很好。Iv还尝试了查看Xamarin上的各种示例,但它们都使用Application Delegate,如果我没有记错的话,这是一种旧的做法。如果有人能帮上忙,我将不胜感激。谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-05-03 22:43:24

这是一个模拟器问题,必须检查模拟器上的使用主机GPU选项。在Android Virtual Device Manager上,我可以选择我创建的模拟器,我选择了一个我创建的模拟器,然后我没有启动它,而是首先编辑了它,这就是我找到这个选项的地方(因为我已经创建了一些模拟器)。The answer is here

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43740260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档