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

bgget

Root / Programming Questions / [.]

KomodoCreated:
can someone expain how to use bgget for backround colision i keep on getting a out of range error?

BGGet(X,Y,F) return the cell on the coordinate X,Y. X,Y could be pixel unit if F == 1 or tile unit if F == 0. The first 12 bits represent the tile, the rest are used for transformation. You could do something like this:
// SP is the management number of the sprite
// VX and VY are the speed in pixel unit
// Return true if the sprite overlap a tile different to 0

DEF collisionWithBG(SP,VX,VY)
 VAR X,Y,W,H,C

 C=0
  
 SPCOL SP OUT X,Y,W,H
 INC X,VX
 INC X,VY
 INC W,VX
 INC H,VY

 INC C,BGGET(X,Y,1)
 INC C,BGGET(X+W,Y,1)
 INC C,BGGET(X,Y+H,1)
 INC C,BGGET(X+W,Y+H,1)

 RETURN C
END
The code above get the collider of the sprite and then check if it overlap a tile different to 0(Empty). If you want to know if the collider is overlapping certain tile then you could do something like this.
// SP is the management number of the sprite
// VX and VY are the speed in pixel unit
// T is the tile id without transformation.
// Return true if the sprite overlap a tile T.

DEF collisionWIthTileT(T,SP,VX,VY)
 VAR X,Y,W,H,C
 VAR FILTER=&B111111111111

 C=0
  
 SPCOL SP OUT X,Y,W,H
 INC X,VX
 INC X,VY
 INC W,VX
 INC H,VY

 INC C, (BGGET(X,Y,1) AND FILTER)==T 
 INC C, (BGGET(X+W,Y,1) AND FILTER)==T
 INC C, (BGGET(X,Y+H,1) AND FILTER)==T
 INC C, (BGGET(X+W,Y+H,1) AND FILTER)==T

 RETURN C
END

what do you mean by the speed in pixel units?(btw thanks for replying)

That's the pixel per frame that the sprite move. VX is the movement from left to the right. VY is the movement from top to the bottom.