How to increase/desrease a speed of sprite

Hello.

I'm just interesting?, how to increase/desrease a speed of sprite, for example some "bullet" sprite.

Could you code some example? 

Comments

  • Depends on the game, usually you change the number to a higher one on how many it moves per frame. No code will help you, it's as simple as that, good luck finding the value you need or changing whatever you need.
  • Let's say for example the bullet uses sprite $0200.



    From that information, we know that:



    $0200 is the vertical positioning.

    $0201 is the tile number.

    $0202 is the attribute number.

    $0203 is the horizontal positioning.



    So if we want to move the sprite vertically, we'd just have to change $0200 every frame.



    MoveBulletUp:

    DEC $0200

    RTS



    If you wanted to move it up faster, you would just do that twice.



    MoveBulletUp:

    DEC $0200

    DEC $0200

    RTS
  • In actual games objects rarely use fixed OAM position and rarely store coordinates in screen space. Normally bullet coord would be two bytes somewhere in the RAM, and depending from design the 'speed' could be code (similar to above, but 16-bit), or 'delta'. Often it stored in fixed point, like 12 bits integer and 4 bits fractional part, or something like that, so the bullet can have non-integer speed (like 1.5 pixels per frame).
  • Thanks for the information.

    Please could you code how to get 0,5 value
  • 0.5 pixels per frame is in fact 'change every other frame'. So you can make a counter that will serve as a divider:



    lda counter ;the counter variable

    eor #1 ;it just changes between 0 and 1

    sta counter

    beq skip

    inc coord ;the coord variable

    skip:





    Or you can use fixed point math. If .5 is the smaller unit you need, you just need one bit as fractional part (the counter in the example above is exactly that, just done another way). In other words, your coord value is stored multiplied by two, you simply increment it each frame, but before using it you divide it by two (shift right by one bit).

  • 1).


    How I understand, PPU have rate about 50 frame/sec and when I perform 


     


    Moving:


      LDX $0203       ; load some "bullet" sprite X position 


      INX


      STX $0203       ; store it


      JMP Moving:


     


    Then PPU move the "bullet" where the move is one pixel


    But in loop PPU forced use full rate as 6502 rate more then PPU. Is it? )


     


    2). 


    I can't decrease rate of the bullet by you instruction. May be I do not understand something.


    Please can you paste you code in my "Moving" cycle that speed of the sprite will be double less then just INX


     


    p.s.


    I assemble using NESASM.EXE and test the result using nestopia.exe


     


    Sorry for my english
  • I'm not sure why you're using LDX and STX. I think you're assuming because you're using the x accumulator that it's affecting the x axis, which is incorrect. They actually have nothing to do with one another.



    To move the sprite slower than one pixel per cycle, you need to use 16-bit math.



    Moving:

    LDA Partial ;zero page variable

    CLC

    ADC #$xx ;this is where you'll set the speed

    STA Partial

    LDA $0203

    ADC #$00

    STA $0203
  • PPU does not move anything at all. What it does is display a picture according to the settings that you provided. So when you change a X-offset in the OAM, that's what the move actually is; PPU just will display it once you send the OAM buffer to the VRAM.



    It is difficult to provide you with a working code, as you use absolute addresses and locations in the OAM buffer instead of labeled variables.



    Your code



    ldx $0203

    inx

    stx $0203



    could be replaced with just inc $0203. That would be the 'inc coord' line in my example above.

  • Originally posted by: Shiru



    0.5 pixels per frame is in fact 'change every other frame'. So you can make a counter that will serve as a divider:



    lda counter ;the counter variable

    eor #1 ;it just changes between 0 and 1

    sta counter

    beq skip

    inc coord ;the coord variable

    skip:





    Or you can use fixed point math. If .5 is the smaller unit you need, you just need one bit as fractional part (the counter in the example above is exactly that, just done another way). In other words, your coord value is stored multiplied by two, you simply increment it each frame, but before using it you divide it by two (shift right by one bit).



    I never thought using an EOR for this. I would have LDA'd the counter variable and then I would ROR A and then do stuff based on the carry flag. I also used this technique to compare odd and even numbers in Beat 'em and Eat 'em...


  • How about timer-based animation?

  • Originally posted by: Vectrex280996



    I never thought using an EOR for this. I would have LDA'd the counter variable and then I would ROR A and then do stuff based on the carry flag. I also used this technique to compare odd and even numbers in Beat 'em and Eat 'em...

     

    Doesn't really matter how you would do it, if it works either way. lda mem/eor #/sta mem is almost the same as inc mem:lda mem:ror a, one tick faster, two bytes longer.

  • Originally posted by: KHAN Games



    I'm not sure why you're using LDX and STX. I think you're assuming because you're using the x accumulator that it's affecting the x axis, which is incorrect. They actually have nothing to do with one another.



    To move the sprite slower than one pixel per cycle, you need to use 16-bit math.



    Moving:

    LDA Partial ;zero page variable

    CLC

    ADC #$xx ;this is where you'll set the speed

    STA Partial

    LDA $0203

    ADC #$00

    STA $0203



    This is how I did the variable speed in BAN.  It is easy in one direction, but when you do accelleration, deaccelleration, right, and left  (or up/down) movement, it gets really fun!!




  • Thanks.

    More or less I get it. But I have a couple of questions. I have find in internet some source code.

    1. In example that I have attached (http://yadi.sk/d/xLjhvHIxR5XH8) in line 122 position of a sprite is increasing once.

    NOTHINGdown:

    lda X_Pos

    adc #01

    sta X_Pos

    (Sprite by default under screen and need to press UP to show it and then a spite moving right) I'm interesting, "who" set this default speed as it is?





    2. Could you change move.asm that the sprite will appear in center of screen and auto move right slower twice?

    I try. I can't do it.)



    p.s.

    I use nesasm to compile and deponia to execute.
  • The "ADC #$01" is 1 pixel per frame. You have to change that number to which ever speed you want to move.



    To make it move faster use:



    LDA X_Pos

    CLC

    ADC #$02 ;or whatever speed you want to use

    STA X_Pos





    To make it move slower, use something like:



    INC Ticker

    LDA Ticker

    CMP #$04

    BNE .end



    LDA #$00

    STA Ticker

    INC X_Pos

    .end



    Where "Ticker" is just a variable. Simply change the "CMP #$04" command to change the speed at which it moves. This is probably the simplest way to do this and the easiest to understand, but there are definitely more efficient ways.
Sign In or Register to comment.