LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

How do I do background scrolling in my game?

Root / Programming Questions / [.]

GuzzlerCreated:
I want to be able to do something like referencing a bunch of data to place background tiles. The idea is if I say somewhere something like this(I don't know if this should be in front of DATA or not): 1,1,1,1,1,1,1,1,1 1,0,0,0,0,0,0,0,1 1,0,0,0,0,0,0,0,1 1,0,0,0,0,0,0,0,1 1,0,0,0,0,0,0,0,1 1,0,0,0,0,0,0,0,1 1,0,0,0,0,0,0,0,1 1,0,0,0,0,0,0,0,1 1,1,1,1,1,1,2,1,1 Where 1 is a wall, 0 is nothing, and 2 is a door. Basically, I it to place these background tiles and give them properties corresponding to the numbers I have stored somewhere. Please help.

The built-in SmileBasic Background system works exactly how you describe. You've got:
BGLOAD Layer, [Start point X,Start point Y,Width,Height,] Numerical value array
Where your tiles are the actual value of the sprite def.
Variable=BGGET( Layer, X, Y)
IF Variable==theSPDEFofWalls THEN
  there is a wall at X,Y
ELSEIF Variable!=0 THEN
  GOTO action$[Variable]
ENDIF
... MORE CHECKS...
EDIT: just use an array if it's not display data.
TILE = map[nextX][nextY]
If TILE==1 THEN
  'WALL
  nextX=curX
  nextY=curY
ELSEIF TILE>1 THEN
  GOTO warps$[TILE]
ENDIF
EDIT 2: As far as scrolling goes, you just maintain a BGOFS. The grid position has nothing to do with the pixel offset. To load that map:
DIM map[9,9]
COPY map,"@SRC"
@SRC
DATA 1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,1,1

Thank you! I'll use this sometime soon.

Did anyone notice this is forum #666

Did anyone notice this is forum #666
yes.