Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!

trying to get camera working

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 crohnsandme   Members   -  Reputation: 123


Posted 19 February 2013 - 09:00 AM

hi all , so i have a main class




which holds my different scenes


then i have an actionscene which holds all my players , weapons,enemies etc


i have created a camera class and then i have created a new camera within my player class (i have also tried to create it within the actual actionscene) but i think its all ok apart from when it comes to the draw method when i have to include the camera within the spritebatch.begin(.............) but i am getting an error because obviously i have an spritebatch.begin in the main class which holds  the different scenes.... so i tried writing a new spritebatch.begin in the player/actionscene but getting the error obviously i cant begin a new one until the end has been called



can anyone help me with this problem. if needed to see any code i will paste it in if needed. i just wondered if this is a common problem people get?


i cant see how to create the new camera in the main heliClass because i need to pass the character values which are created within the player/action class?


#2 Jutaris   Members   -  Reputation: 483


Posted 19 February 2013 - 02:31 PM

Firstly, yes you can only have one spritebatch running at a time and that's usually fine.


I'm assuming your camera is or contains a matrix which you intend to pass into .Begin. Now, ideally, your camera object should be accessible from the highest level it's needed  - in this case, the spritebatch.Begin call that would be effected by the camera (so not for any UI components). Without seeing the code it's more complicated to guess at what you're doing but I'll try and provide a few options for you.

A. remove the begin call from the main class and have the begin called in the scene. This makes sense if the scene manages drawing all the objects for the scene. Alternatively, End the spritebatch call in the main class before the draw is called on the scene if main drawing something that won't be overwritten by the scene, or begin it afterwards if it is drawing some UI components that would be overwritten. 

B. put your camera instance in the main class and pass it around by parameter or property to the child objects that need it. This method is less clean, but it is a viable solution.


If neither of those work out feel free to include your problematic code in a post or via pastebin and we can try an help :)

My Site -- My Music  -- My Ramblings -- My Game

 Basic Flying Rules:Try to stay in the middle of the air. Do not go near the edges of it. The edges of the air can be recognized by the appearance of ground, buildings, sea, trees and interstellar space. It is much more difficult to fly there.

Come join us for some friendly game dev discussions over in XNA Chat!

#3 crohnsandme   Members   -  Reputation: 123


Posted 20 February 2013 - 09:42 AM

ahh yes that is fine , at the moment i have took a step back and decided to clean the coding up of what i have so far ie, create a spritemanager to make it easier for others to read my code and help me learn more about making a spritemanager, but soon as i am sorted with that i will be back to look at the camera problem im glad its not a major problem and seems to be easy enough to sort out :)


thanks for looking

#4 crohnsandme   Members   -  Reputation: 123


Posted 21 February 2013 - 08:01 AM

ok this is annoying me now i decided because the only enemies for now will be same enemiy texture in list its pointless making a complex sprite manager when its only a 1 player simple game, so back to the camera problem


if i remove the sprite.begin and end from the main class none of the menus are drawn, i have tried a few different ways trying to end before the next begin and having no luck , here is the MAIN class code



protected override void Draw(GameTime gameTime)
            switch (CurrentGameState)
                case GameState.Playing:
                     actionScene.Draw(spriteBatch);//spriteBatch.Draw(actionBackTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
                case GameState.MainMenu:
                    spriteBatch.Draw(backgroundTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
                case GameState.Options:
                    spriteBatch.Draw(optionsTexture, new Rectangle(0, 0, screenWidth, screenHeight), Color.White);
and then here is the main actionscene where the player,enemies,bullets everything in game is drawn etc
 public void Draw(SpriteBatch spriteBatch)
              //  BlendState.AlphaBlend,
                //null, null, null, null,
            if (firing)
                foreach (Bullet bullet in bulletList)
ye at the moment there are no enemies, nor map tiles etc so for now its just the player the crosshair and bullets drawn
can someone help me find what/where to put the camera sprite.begin please thanks

#5 crohnsandme   Members   -  Reputation: 123


Posted 21 February 2013 - 09:50 AM

hahahaha omg it was so obvious after i wrote the previous post i basically had said what i needed to do lol :) now onto creating a  tiled map so i can take advantage of the working camera :)

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.