0
votes

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

1
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

1 Answers

0
votes

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?