Hide Behind Tile [4.5.6]

baardbi

Well-known member
I think I have solved the problem where the sprite comes to the foreground when you press against a solid tile.

Instead of resetting the sprite priority in Bank18 I moved it to +skipThisTile in doHandleTileCollisions. So around line 212 in my doHandleTileCollisions it looks like this:

+isNotSolid
+skipThisTile
LDA tempD
BEQ +skipThisTile
CMP #$01
;BEQ +isSolid
BNE +skipThisTile
JMP +isSolid
+skipThisTile

LDA Object_flags,x
AND #%10111111
STA Object_flags,x ;; reset sprite priority

I haven't found a problem with this yet.
 
Wow! Great fix Baardbi!! I have made some secret tunnels in my game. Using the Walkbehind tile. And if the player jumped and hit his head on the tunnel ceiling, he became visible for a short moment. This fixes that problem.
Very nice, thank you!
 

Icon-Ninja

New member
I think I have solved the problem where the sprite comes to the foreground when you press against a solid tile.

Instead of resetting the sprite priority in Bank18 I moved it to +skipThisTile in doHandleTileCollisions. So around line 212 in my doHandleTileCollisions it looks like this:



I haven't found a problem with this yet.
I'm late to the party on your walkable tile solution here, @baardbi . Do you think you could post an update in here containing all the necessary steps in one post? I'm getting lost reading the incremental fixes in this thread, but it sounds like you created a solid solution that I could definitely use in my current project.
 
Ok, I'm trying to backwards recreate how I did to get the walkBehind-Tile to work.
I am using it in my metroidvania game (4.5.9) and it works well.
It looks like this is what i did:

WalkBehindTile -Tutorial 2024
First you need a tile script

Code:
;;WalkBehind tile
LDA Object_flags,x
ORA #%01000000
STA Object_flags,x
RTS



Then lets go to ProjectSettings - Subroutines
we need to edit Handle Drawing Sprites
Look for this part, my scripts is further modyfied can't say exactly what line.

Code:
    doDrawSpritesLoop:
            LDA (temp16),y
            clc
            ADC temp3
            STA tempC ;; the calculated table position, with offest.
                        ;; tempC becomes the "tile to draw".
            INY
            LDA Object_flags,x     ;WalkBehind
            AND    #%01000000         ;WalkBehind
            BNE +noPriFlip         ;WalkBehind
                LDA (temp16),y     ;WalkBehind           
                JMP +doneFlip      ;WalkBehind
            +noPriFlip             ;WalkBehind
            LDA (temp16),y
            ORA #%00100000         ;WalkBehind
            +doneFlip              ;WalkBehind
            STA tempD ;; the next value is the attribute to draw.
            INY         ;; increasing again sets us up for the next sprite.
                        ;; now we can use tempA-D to draw our sprite using the macro.


And finally go to ProjectSettings - Subroutines - Handle Tile Collisions
Look for this part of the code:
I commented with "baardbi" on the lines that needs changing.

Code:
    LDA tempA
    BEQ +skipThisTile
    CMP #$01
    BNE +isNotSolid
        JMP +isSolid
    +isNotSolid
    +skipThisTile
    LDA tempB
    BNE +dontSkipThisTile
        JMP +skipThisTile
    +dontSkipThisTile:
    CMP #$01
    BNE +isNotSolid
        JMP +isSolid
    +isNotSolid
    +skipThisTile
    LDA tempC
    BEQ +skipThisTile
    CMP #$01
    BNE +isNotSolid   
        JMP +isSolid
    +isNotSolid
    +skipThisTile
    LDA tempD
    BEQ +skipThisTile
    CMP #$01
        ;BEQ +isSolid            ;baardbi fix for walkbehind tile
        BNE +skipThisTile        ;baardbi
        JMP +isSolid            ;baardbi
    +skipThisTile
LDA Object_flags,x                            ;baardbi   
AND #%10111111                                ;baardbi   
STA Object_flags,x ;; reset sprite priority    ;baardbi   
    LDA tempA
    BEQ tempAisNull
        ;; temp A is not null

Now everyting should hopfully be working..

