|
|||||||
| Forum Home | Register | Members List | Mark Forums Read |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||||||||
|
Junior Member
|
Hey everyone,
I'm curious about how scrolling backgrounds work. I'd assume that the texture (background) rendering rectangle is modified to emulate scrolling but how do you make the player appear to be moving to the left while the background scrolls to the right. I'm trying to implement the feature of the scrolling background in an XNA game I'm working on. When the player hits the left edge of the screen, they lose the game. Example games: The Impossible Game, Robot Unicorn Attack |
||||||||
|
|
|
|
|
#3 | ||||||||
|
Junior Member
|
Here's some pseudo code, what do you think?
Code:
int nBGOffset = 0;
RECT drawRect
Texture texBG;
Update(float _dt)
{
nBGOffset += 40* _dt;
if(nBGOffset > texBG.Width)
nBGOffset = 0;
Player.Position.X -= 40* _dt
}
Render()
{
drawRect.x = nBGOffset;
texBG.Draw(drawRect);
}
What i hope the code will
Last edited by Killerapathy : 02-14-2011 at 11:08 PM. |
||||||||
|
|
|
|
|
#4 | ||||||||
|
Moderator
Location: Netherlands |
I don't have much experience with XNA, but that code could work just fine, sure.
I also find "wrapping the background around" to usually be an annoying issue. It (probably) requires creating a second instance of your background instance, when the first instance is fully visible to the player. Place it adjacent to your other instance, and have it scroll the same amount as your first instance. When the leftmost instance scrolls outside of the viewing area, you can remove references to the object so you don't waste resources rendering an object the player can't see anyway. Oh, and by the way, this is not really "pseudo code", but rather "code". ![]()
__________________
I'm a web developer by profession, but a game developer by heart. Uh oh! The princess is in another signature! |
||||||||
|
|
|
![]() |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
All times are GMT -8. The time now is 01:11 PM.






















Linear Mode

