View previous topic - View next topic |
Author |
Message |
[Neodog] Solar Wandering Minstrel
Joined: 27 May 2003 Posts: 122 Location: Solarland
|
Posted: Tue Jun 03, 2003 6:31 pm Post subject: Side Scrolling... |
[quote] |
|
I seed to make an engine for a pixelrpg, and I need it to sidescroll the background. How do I do it? Answers may be in C/C++/Perl/Python _________________ I think, therefore I am... I think.
|
|
Back to top |
|
|
DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: Tue Jun 03, 2003 6:33 pm Post subject: |
[quote] |
|
err, say what?
could you be a little more specific? _________________ If there's life after death there is no death, if there's no death we never live. | ENTP
|
|
Back to top |
|
|
[Neodog] Solar Wandering Minstrel
Joined: 27 May 2003 Posts: 122 Location: Solarland
|
Posted: Tue Jun 03, 2003 6:35 pm Post subject: |
[quote] |
|
I need the camera to stay focused on the main person, but the background to move, like Diablo, etc., _________________ I think, therefore I am... I think.
|
|
Back to top |
|
|
DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: Tue Jun 03, 2003 6:52 pm Post subject: |
[quote] |
|
ummm, ok first I thought that you were doing something like super mario, now it sounds like you wan't to make an iso game... _________________ If there's life after death there is no death, if there's no death we never live. | ENTP
|
|
Back to top |
|
|
[Neodog] Solar Wandering Minstrel
Joined: 27 May 2003 Posts: 122 Location: Solarland
|
Posted: Tue Jun 03, 2003 6:59 pm Post subject: |
[quote] |
|
Yes _________________ I think, therefore I am... I think.
|
|
Back to top |
|
|
Bjorn Demon Hunter
Joined: 29 May 2002 Posts: 1425 Location: Germany
|
Posted: Tue Jun 03, 2003 7:05 pm Post subject: |
[quote] |
|
He's only just asking how to scroll the map... while keeping the player in the middle. The way most people do it (I think) is to shift the map origin so that the players position gets to the center of the screen. Assuming pixel based coords, start drawing map at:
Code: | screen.width / 2 - player.x
screen.height / 2 - player.y |
You see as the player walks down the map, the map itself will get shifted upwards. The easiest way to implement such a thing would be using an offscreen area to draw the map to and then the player and then flipping or copying to the visible screen.
When you play Cave Adventure, you can see we've added extra checks to make sure we never show the border of the map somewhere on the screen, but keep it at the border of the screen. Like:
Code: | origin.x = screen.width / 2 - player.x
origin.y = screen.height / 2 - player.y
if (origin.x > 0) origin.x = 0
if (origin.y > 0) origin.y = 0
if (origin.x + map.width < screen.width) origin.x = map.width - screen.width
if (origin.y + map.height < screen.height) origin.x = map.height - screen.height |
Of course, you might also want to take into account the cases where the map is smaller than the screen, in which case you might want to center the map.
Edit: fixed centering formulas.
Last edited by Bjorn on Tue Jun 03, 2003 7:09 pm; edited 1 time in total
|
|
Back to top |
|
|
[Neodog] Solar Wandering Minstrel
Joined: 27 May 2003 Posts: 122 Location: Solarland
|
Posted: Tue Jun 03, 2003 7:07 pm Post subject: |
[quote] |
|
Thnx, Bjorn, That'll come in handy to kick major *** at the RPG Compo! :) _________________ I think, therefore I am... I think.
|
|
Back to top |
|
|
DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: Tue Jun 03, 2003 7:09 pm Post subject: |
[quote] |
|
oh my god do I feel stupid. _________________ If there's life after death there is no death, if there's no death we never live. | ENTP
|
|
Back to top |
|
|
Bjorn Demon Hunter
Joined: 29 May 2002 Posts: 1425 Location: Germany
|
Posted: Tue Jun 03, 2003 7:12 pm Post subject: |
[quote] |
|
Notice my edit...
Hey dandelion, heads up! :-)
|
|
Back to top |
|
|
DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: Tue Jun 03, 2003 7:22 pm Post subject: |
[quote] |
|
ok, really this is nitpick but don't you mean:
Code: |
origin.x = screen.width / 2 - player.x
origin.y = screen.height / 2 - player.y
if (origin.x < 0) origin.x = 0
else if (origin.x + map.width < screen.width) origin.x = map.width - screen.width
if (origin.y < 0) origin.y = 0
else if (origin.y + map.height < screen.height) origin.x = map.height - screen.height
|
i.e. that if the origin is negative it should be zero else if it happens
to pass its max it should be max else its ok? _________________ If there's life after death there is no death, if there's no death we never live. | ENTP
|
|
Back to top |
|
|
Bjorn Demon Hunter
Joined: 29 May 2002 Posts: 1425 Location: Germany
|
Posted: Tue Jun 03, 2003 7:37 pm Post subject: |
[quote] |
|
Uhm, the origin was meant to be the point where you would start to draw your map (assuming you don't do any optimization by not drawing tiles completely outside the visible area). If it's smaller than zero, that just means the map starts outside of the screen, which is no problem and it should not be set to 0.
About the change to "else if", that might safe one check if the map origin is positive, but shouldn't cause any different result assuming the map is larger than the screen.
Of course, I'm not saying there's no errors in what I just wrote down, so I'm glad somebody is looking at it closely. :-)
|
|
Back to top |
|
|
DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: Tue Jun 03, 2003 7:42 pm Post subject: |
[quote] |
|
ohh.. we just think about the origin in diffrent ways.
I thought it was the world coordinate at the top left corner, and that would mean that a negative origin was really bad..
my bad again I guess.. geez am I having a bad day.. _________________ If there's life after death there is no death, if there's no death we never live. | ENTP
|
|
Back to top |
|
|
ThousandKnives Wandering Minstrel
Joined: 17 May 2003 Posts: 147 Location: Boston
|
Posted: Tue Jun 03, 2003 10:34 pm Post subject: |
[quote] |
|
Also, if you want to do basic donut-shaped map border looping, you can set it up like this:
Code: |
while(screen.x < 0)
screen.x += map.width;
while(screen.y < 0)
screen.y += map.height;
while(screen.x >= map.width)
screen.x -= map.width;
while(screen.y >= map.height)
screen.y -= map.height;
|
You'll have to keep making checks like that as you cycle through the blocks that are on screen.
I find it easier to set the screen origin only initially (file loading, warping from map to map). origin position changes are then made during the movement handling function
Code: |
if (camera_follow)
{
screen.x += delta_x;
screen.y += delta_y;
}
|
This way the "torch can be passed" if some other object wants the camera to follow it when it moves.
|
|
Back to top |
|
|
[Neodog] Solar Wandering Minstrel
Joined: 27 May 2003 Posts: 122 Location: Solarland
|
Posted: Wed Jun 04, 2003 7:22 am Post subject: |
[quote] |
|
Please no discussion, it's already finished.... _________________ I think, therefore I am... I think.
|
|
Back to top |
|
|
DrunkenCoder Demon Hunter
Joined: 29 May 2002 Posts: 559
|
Posted: Wed Jun 04, 2003 3:43 pm Post subject: |
[quote] |
|
[Neodog] Solar wrote: | Please no discussion, it's already finished.... |
umm, so we can't discuss our ideas because you consider it done?
sorry but I really can't see the logic in that, discussion and
exchange of ideas is what makes up a community if you're
satesfied with the answer you've got then just ignore
the rest of the thread I consider other peoples input
intresting and enriching _________________ If there's life after death there is no death, if there's no death we never live. | ENTP
|
|
Back to top |
|
|