Sprite tearing when moving right

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
softserve
Posts: 2
Joined: Mon May 16, 2022 2:17 pm

Sprite tearing when moving right

Post by softserve »

Hello I've just started with this yesterday so I'm very new and I'm sure there's tons I'm already doing wrong. But for starts I'm just trying to draw a 4 sprite character to screen and move with controller inputs. Everything seems to work well except there's a one pixel gap between the 2 sprites on the left and the two on the right that only occurs when moving in the right direction. Here's the relevant section of code:

Code: Select all

CheckRight
  LDA #%00000001
  AND buttons
  BEQ CheckLeft
  INC playerx

CheckLeft 
  LDA #%00000010
  AND buttons
  BEQ CheckUp 
  DEC playerx 

CheckUp
  LDA #%00001000
  AND buttons
  BEQ CheckDown
  DEC playery

CheckDown
  LDA #%00000100
  AND buttons
  BEQ GameEngineDone
  INC playery

GameEngineDone
  JSR UpdateSprites
  RTI

ReadController:
  LDA #$01
  STA $4016
  LDA #$00
  STA $4016
  LDX #$08
ReadControllerLoop:
  LDA $4016
  LSR A           
  ROL buttons     
  DEX
  BNE ReadControllerLoop
  RTS

UpdateSprites
  LDA playerx 
  STA $0207
  STA $020B
  ADC #$08
  STA $0213
  STA $020F

  LDA playery
  STA $0204
  STA $020C
  ADC #$08
  STA $0208 
  STA $0210

  RTS
  
Any insight into this would be helpful. Just assume I'm an idiot with any explanations.
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: Sprite tearing when moving right

Post by Fiskbit »

I'd start by putting CLC before those ADC instructions. Those add 1 extra if carry is set, so when it's in an unknown state, you need to explicitly set or clear it.
softserve
Posts: 2
Joined: Mon May 16, 2022 2:17 pm

Re: Sprite tearing when moving right

Post by softserve »

Fiskbit wrote: Mon May 16, 2022 3:02 pm I'd start by putting CLC before those ADC instructions. Those add 1 extra if carry is set, so when it's in an unknown state, you need to explicitly set or clear it.
Wow I'm so dumb I'm completely missed that. Worked like a charm thanks!
Post Reply