ChangeTileAtCollision when scrolling (Metro 4.5.9)

In my game, I have tiles that are solid, but become walkable and change to a blank background after upon collision with a player projectile.

I include the code below in the above tile's code, where #$20 is my blank black background, and #$00 is my walkable tile.

ChangeTileAtCollision #$20, #$00

Normally it works fine; however, if the screen is scrolling during the collision, the tile will become walkable as expected, but the background retains its solid graphics.

The issue doesn't seem to occur on the emulator FCEUmm, but when I use my testing emulator (Mesen) or console, it does, so I'm thinking it's a problem of background graphics not being able to get updated in time. I'm hoping that when I'm getting close to finishing my game, I can delete code I know I'm not using to help improve optimization, but I don't know if that is the best practice or not.
 

m8si

Active member
Having the same issue and haven't found a perfect solution yet. However waiting a frame works in most cases but causes lag.

Code:
ChangeTileAtCollision #$20, #$00
JSR doWaitFrame
 
Having the same issue and haven't found a perfect solution yet. However waiting a frame works in most cases but causes lag.

Code:
ChangeTileAtCollision #$20, #$00
JSR doWaitFrame

Thanks for the response m8si. I tried this and it did seem to alleviate the issue. In fact, on my first test, all of the tiles managed to change as intended, although I still get a screen full of garbled graphics on occasion (an issue which I neglected to mention in my first post).

However, it's nice to know about this subroutine, so thanks again!
 

dale_coop

Moderator
Staff member
You could try adding this a the beginning of your tile script :
Code:
LDA updateScreenData
AND #%0000100
BEQ +continue
    RTS
+continue:
I haven't tested... but I think it would prevent the tile to be changed at the same time that the scrolling update.
 
You could try adding this a the beginning of your tile script :
Code:
LDA updateScreenData
AND #%0000100
BEQ +continue
    RTS
+continue:
I haven't tested... but I think it would prevent the tile to be changed at the same time that the scrolling update.

Thanks for this idea Dale. After a couple playthroughs without the issue occurring, it seems that you have eliminated the problem :)
 

m8si

Active member
You could try adding this a the beginning of your tile script :
Code:
LDA updateScreenData
AND #%0000100
BEQ +continue
    RTS
+continue:
I haven't tested... but I think it would prevent the tile to be changed at the same time that the scrolling update.
Nice! I got test this tomorrow. I believe it will solve the problem. I had a similar approach with updateScreenData but I put waitframe instead of RTS and it caused lag.
 
Just wanted to note that, while Dale's fix does seem to eliminate the issue of garbled graphics, for me, it has created an issue where expected behavior of the tile will sometimes fail to occur while scrolling.

For example, my tile acts as a solid, but becomes walkable upon colliding with a player projectile. If the player or an enemy collides with the tile in its solid state while scrolling, they will sometimes clip into the tile a couple pixels and be rendered immovable. I believe this is because by putting Dale's code at the beginning, it will reach the RTS before executing checks that I want to occur.

To prevent this, I tried putting the code for solidity check before Dale's code, but this means that if my projectile hits the tile with scrolling, it will destroy itself upon colliding with the solid, but RTS before reaching the code to change the tile to walkable.

I feel like this issue is really close to being solved, maybe by repositioning Dale's code and also adding a waitframe somewhere?
 

m8si

Active member
Sadly this did not work for me either. It works most of the time but sometimes the tile won't vanish. With this code it works 100% of time but if players collects more than one pickup during one update it forces to wait another frame and causes lag.

Code:
    ChangeTileAtCollision #$00, #$00     
    LDA updateScreenData
    AND #%00000100
    BEQ +isUpdated
    JSR doWaitFrame
    +isUpdated:
 

tbizzle

Well-known member
You could try adding this a the beginning of your tile script :
Code:
LDA updateScreenData
AND #%0000100
BEQ +continue
    RTS
+continue:
I haven't tested... but I think it would prevent the tile to be changed at the same time that the scrolling update.
Thanks @dale_coop , this cleared up a graphical glitch I was having when colliding with pickups! I put it right before my Dropables code.
 
Top Bottom