Smooth RPG map scrolling :)

I have a functioning game map at this point, but I'm bothered by the fact that I can't get the map to scroll very well.

I have a map loaded into an array, it has a variable size, but it is square and goes from (0,0) to (Map.Size, Map.Size) (measured in 32x32 tiles)

The viewport, the screen that the player sees, goes from (0,0) to (10,10).

When I load the map I put a 5 tile buffer around the map array that the player cannot walk through, so that I don't get the dreaded IndexoutofboundsException.

After getting everything working I realized that when my player moves the tiles that are coming into view don't show up until the player finishes moving. This happens because I have the map moving a few pixels at a time during his movement, but I don't update his actual position until the movement is finished. I found a work-around by increasing the number of tiles drawn (now 0,0 to 11,11), but it only fixes the bottom and right side scroll issue, of course.

If I increase the number of tiles drawn on the left or top side (-1,-1 to 11,11) I get an exception. I tried catching the exceptions, but it slows my frame rate to a crawl (from 200 FPS down to 7).

A few ways to get around this, that I'm aware of:

Increase the size of the map buffer so that going one or two more spaces out to the left or top doesn't cause an error.
(the Dragon Warrior way)

-or-

Lose the buffer altogether and change my code so that when the player gets near a map edge it switches from him standing in the middle of the screen and the map actually doing the moving, to him moving around the side or corner of the map.
(the Final Fantasy way)

The other reason I'm interested in finally fixing this annoying issue is that I implemented irregularly shaped objects into the code. Since they fire (show) when their lower left-hand corner comes into player view, the bigger they are the faster they disappear off my screen as I move around. :(

I can post some code on here, but it's really dense stuff. I guess I'm looking for advice on what would be the better methodology rather than a code fix, for the most part.

That said, if you want to see some of it let me know and I'll turn a chunk of it into something readable and post it here ;)

-G

Comments

  • Silly me, I went ahead and dreamed up a solution to my problem last night. I just stuck one of these in front of every "draw" statement.

    [code]
    If (Trainer.CurrentX - 5 + x) > -1 And (Trainer.CurrentY - 5 + y) > -1 Then
    'draw the sprites
    End If
    [/code]

    While it's not the most elegant way of doing things, it does get the job done :)

    I'd still love to hear anyone's input on general methodology for game making.

    -Gavin
  • seancampbellseancampbell Pennsylvania, USA
    This is using a Different .Net package (XNA) and a different language (XNA only works with C#), but it is an article about making a 2D Camera object in a tilebased game and how to implement it.

    I prefer this method to keep the character in view of my level... More advanced behavior can be added/editted to allow the Camera to function as you'd like it to (for instance only moving when you reach the end of a level and the screen slides to the next level. You can also use Camera classes to only Render Tiles and perform logic on tiles that are in view...

    Have fun,
    Sean Campbell
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories