私はcocossharpを使い慣れました。私は新しいcocossharpアンドロイドゲームを選択し、アプリケーションを実行すると、ビジュアルスタジオ用のcocossharpテンプレートをインストールしました。トップにロゴが付いた黒い画面が表示されます。コードから、私は私がイベントViewCreatedが発射されたときに呼び出されるメソッドのthatsの中にブレークポイントを置く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
}
}
}
書かれたラベルがブルースクリーンを取得することになっています信じて、ブレークポイントがヒットされることはありません。私はその後、私は
CCGameView gameView = (CCGameView)FindViewById(Resource.Id.GameView);
gameView.ViewCreated += LoadGame;
LoadGame(gameView, EventArgs.Empty);
直接LoadGameメソッドを呼び出してみましたが、これがためにはnull例外が発生した私は、イベントが
CCGameView gameView = new CCGameView(this);
gameView.ViewCreated += LoadGame;
gameView = (CCGameView)FindViewById(Resource.Id.GameView);
を登録する前に発射されたと思ったので、その後のEventHandlerを登録まずCCGameViewを作成してみましたgameView.ContentManager。
私の唯一の疑惑はエミュレータそのものですが、おそらくそれは余分にインストールされたものが必要ですが、通常のxamarinアンドロイドプロジェクトでは完全に動作します。 Ivはまた、Xamarinのさまざまなサンプルを見てみましたが、それらはすべてApplication Delegateを使用しています。私が誤解していなければ、古いことでした。誰かが助けることができるならば、私はそれを感謝します。ありがとう