All credit goes to AllDarnDavey, baardbi and everyone else who has helped create this!!!
I just copied and pasted it together.
This is one of my favorite tutorial fixes, really makes your game look cooler.
 

Icon-Ninja

New member
Ok, I'm trying to backwards recreate how I did to get the walkBehind-Tile to work.
I am using it in my metroidvania game (4.5.9) and it works well.
It looks like this is what i did:

WalkBehindTile -Tutorial 2024
First you need a tile script

Code:
;;WalkBehind tile
LDA Object_flags,x
ORA #%01000000
STA Object_flags,x
RTS



Then lets go to ProjectSettings - Subroutines
we need to edit Handle Drawing Sprites
Look for this part, my scripts is further modyfied can't say exactly what line.

Code:
    doDrawSpritesLoop:
            LDA (temp16),y
            clc
            ADC temp3
            STA tempC ;; the calculated table position, with offest.
                        ;; tempC becomes the "tile to draw".
            INY
            LDA Object_flags,x     ;WalkBehind
            AND    #%01000000         ;WalkBehind
            BNE +noPriFlip         ;WalkBehind
                LDA (temp16),y     ;WalkBehind          
                JMP +doneFlip      ;WalkBehind
            +noPriFlip             ;WalkBehind
            LDA (temp16),y
            ORA #%00100000         ;WalkBehind
            +doneFlip              ;WalkBehind
            STA tempD ;; the next value is the attribute to draw.
            INY         ;; increasing again sets us up for the next sprite.
                        ;; now we can use tempA-D to draw our sprite using the macro.


And finally go to ProjectSettings - Subroutines - Handle Tile Collisions
Look for this part of the code:
I commented with "baardbi" on the lines that needs changing.

Code:
    LDA tempA
    BEQ +skipThisTile
    CMP #$01
    BNE +isNotSolid
        JMP +isSolid
    +isNotSolid
    +skipThisTile
    LDA tempB
    BNE +dontSkipThisTile
        JMP +skipThisTile
    +dontSkipThisTile:
    CMP #$01
    BNE +isNotSolid
        JMP +isSolid
    +isNotSolid
    +skipThisTile
    LDA tempC
    BEQ +skipThisTile
    CMP #$01
    BNE +isNotSolid  
        JMP +isSolid
    +isNotSolid
    +skipThisTile
    LDA tempD
    BEQ +skipThisTile
    CMP #$01
        ;BEQ +isSolid            ;baardbi fix for walkbehind tile
        BNE +skipThisTile        ;baardbi
        JMP +isSolid            ;baardbi
    +skipThisTile
LDA Object_flags,x                            ;baardbi  
AND #%10111111                                ;baardbi  
STA Object_flags,x ;; reset sprite priority    ;baardbi  
    LDA tempA
    BEQ tempAisNull
        ;; temp A is not null

Now everyting should hopfully be working..

All credit goes to AllDarnDavey, baardbi and everyone else who has helped create this!!!
I just copied and pasted it together.
This is one of my favorite tutorial fixes, really makes your game look cooler.
Thanks!
 

tbizzle

Well-known member
I don't know if anyone has gotten this to work using the Adventure Module? All I did to get it to work was add this bit of code into AllDarnDavey's doDrawSprite.asm at around line 219

Code:
SwitchBank #$1D

right after this bit of code:

Code:
LDA (tempPointer_lo),y
STA temp16
LDA (tempPointer_hi),y
STA temp16+1

Then at the very end of the doDrawSprites.asm I added this:

Code:
ReturnBank

And it is working totally fine! Thank you @AllDarnDavey!
 

Icon-Ninja

New member
So I got this working in my project, for the most part. I'm using a 16x24 pixel player sprite, but when I collide with the walk behind tile, the entire sprite shifts behind all the background tiles instead of just the 16x16 pixel walk-behind tile. Does this solution simply change the player sprite's priority and not the actual tile's priority?
 

kevin81

Well-known member
That's how the NES architecture works. You can tell sprites to be either in front or behind the background tiles, but there's no way to draw a single tile in front of a sprite. Sprites will always be drawn over the tile's background color though, so you could try and design your level layout around that (i.e. by using background colored tiles only around the walk-behind tiles).
 
Top Bottom