问题
Im new in xamarin studio and im trying to create a cocosproject following the official guide, but this document is not very clear and my project have so many errors.
https://developer.xamarin.com/guides/xamarin-forms/advanced/cocossharp/#nuget
I've created a xamarin.form with IOS, android and PCL as guide say
I've added the cocosSharp packages to IOS and Android projects
BUT
if i don't add the cocosSharp package to PCL target, the cocos Classes cant be found by the code
And if I try to add the cocosSharp packages to PCL, console show this
Could not install package 'CocosSharp 1.7.1'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
i tried to change the targetFramework but this don't help me
if someone work with cocosSharp and xamarin studio V6, please how can i solve this ?
Or how can i add the add in of cocosSharp in Galery like in previous versions of xamarin ?
This is the code in a ContentPage, Cocos Classes can't be found
public class MyPage : ContentPage
{
public MyPage()
{
Content = new StackLayout
{
Children = {
new Label { Text = "Hello ContentPage" }
}
};
}
void CreateTopHalf(Grid grid)
{
// This hosts our game view.
var gameView = new CocosSharpView()
{
// Notice it has the same properties as other XamarinForms Views
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
// This gets called after CocosSharp starts up:
ViewCreated = HandleViewCreated
};
// We'll add it to the top half (row 0)
grid.Children.Add(gameView, 0, 0);
}
void HandleViewCreated(object sender, EventArgs e)
{
var gameView = sender as CCGameView;
if (gameView != null)
{
// This sets the game "world" resolution to 100x100:
gameView.DesignResolution = new CCSizeI(100, 100);
// GameScene is the root of the CocosSharp rendering hierarchy:
gameScene = new GameScene(gameView);
// Starts CocosSharp:
gameView.RunWithScene(gameScene);
}
}
}
回答1:
just figured this out myself. It's true that there's no matching build for Profile 259. Try 151 instead:
- Right click the PCL project in your solution explorer
- Click 'Options'
- Click 'General' on the left hand side.
- Change the Current Profile to "PCL 4.6 - Profile151"
- Click 'OK'.
Now you'll need to refresh the Nuget Packages so that Xamarin Forms can redownload the right profile. Afterward you can successfully add CocosSharp.Forms.
来源:https://stackoverflow.com/questions/40195764/create-a-cocossharp-project-in-xamarin