Hi all,
I need help to port this project to Windows Phone 8 (Monogame): [xnaelectriceffect][1][1]: https://xnaelectriceffect.codeplex.com/releases/view/84668
Who can help me?
Razib
Hi all,
I need help to port this project to Windows Phone 8 (Monogame): [xnaelectriceffect][1][1]: https://xnaelectriceffect.codeplex.com/releases/view/84668
Who can help me?
Razib
What have you tried so far? Looking at the code it seems it should work simply by creating a new MonoGame Windows Phone 8 class library and adding all the source files.
One thing to watch out for is garbage. That library is allocating a new VertexPositionColor every time you draw it. You’d want to refactor it so you pass in and reuse you vertex array to the PrimitiveUtil functions.
Hi Aranda,
Thanks for your answer.
Actually I’ve just imported the source files to the project, instead of creating a new MonoGam class library. Anyway everythink it’s working great except for the class “PrimitiveUtil”, where I’m having trouble with rendering primitives.
This is what I’ve done (actually trying to render only line type electricity):
public static VertexPositionColor[] DrawLine(
List<ElectricNode> nodes,
int segments, Color color)
{
//EnsureInitialization();
int verticesCount = (nodes.Count - 1) * segments;
VertexPositionColor[] vertices = new VertexPositionColor[verticesCount];
for (int i = 0; i < (nodes.Count - 1); i++)
{
float amount = 0.0f;
for (int j = 0; j < segments; j++)
{
float x = nodes[i + 1].Position.X * amount + nodes[i].Position.X * (1f - amount);
float y = nodes[i + 1].Position.Y * amount + nodes[i].Position.Y * (1f - amount);
vertices[i * segments + j] = new VertexPositionColor();
vertices[i * segments + j].Position = new Vector3(x, y, 0);
vertices[i * segments + j].Color = color;
amount += 1f / segments;
}
}
//Game1._graphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, vertices, 0, verticesCount - 1);
return vertices;
}
These are my proprieties in the game class:
public static GraphicsDevice _graphicsDevice;
public static GraphicsDeviceManager _graphics;
public static SpriteBatch _spriteBatch;
And this is the resoult:
If I enable “EnsureInitialization()” and “DrawUserPrimitives” the game show me black screen.
Does MonoGame support “SharedGraphicsDeviceManager”?
Anyway thanks for tips about “VertexPositionColor[]” and sorry for my bad english.
Razib
There is no support for SharedGraphicsDeviceManager. It was only used in Windows Phone 7.5, and even then it wasn’t used a lot.
I’m not surprised… in fact I’m surprised the code works at all given it’s creating a new BasicEffect right before every Draw call (it’s also extremely bad for generating garbage). Try making the BasicEffect a member of your game class and moving this to your game’s Initialize():
basicEffect = new BasicEffect(device);
basicEffect.Projection = Matrix.CreateOrthographicOffCenter
(0, device.Viewport.Width,
device.Viewport.Height, 0,
0, 1);
Then just apply the Pass in each PrimitiveUtil draw function:
basicEffect.CurrentTechnique.Passes[0].Apply();