Go Back   Zune Boards > Zune Discussions > Zune Games > Development Discussions > Development Help

Development Help For help from coding to error finding to that one thing you just can't get right

Reply
 
LinkBack Thread Tools
Old 10-23-2009, 01:14 PM   #1 (permalink)
Jr. Member
 
BlackFox's Avatar
 
Join Date: Mar 2009
Posts: 487
BlackFox is on a distinguished road
Default Scrolling Method

I'm making a racing game as you may know, and I need a way to scroll the car around the track. I want the car to stay in the center of the screen at all times. Any suggestions?
__________________




BlackFox is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old 10-23-2009, 01:20 PM   #2 (permalink)
lost in paradise with rae
Support Team
Moderator
Expert Zuner
 
Red Sky's Avatar
 
Join Date: Nov 2007
Location: Pennsylvania
Posts: 2,660
Red Sky is just really niceRed Sky is just really niceRed Sky is just really nice
Send a message via MSN to Red Sky
Default

What exactly do you mean by 'scroll the car around the track?'

Is it a first person racer, a third person racer, an over-the-head (or racecar) racer?





Red Sky is offline   Reply With Quote
Old 10-23-2009, 02:09 PM   #3 (permalink)
Jr. Member
 
BlackFox's Avatar
 
Join Date: Mar 2009
Posts: 487
BlackFox is on a distinguished road
Default

Over the head. Check out my thread at the development discussions.
__________________




BlackFox is offline   Reply With Quote
Old 10-23-2009, 03:09 PM   #4 (permalink)
lost in paradise with rae
Support Team
Moderator
Expert Zuner
 
Red Sky's Avatar
 
Join Date: Nov 2007
Location: Pennsylvania
Posts: 2,660
Red Sky is just really niceRed Sky is just really niceRed Sky is just really nice
Send a message via MSN to Red Sky
Default

If I'm understanding what you mean properly...

You could just have the sprite stay stationary, and then draw it right in the middle of the screen and do your rotations and things to that sprite. Then, you could move the background in the opposite direction you want the sprite to 'move.' For example, if you want to drive up, you move the background down to give it that appearance.

Above is the more simple method, but it's not as powerful, and can be difficult to add features to (but for just a simple racing game it works).

The method that you'll probably want to use is that of a camera. Now, I'm not sure if cameras work with the zune, but I don't see why they wouldn't, as long as you don't use any 3D stuff. You would keep the camera focused on your car (it would move as your car moves), and then it should work how you want it to. This method is better if you plan on adding other racers (AI) and objects to the track.

If you're confused about anything, let me know.





Red Sky is offline   Reply With Quote
Old 10-23-2009, 03:38 PM   #5 (permalink)
God
α+ω
Retired Staff
Professional Spammer
 
Join Date: Jan 2007
Location: Look up
Posts: 7,802
God has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud of
Send a message via AIM to God Send a message via MSN to God Send a message via Yahoo to God Send a message via Skype™ to God
Awards Showcase
Biggest Abuser of Noobs Trogdor's Peasant Favorite zB Extremity 
Total Awards: 3
Default

In this case your "camera" is just a rect, every frame update the camera's rect to be centered on the center of your car. Then you just draw anything that's inside the rect. I believe XNA is good enough so that your pixel position is just the item's position minus the camera's position. Doing it such that your car is stationary and everything else moves around it is fine if you're moving in a certain direction, but once things are turning it gets really confusing
__________________
Quote:
Originally Posted by sb
10:15 PM <Marshillboy> I almost never eat out

Nurta.net cures 29 known diseases



God is offline   Reply With Quote
Old 10-23-2009, 05:43 PM   #6 (permalink)
Jr. Member
 
BlackFox's Avatar
 
Join Date: Mar 2009
Posts: 487
BlackFox is on a distinguished road
Default

Thanks all, I will be adding AI in the future so I will be going with the camera method.
__________________




BlackFox is offline   Reply With Quote
Old 10-24-2009, 02:03 PM   #7 (permalink)
Jr. Member
 
BlackFox's Avatar
 
Join Date: Mar 2009
Posts: 487
BlackFox is on a distinguished road
Default

