Sprite flickering (floating point or blending issue?)
by Jason Swearingen · in Torque X 2D · 06/22/2007 (12:40 am) · 6 replies
I remember this being a bit of a problem with tgb, but i dont remember the solution (And not sure if it's exactly portable to tx anyway)
I am trying to use staticSprite's as tiles, but when I do so, when I move away from point 0,0 I start to see flickering where the tiles are no longer flush with eachother.
This seems to get worse the further away from 0,0 i get, leading me to belive it's due to some floating point math issues.
I know that tiles dont suffer from this issue, is there some way of preventing this?
And FYI, I'm using sprites instead of tiles because I need non-square tiles (ex, an isometric wall)
I thought it might have something to do with T2DSceneContainer's binSize, but playing with this didnt solve anything.
I am trying to use staticSprite's as tiles, but when I do so, when I move away from point 0,0 I start to see flickering where the tiles are no longer flush with eachother.
This seems to get worse the further away from 0,0 i get, leading me to belive it's due to some floating point math issues.
I know that tiles dont suffer from this issue, is there some way of preventing this?
And FYI, I'm using sprites instead of tiles because I need non-square tiles (ex, an isometric wall)
I thought it might have something to do with T2DSceneContainer's binSize, but playing with this didnt solve anything.
#2
If you do send your project, trash the bin and obj directories before you zip it (GG mail rejects archived binaries).
06/25/2007 (12:42 pm)
If you have a solid repro case would you mind zipping it up and emailing it to me? If not, screenshots might help. I don't think I've seen this before.If you do send your project, trash the bin and obj directories before you zip it (GG mail rejects archived binaries).
#3
My project (multithreaded mmo wannabe) only uses TX for rendering, so to avoid the clutter (and chance that it's my code that's causing the issue) I'll put together some quick sample of the issue in TX and send it (or paste it) in the next few hours.
06/25/2007 (6:05 pm)
Thanks for the help Thomas.My project (multithreaded mmo wannabe) only uses TX for rendering, so to avoid the clutter (and chance that it's my code that's causing the issue) I'll put together some quick sample of the issue in TX and send it (or paste it) in the next few hours.
#4
1) Create a new "StarterGame"
2) Build it and run it (to make sure it works as-is)
3) add a texture, located and named as "data/images/tile1.jpg" (Note: I used a 512x512 and 128x128 texture, both with same results)
4) paste the following code at the bottom of Game.cs:BeginRun()
06/25/2007 (7:16 pm)
Here's a repro for you: 1) Create a new "StarterGame"
2) Build it and run it (to make sure it works as-is)
3) add a texture, located and named as "data/images/tile1.jpg" (Note: I used a 512x512 and 128x128 texture, both with same results)
4) paste the following code at the bottom of Game.cs:BeginRun()
float tileSize = 16f;
//setup template
GarageGames.Torque.Materials.DXEffects.DefaultEffect material = new GarageGames.Torque.Materials.DXEffects.DefaultEffect();
material.Filename = "DefaultEffect";
material.BaseTex = "data/images/tile1.jpg";
GarageGames.Torque.T2D.T2DStaticSprite template = new GarageGames.Torque.T2D.T2DStaticSprite();
template.Name = "tile1";
template.Material = material;
template.Size = new Microsoft.Xna.Framework.Vector2(tileSize, tileSize);
template.Visible = true;
template.IsTemplate = true;
//draw sprites as tiles
GarageGames.Torque.T2D.T2DStaticSprite sprite;
for (int i = 0; i < 64; i++)
{
for (int j = 0; j < 64; j++)
{
sprite = template.Clone() as GarageGames.Torque.T2D.T2DStaticSprite;
sprite.IsTemplate = false;
sprite.Position = new Microsoft.Xna.Framework.Vector2(tileSize * i, tileSize * j);
GarageGames.Torque.Core.TorqueObjectDatabase.Instance.Register(sprite);
}
}
//create a camera with physics
camera = new T2DSceneCamera();
camera.CreateWithPhysics = true;
GarageGames.Torque.Core.TorqueObjectDatabase.Instance.Register(camera);
camera.Extent = new Microsoft.Xna.Framework.Vector2(80, 60);
camera.Position = new Microsoft.Xna.Framework.Vector2(0, 0);
GarageGames.Torque.T2D.T2DSceneGraph.Instance.Camera = camera;
//setup camera movement.
GarageGames.Torque.Sim.InputMap.Global.BindAction("keyboard", "Right", MoveRight);
GarageGames.Torque.Sim.InputMap.Global.BindAction("keyboard", "Down", MoveDown);
GarageGames.Torque.Sim.InputMap.Global.BindAction("keyboard", "Left", MoveLeft);
GarageGames.Torque.Sim.InputMap.Global.BindAction("keyboard", "Up", MoveUp);5) after the BeginRun() method paste the following://new camera
GarageGames.Torque.T2D.T2DSceneCamera camera;
//helper methods
private void MoveRight(float val)
{
camera.Physics.VelocityX = val * 100;
}
private void MoveDown(float val)
{
camera.Physics.VelocityY = val * 100;
}
private void MoveLeft(float val)
{
camera.Physics.VelocityX = -val * 100;
}
private void MoveUp(float val)
{
camera.Physics.VelocityY = -val * 100;
}6) start the game, use arrow keys to scroll to the right until you get to the end of the "tiles", you will see, in the last few tiles, flickering at the edges (where the tiles meet eachother)
#5
06/25/2007 (7:39 pm)
Roger that. I'll check this out tomorrow when I get into the office. Hopefully I'll have an easy fix for you.
#6
I havent heard back about this yet. Is there an easy fix? Or if there's not, then any suggestions on how to approach the issue (I'm a TX Pro owner, so i can make code changes) would be appreciated.
Or, if there's a different route i should take for this functionality (triangle list, sprite batch, etc) I'd like to hear the suggestions.
Thanks,
-Jason
07/04/2007 (12:02 am)
Ping!I havent heard back about this yet. Is there an easy fix? Or if there's not, then any suggestions on how to approach the issue (I'm a TX Pro owner, so i can make code changes) would be appreciated.
Or, if there's a different route i should take for this functionality (triangle list, sprite batch, etc) I'd like to hear the suggestions.
Thanks,
-Jason
Torque Owner Jason Swearingen
and fyi, i'm not using huge spites or anything like that, 64 of them, each size 16,16.
i start seeing the issue somewhere around 512 units away from the origin, though havent inspected further than this.