How to increase/desrease a speed of sprite
in The Brewery
Hello.
I'm just interesting?, how to increase/desrease a speed of sprite, for example some "bullet" sprite.
Could you code some example?
I'm just interesting?, how to increase/desrease a speed of sprite, for example some "bullet" sprite.
Could you code some example?
Comments
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
Please could you code how to get 0,5 value
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
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
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...
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!!
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.
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.