I seem to have a working camera method, though when everything deploys and the game is about to start, this message pops up:
An unhandled exception of type 'System.NullReferenceException' occurred in RacingGameStarter.exe

The line that is highlighted:
Camera.Update(gameTime, carPosition);
__________________




BlackFox is offline   Reply With Quote
Old 10-24-2009, 04:51 PM   #8 (permalink)
God
α+ω
Retired Staff
Professional Spammer
 
Join Date: Jan 2007
Location: Look up
Posts: 7,802
God has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud of
Send a message via AIM to God Send a message via MSN to God Send a message via Yahoo to God Send a message via Skype™ to God
Awards Showcase
Biggest Abuser of Noobs Trogdor's Peasant Favorite zB Extremity 
Total Awards: 3
Default

did you initialize Camera?
__________________
Quote:
Originally Posted by sb
10:15 PM <Marshillboy> I almost never eat out

Nurta.net cures 29 known diseases



God is offline   Reply With Quote
Old 10-24-2009, 05:32 PM   #9 (permalink)
Jr. Member
 
BlackFox's Avatar
 
Join Date: Mar 2009
Posts: 487
BlackFox is on a distinguished road
Default

Yes. If you mean this:
private
Camera2D Camera;
__________________




BlackFox is offline   Reply With Quote
Old 10-24-2009, 08:42 PM   #10 (permalink)
God
α+ω
Retired Staff
Professional Spammer
 
Join Date: Jan 2007
Location: Look up
Posts: 7,802
God has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud ofGod has much to be proud of
Send a message via AIM to God Send a message via MSN to God Send a message via Yahoo to God Send a message via Skype™ to God
Awards Showcase
Biggest Abuser of Noobs Trogdor's Peasant Favorite zB Extremity 
Total Awards: 3
Default

That declares it, but not initializes it. You need to use one of the constructors the create the camera
__________________
Quote:
Originally Posted by sb
10:15 PM <Marshillboy> I almost never eat out

Nurta.net cures 29 known diseases



God is offline   Reply With Quote
Old 10-25-2009, 11:25 AM   #11 (permalink)
Jr. Member
 
BlackFox's Avatar
 
Join Date: Mar 2009
Posts: 487
BlackFox is on a distinguished road
Default

Yea I figured that out. Thanks. Should get this part done soon.
__________________




BlackFox is offline   Reply With Quote
Old 10-25-2009, 06:25 PM   #12 (permalink)
Jr. Member
 
BlackFox's Avatar
 
Join Date: Mar 2009
Posts: 487
BlackFox is on a distinguished road
Default

I'm having a little trouble incorporating my camera system into the game. What I have now is:
//STEERING
if(GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadLeft))
{
carRotation -= (
float)( 1*3f * gameTime.ElapsedGameTime.TotalSeconds);

}
elseif (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadRight))
{
carRotation += (
float)(1 * 3f * gameTime.ElapsedGameTime.TotalSeconds);

}
//THROTTLE
if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed && !BackgroundCollisionDetection(newX, newY) == true)
{
engine_acceleration = engine_acceleration_go;
carPosition.X += (
float)(engine_speed * CarMove * Math.Cos(carRotation));
carPosition.Y += (
float)(engine_speed * CarMove * Math.Sin(carRotation));
if (engine_speed >= engine_topspeed)
{
engine_speed = engine_topspeed;
engine_acceleration = 0;
}

}
if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed && !BackgroundCollisionDetection(newX, newY) == true)
{
carPosition.X -= (
float)(CarMove * 100f * Math.Cos(carRotation));
carPosition.Y -= (
float)(CarMove * 100f * Math.Sin(carRotation));

}

And what I need to put in is:

if
(GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadRight))
carPosition.X += engine_topspeed * CarMove;

if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.DPadLeft))
_carPosition.X -= engine_topspeed * CarMove;

if (GamePad.GetState(PlayerIndex.One).DPad.Down == ButtonState.Pressed)
carPosition.Y += engine_topspeed * CarMove;

if (GamePad.GetState(PlayerIndex.One).DPad.Up == ButtonState.Pressed)
carPosition.Y -= engine_topspeed * CarMove;

Though I can't get it in without screwing up how the car moves. Any help?
__________________




BlackFox is offline   Reply With Quote
Reply

Bookmarks

Thread Tools