Pregunta

Actualmente estoy trabajando en un juego, en el que tenemos que combinar el uso de DrawUserIndexedPrimitives y normal spriteBatch.Draw . Sin combinar como los usamos al mismo tiempo, pero primero tenemos que sacar algunas sprites en 2D utilizando SpriteBatch, donde después de que SpriteBatch desactivar para permitir basicEffect y dibujar las primitivas, y por último volver a activar SpriteBatch. El código siguiente muestra la sección del código, en donde está ocurriendo el problema.

spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cam.get_transformation(GraphicsDevice));
                levelController.Draw(spriteBatch);


                if (gameReady)
                {
                    foreach (GameObject.GameObject go in gameObjects)
                    {
                        go.Draw(spriteBatch);
                    }
                    spriteBatch.End();

                    foreach (GameObject.GameObject go in gameObjects)
                    {
                        if (go is GameObject.Enemy.Enemy)
                        {
                            GameObject.Enemy.Enemy enemy = (GameObject.Enemy.Enemy)go;

                            basicEffect = new BasicEffect(graphics.GraphicsDevice);
                            basicEffect.VertexColorEnabled = true;
                            basicEffect.CurrentTechnique.Passes[0].Apply();

                            GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, enemy.GetCollisionTriangle.Triangle, 0, 3, enemy.GetCollisionTriangle.Indices, 0, 1);
                        }
                    }
                }

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, cam.get_transformation(GraphicsDevice));

Si el código de abajo se cita fuera, el retraso se detiene.

basicEffect = new BasicEffect(graphics.GraphicsDevice);
                        basicEffect.VertexColorEnabled = true;
                        basicEffect.CurrentTechnique.Passes[0].Apply();

                        GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, enemy.GetCollisionTriangle.Triangle, 0, 3, enemy.GetCollisionTriangle.Indices, 0, 1)

Puede realmente ser que no podemos tanto para uso SpriteBatch y basicEffect sin el juego desfases mucho? que ha sido probado en 3 ordenadores diferentes, desde un ordenador portátil muy antiguo, a un nuevo PC Gamer. El juego no se puede reproducir con el retraso que se produce.

¿Fue útil?

Solución

I think you should create the basiceffect elsewhere then your drawing routine. If I guess right you will use the same basiceffect all the time, so put it into inicializing, since "new" per every frame (edit: in a foreach for each and every object) can cost performance.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top