Does anyone know, game scrolling
I am having a million problems all at once with this thing. You know games like the older Final Fantasy, the Phantasy Star series, the Lunar series, and games that look about the same, right? You know how smooth they scroll and seem to have a big-ass landscape which can impossibly be made from several and several of smaller tiles?
Do you also know games like Icari Warriors, Gauntlet and such? They too, have smooth scrolling, and in four more directions.
I am, in short, looking to make a game that scrolls that way, but I cannot figure out how to do it. I don''t want the character to move a set number of pixels each time I press the movement key. I also want the landscape to scroll...
Damn, I am even having a hard time explaining here.. I hope you get what I mean.
Let''s say you have a tile size of 64x64 pixels.
What you do is take your world, and it will have an offset value for whole X and Y and then a smaller offset value for the "smooth" scroll.
What I tend to do is render the entire tilemap to a buffer, but make it one tile bigger than the screen (so it has a border of extra tiles). Now, if I move right I''ll increment the "smooth" offset until it hits 64, drawing in the tiles from the buffer. When I get to 64 I then shunt all the tiles in the buffer leftwards by 64 pixels, destroy the extra tiles that leave the buffer to the left and draw in one extra column to the right. I then set the smooth scroll value to 0 and increment the X by one.
Does that make sense? I tend to use this for TI games where speed is of the essence (damn 6MHz z80 processor!)
What you do is take your world, and it will have an offset value for whole X and Y and then a smaller offset value for the "smooth" scroll.
What I tend to do is render the entire tilemap to a buffer, but make it one tile bigger than the screen (so it has a border of extra tiles). Now, if I move right I''ll increment the "smooth" offset until it hits 64, drawing in the tiles from the buffer. When I get to 64 I then shunt all the tiles in the buffer leftwards by 64 pixels, destroy the extra tiles that leave the buffer to the left and draw in one extra column to the right. I then set the smooth scroll value to 0 and increment the X by one.
Does that make sense? I tend to use this for TI games where speed is of the essence (damn 6MHz z80 processor!)
Sure, makes perfect sense in theory. I am not a theoretic guy though
Any sample code you would be willing to share?
Any sample code you would be willing to share?
You should check out the articles section of this site, last I knew there was a very good article on smooth scrolling, that gave plenty of sample code as well.
Drakonite
Shoot Pixels Not People
Drakonite
Shoot Pixels Not People
You might wanna take a look at the Jump'n'Run Dev tutorials here. The third tutorial covers big maps and scrolling. It does use it for a platform game but I guarantee the technique is the same.
Edit = typo
[edited by - ghosted on June 9, 2004 6:53:10 AM]
Edit = typo
[edited by - ghosted on June 9, 2004 6:53:10 AM]
The concept is the same no matter which graphics API is used (although if your looking at something 3D it will be more complex). What language/graphics API are you using if you want examples in it?
I usually (this isn''t the fastest way to do this) , have all my tiles in an array. the tiles all contain their x and y pixel coordinates, and a method/function that can change the x an y coordinates. whenever you want to sroll the map (like scroll right when you press the right arrow), use a for loop that runs the length of the tiles array. inside the loop just use the function/method that changes the x and y coordinates to shift the x and y coorinate in the direction you want.
I like to think about it in terms of a camera, or view point. The entire level is kept in a 2D array of tiles corresponding to their locations in the world. If you wanted the player to always be centered you would just move the camera every time you moved the player. Then, when you render the scene, you would subtract the camera locations from everything that you draw, doing the appropriate clipping.
Sure, I can post some source:
quote:
; ==================================================================================================
; DRAWBACK.INC - handles drawing the tiled background, scrolling it &c.
; ==================================================================================================
; ==================================================================================================
; COPY BG. Copies the BG (aligned &c) and scrolls by "a" to graphmem.
; ==================================================================================================
Copy_Bg:
;First to check: has the background actually changed?
ld b,a
ld a,(Last_Scroll_Pos)
cp b
jr nz,New_Back_Required
;As from here, the background hasn''t changed so reload it from a buffer. <- makes the game MUCH faster
ld de,PlotsScreen
SetScrollPos:
ld hl,0000
ld bc,768
ldir
ret
;OK, so we need a new
New_Back_Required:
ld a,b
ld (Last_Scroll_Pos),a
;Copy the stars to the backbuffer:
SetStarPos:
ld hl,0000
SetScrollPos_2:
ld de,0000
ld bc,768
ldir
ld l,a
ld h,0
add hl,hl ;*2
add hl,hl ;*4
push hl
pop de ;de = original a*4
add hl,hl ;*8
add hl,de ;hl=a*12
push hl
SetMaskPos_2:
ld de,0000
add hl,de
push hl
pop ix
pop hl
ld de,(PageFileLoc)
add hl,de
SetScrollPos_3:
ld de,0000
ld bc,768
Loop_Parallax:
ld a,(ix+0)
or a
jr z,Skip_Drawing_Back_Tile
ld a,(hl)
ld (de),a
Skip_Drawing_Back_Tile:
inc hl
inc de
inc ix
dec bc
ld a,b
or c
jr nz,Loop_Parallax
ld a,(GS_Terrain)
or a
jr z,SetScrollPos_4
SetScrollPos_5:
ld hl,0000
ld bc,768
Invert_Copy_Loop:
ld a,(hl)
cpl
ld (hl),a
inc hl
dec bc
ld a,c
or b
jr nz,Invert_Copy_Loop
SetScrollPos_4:
ld hl,0000
ld de,PlotsScreen
ld bc,768
ldir
ret
; ==================================================================================================
; SHIFT 8. Shifts the entire buffer down 8 pixels
; ==================================================================================================
Shift_8:
Back_copy_1:
ld hl,0000
Back_copy_2:
ld de,0000
ld bc,768
lddr
SetMaskPos_3:
ld hl,0000
SetMaskPos_4:
ld de,0000
ld bc,768
lddr
SetStarPos_2:
ld hl,0000
SetStarPos_3:
ld de,0000
ld bc,768-12
lddr
SetStarPos_4:
ld hl,0000
SetStarPos_5:
ld de,0000
ld bc,12
ldir
ret
; ==================================================================================================
; DRAW ROW. Draws a row of background tiles.
; ==================================================================================================
Draw_Row:
;1st, clear top row of pixels
ld a,$FF
ld bc,12*8
ld hl,(PageFileLoc)
bcall(_memset)
xor a
ld (Tile_X),a
ld hl,(Level_Pointer)
DrawNextTile:
ld a,(hl)
or a
jr z,SkipTile
dec a
ld l,a
ld h,0
add hl,hl
add hl,hl
add hl,hl
ld de,Background_Tiles
add hl,de
ex de,hl
ld a,(Tile_X)
call putSprite_LargeBuffer
ld a,$FF ;Mask = $FF.
SkipTile:
ld b,a
ld a,(Tile_X)
ld l,a
ld h,0
SetMaskPos_5:
ld de,0000
add hl,de
ld de,12
ld a,b
ld b,8
putASLoop_3:
ld (hl),a
add hl,de
djnz putASLoop_3
ld hl,(Level_Pointer)
inc hl
ld (Level_Pointer),hl
ld a,(Tile_X)
inc a
cp 12
ret z
ld (Tile_X),a
jr DrawNextTile
; ==================================================================================================
; PUT SPRITE ONTO LARGE BUFFER. DON''T CALL before page file has been created.
; ==================================================================================================
putSprite_LargeBuffer:
ld h,0
ld l,a
SetBufPos:
ld bc,PageFileLoc
add hl,bc ; HL => Where to put sprite
ld b,8
putASLoop_2:
ld a,(de)
ld (hl),a
inc de
push de
ld de,12
add hl,de
pop de
djnz putASLoop_2
ret
putSprite_LargeBuffer_Y:
ld h,0
add hl,hl ; x2
add hl,hl ; x4
add hl,hl ; x8
add hl,hl ; x16
add hl,hl ; x32
ld b,h
ld c,l
add hl,hl ; x64
add hl,bc ; x96
ld c,a
ld b,0
add hl,bc
SetBufPosY:
ld bc,PageFileLoc
add hl,bc ; HL => Where to put sprite
ld b,8
putASLoop_2Y:
ld a,(ix+0)
ld (hl),a
inc ix
push ix
ld de,12
add hl,de
pop ix
djnz putASLoop_2Y
ret
Level_Pointer:
.dw 0
Tile_X:
.db 0
Scroll_Amt:
.db 0
Scroll_Delay:
.db 0
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement