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.
Thanks.
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