Hi.
We working on application with Xamarin+Urho on Android.
And have strange problem with displaing sprites and terrarin textures.
Left side of image is screenshot geted from real device and sprite consists of pixel doted pattern over it. Right site is bitmap that copied to sprite.
What we do wrong?
Code that we use to draw on sprite.
const int cnt = 5;
Sprite[] spriteList = new Sprite[cnt];
Texture2D[] textureList = new Texture2D[cnt];
private Texture2D GetTexture(int h , int w)
{
#region TestDrawTexture
Texture2D texture=new Texture2D();
texture.FilterMode = TextureFilterMode.Nearest;
texture.SetNumLevels(1);
texture.SetSize(w, h, Graphics.RGBAFormat, TextureUsage.Static);
return texture;
#endregion
}
public bool DrawOnSprite(int num, Bitmap bitmap)
{
#region DrawOnSprite
try
{
if (num < 0 || num > cnt)
{
return false;
}
if (textureList[num] == null)
{
textureList[num] = GetTexture(bitmap.Height, bitmap.Width);
}
Texture2D texture = textureList[num];
unsafe
{
int psize = bitmap.Width * bitmap.Height * 4;
int[] pixels = new int[psize];
if (pixels == null)
{
log.WriteError("Error in DrawOnSprite, pixels == null");
return false;
}
{
bitmap.GetPixels(pixels, 0, bitmap.Width, 0, 0, bitmap.Width, bitmap.Height);
MainModule.obj.SaveBitmap(bitmap,"bitmap_"+num.ToString()+".png");
fixed (void * data = &(pixels[0]))
{
if (data == null)
{
log.WriteError("Error in DrawOnSprite, data == null");
return false;
}
bool result_SetData = texture.SetData(0, 0, 0, texture.Width, texture.Height, (void *) data);
if (result_SetData == false)
{
log.WriteError("Error in DrawOnSprite, SetData to textute return false");
return false;
}
if (spriteList[num] == null)
{
spriteList[num] = new Sprite();
}
Sprite sprite = spriteList[num];
sprite.Texture = texture;
sprite.SetSize(128, 128);
sprite.BlendMode = BlendMode.Replace;
int x = (int) (840/6);
int y = (int) (480/8) + num * sprite.Height + 20;
sprite.Position = new IntVector2(x, y);
ApplicationIUHelperClass.obj.AppUI.Root.AddChild(sprite);
}
}
return true;
}
}
catch (Exception ex)
{
log.WriteError("Error in DrawOnSprite", ex);
}
return false;
#endregion
}