Hacer nuevo GameObject en XNA 4 (Crear nueva instancia)
Frecuentes
Visto 1,442 veces
0
I have a Class for create GameObjects and it get's sprite and .... to make a game object. And I draw my Texture like this :
spriteBatch.Begin();
foreach (GameObject gameObject in Game.gameObjects)
{
if (gameObject.visible)
{
spriteBatch.Draw(gameObject.sprite.texture, gameObject.rect, gameObject.sprite.sourceRect, gameObject.color, MathHelper.ToRadians(gameObject.rotation), gameObject.sprite.origin, gameObject.spriteEffect, gameObject.layer);
}
}
foreach (Text text in Game.texts)
{
spriteBatch.DrawString(text.font, text.text, text.position, text.color, MathHelper.ToRadians(text.rotation), text.origin, text.scale, text.spriteEffects, text.layer);
}
spriteBatch.End();
I try some way to do this and crate new Object between game. for example I want to crate new bullet when i press space. But I cant make new GameObject between Game; Please help me.
Gracias.
Update : I trying to add another game object while the game is running; and the Game.gameObjects is a static list in Game1(I change Game1 name to Game) and it's on GameObject class :
public GameObject(Sprite sprite)
{
this.sprite = sprite;
rectWidth = (int)sprite.texture.Width;
rectHeight = (int)sprite.texture.Height;
rect = new Rectangle((int)position.X, (int)position.Y, rectWidth, rectHeight);
Game.gameObjects.Add(this);
}
so I can get my GameObjects in game to render they or mange they; then i have gameObjects is a list and it have All gameObjects in game
1 Respuestas
0
Your trying to add another game object while the game is running? Sorry your question is unclear.
I dont know if your Game.gameObjects is an array or list (Could you post the class, and where you initialize it?)
Game.gameObjects.Add(new GameObject(Sprite, position, whatever));
That possibly?
Respondido 25 ago 12, 13:08
oh i'm sorry. i think its happened because my language is not english and I can't speak English well. I Updated My first post. - Mohammadali Najjar khodabakhsh
no lo hagas Game.gameObjects.Add(this);
inside the contructor, use it to add the gameobject, for example If (SpacePressed) { Game.gameObjects.Add(new GameObject())
You dont do it when you make the object - Ciral
thanks alot. i think my code isn't currect know. I know It when see your comment. - Mohammadali Najjar khodabakhsh
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas c# xna xna-4.0 or haz tu propia pregunta.
Your question is very unclear, and the code you've given doesn't seem pertinent to the problem. You should reformulate the question to make it easier to understand, otherwise we won't be able to answer you. - annonymously