2017-05-02 2 views
0

저는 cocossharp를 처음 사용했습니다. Visual Studio 용 cocossharp 템플릿을 설치했습니다. 새로운 cocossharp android 게임을 선택하고 애플리케이션을 실행하면 상단에 로고가있는 검은 색 화면이 나타납니다. 코드에서, 나는 내가 내가 이벤트 ViewCreated가 발사 될 때 호출 방법 이잖아에서 브레이크 포인트를 넣어Cocossharp 템플릿이 작동하지 않습니다.

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

작성된 레이블 블루 스크린을 얻을 수 있겠 생각, 중단 점을 명중되지 않습니다. I 이벤트 다음 I가 LoadGame 방법 직접

CCGameView gameView = (CCGameView)FindViewById(Resource.Id.GameView); 
gameView.ViewCreated += LoadGame; 
LoadGame(gameView, EventArgs.Empty); 

호출 시도

CCGameView gameView = new CCGameView(this); 
gameView.ViewCreated += LoadGame; 
gameView = (CCGameView)FindViewById(Resource.Id.GameView); 

등록 전에 소성 하였다 생각 때문에 먼저 다음 CCGameView를 생성하는 이벤트 핸들러를 등록하려고하지만이위한 널 결과 예외 gameView.ContentManager.

내 생각에 다른 의심은 에뮬레이터 자체 일 뿐이지 만, 보통의 xamarin android 프로젝트에서는 완벽하게 작동합니다. 또한 Iv는 Xamarin에 대한 다양한 예제를 살펴 보았습니다.하지만 그들은 모두 Application Delegate를 사용합니다. 오타가 아니라면, 이전 작업 방식이었습니다. 누구든지 도울 수 있다면, 이드는 그것을 고맙게 생각합니다. 감사합니다

답변

0

그것은 에뮬레이터 문제 였고 에뮬레이터에서 Use Host GPU 옵션을 확인해야했습니다. 내가 만든 에뮬레이터를 선택할 수있는 Android 가상 장치 관리자에서 내가 만든 에뮬레이터를 선택한 다음 시작하는 대신 처음 편집 했으므로 이제는 에뮬레이터를 이미 만들었으므로이 옵션을 찾은 것입니다. The answer is here

관련 문제