Cocos2DXNA / cocos2d-xna

XNA Port of Cocos2d-X
www.cocos2dxna.com
227 stars 123 forks source link

Game Activity + Game Window #411

Closed Zambiorix closed 10 years ago

Zambiorix commented 10 years ago

On Android, has the initialisation of the AndroidGameActivity changed? In alle examples I see the code below:

But I get 2 exceptions when trying to build.

  1. Game1.Activity has no setter anymore When removing that line and debugging, I noticed that the activity is set automatically.
  2. adding the game.Window to the frameLayout results in build error

Sources.Android/Activity.cs(68,11): error CS1502: The best overloaded method match for Android.Views.ViewGroup.AddView(Android.Views.View)' has some invalid arguments Sources.Android/Activity.cs(68,31): error CS1503: Argument#1' cannot convert Microsoft.Xna.Framework.GameWindow' expression to typeAndroid.Views.View'

The code below used to work on cocos2d xna clone a few months old

public class Program : AndroidGameActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        Game1.Activity = this;
        var game = new Game1();

        var frameLayout = new FrameLayout(this);
        frameLayout.AddView(game.Window);
        this.SetContentView(frameLayout);

        //SetContentView(game.Window);
        game.Run(GameRunBehavior.Asynchronous);
    }
}
Zambiorix commented 10 years ago

when building the android test solution "cocos2d-xna.Tests.Android", I get the same errors .. screen shot 2014-05-01 at 14 30 04

totallyeviljake commented 10 years ago

Yes, MonoGame has recently changed the manner in which we get the activity context. Now we do it via a more elegant API that uses the Activity assigned to the game. You will see some commits from me that addressed that in our source tree on GitHub here.

totallyeviljake commented 10 years ago

From CCLabel-Android:

if (_paint == null) { var display = Game.Activity.WindowManager.DefaultDisplay; var metrics = new DisplayMetrics(); display.GetMetrics(metrics);

totallyeviljake commented 10 years ago

Closing - non-issue for us. Just a refactoring change in MonoGame.

totallyeviljake commented 10 years ago

Make sure you update the submodule (MonoGame) so you get the latest code from there.

Zambiorix commented 10 years ago

I don't understand how this can be closed?

I made a complete new clone from the cocos2d-xna project including all submodules. Then I try to to build the cocos2d-xna test example. That fails for the android example...

See the included image above.

How must I set the content view in the android game activity ? Your examples are not adapted ..

Zambiorix commented 10 years ago

Can you please run your Android test example in cocos2d-xna? (cocos2d-xna.Tests.Android) A fresh clone with all submodules updated does not work, the test example is broken. The problem is in the OnCreate of the main activity ..

        Game1.Activity = this;
        var game = new Game1();

        var frameLayout = new FrameLayout(this);
        frameLayout.AddView(game.Window);
        this.SetContentView(frameLayout);

How must I setup the Game + activity correctly with the new changes in MonoGame? (MonoGame does have tests for iOS & Windows etc, but I cannot find any for Android ??)

Your answer above with code: I fail to see how that solves my problem ?

From CCLabel-Android:

if (_paint == null) { var display = Game.Activity.WindowManager.DefaultDisplay; var metrics = new DisplayMetrics(); display.GetMetrics(metrics);

totallyeviljake commented 10 years ago

Here is what you need:

var game = new Game1();

        var frameLayout = new FrameLayout(this);
        frameLayout.AddView((View)game.Services.GetService(typeof(View)));
        this.SetContentView(frameLayout);

        //SetContentView(game.Window);
        game.Run(GameRunBehavior.Asynchronous);
totallyeviljake commented 10 years ago

Forgot to push up my changes to the tests .... probably was waiting for my Android license to finally allow me to actually USE it.

https://github.com/Cocos2DXNA/cocos2d-xna/commit/e1b087f4a105678313f97e61a8885c51585d66ec

Templates and test code has been updated. Sorry for all of the confusion.

Zambiorix commented 10 years ago

Thank you!