Hi, I'm using the CocosSharpView and CocosSharp v1.7.1 package hosted in Xamarin Forms to display a tilemap created with Tiled (v.0.12.3). The tilemap is a hex map with tile dimensions of 35w x 20h. The map displays fine but I'm unable to perform ExtractTile or SetTileGID functions to dynamically update it's appearance. I'm testing this on my Android HTC M9. Below is the Xaml I'm using as the UI:
<cocos:CocosSharpView HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" x:Name="gameView">
cocos:CocosSharpView.DesignResolution
</cocos:CocosSharpView.DesignResolution>
</cocos:CocosSharpView>
*** And here is the code behind handling the ViewCreated event: ***
private void LoadGame(object sender, EventArgs e)
{
_gameView = sender as CCGameView;
if (gameView != null)
{
CCSizeI viewSize = _gameView.ViewSize;
CCSizeI designResolution = _gameView.DesignResolution;
if (designResolution.Width < viewSize.Width) {
CCSprite.DefaultTexelToContentSizeRatio = 2.0f;
} else {
CCSprite.DefaultTexelToContentSizeRatio = 1.0f;
}
_tilemap = new CCTileMap("tilemaps/Hex5.tmx");
_gameLayer = new CCLayer(new CCSize(1120, 640));
_gameLayer.AddChild(_tilemap);
_gameScene = new GameScene(_gameView);
_gameScene.AddLayer(_gameLayer);
_gameView.RunWithScene(_gameScene);
}
}
*** I've added a button in the Xaml, when clicked I attempt to SetTileGID / ExtractTile from the CCTileMapLayer using the following: ***
void Handle_Clicked(object sender, System.EventArgs e)
{
var tilemapLayer = _gameLayer.TileMap.LayerNamed("Ground");
if (tilemapLayer != null)
{
var coords = new CCTileMapCoordinates(10, 10);
var tileGid = tilemapLayer.TileGIDAndFlags(coords);
// Hangs!
var xx = tilemapLayer.ExtractTile(coords, false);
// Hangs!
tilemapLayer.SetTileGID(new CCTileGidAndFlags { Gid= 2, Flags = tileGid.Flags}, coords);
}
}
This is a very simple program and it's hard for me to see what I'm doing wrong could someone please point me in the right direction?
Thanks,
Peter.
Hi, I'm using the CocosSharpView and CocosSharp v1.7.1 package hosted in Xamarin Forms to display a tilemap created with Tiled (v.0.12.3). The tilemap is a hex map with tile dimensions of 35w x 20h. The map displays fine but I'm unable to perform ExtractTile or SetTileGID functions to dynamically update it's appearance. I'm testing this on my Android HTC M9. Below is the Xaml I'm using as the UI:
<cocos:CocosSharpView HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand" x:Name="gameView">
cocos:CocosSharpView.DesignResolution
</cocos:CocosSharpView.DesignResolution>
</cocos:CocosSharpView>
*** And here is the code behind handling the ViewCreated event: ***
private void LoadGame(object sender, EventArgs e)
{
_gameView = sender as CCGameView;
if (gameView != null)
{
CCSizeI viewSize = _gameView.ViewSize;
*** I've added a button in the Xaml, when clicked I attempt to SetTileGID / ExtractTile from the CCTileMapLayer using the following: ***
void Handle_Clicked(object sender, System.EventArgs e)
{
var tilemapLayer = _gameLayer.TileMap.LayerNamed("Ground");
if (tilemapLayer != null)
{
var coords = new CCTileMapCoordinates(10, 10);
var tileGid = tilemapLayer.TileGIDAndFlags(coords);
This is a very simple program and it's hard for me to see what I'm doing wrong could someone please point me in the right direction?
Thanks,
Peter.