Rotating a sprite 90 degrees
Moderator: Moderators
- battagline
- Posts: 152
- Joined: Wed Sep 05, 2018 11:13 am
- Location: Colorado
- Contact:
Rotating a sprite 90 degrees
Is it possible to rotate a sprite by 90 degrees? Or do I need to do it in photoshop and include it in the .chr file that way?
Thanks
Thanks
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Re: Rotating a sprite 90 degrees
The hardware does not support rotation by 90 degrees, no. Only horizontal and vertical flips, which together are equivalent to a 180 degree rotation.
- rainwarrior
- Posts: 8731
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Rotating a sprite 90 degrees
If you're using CHR-RAM you could write some code to rotate the sprite tile before uploading it to the PPU. This would only really be helpful if you have a lot of stuff that needs a rotated form, though. Doesn't really solve any problems of e.g. pattern table management.
Re: Rotating a sprite 90 degrees
It'd be terribly slow.
Rotate 1 tile left 90°
LDY #0
LDX #0
Loop:
LDA Source, Y
Loop2:
LSR a
ROL Dest, X
INX
CPX #8
BNE Loop2
LDX #0
INY
CPY #8
BNE Loop
LDX #8
;x and y should be 8 now
Loop3:
LDA Source, Y
Loop4:
LSR a
ROL Dest, X
INX
CPX #16
BNE Loop4
LDX #8
INY
CPY #16
BNE Loop3
Edit, wrote the 2nd half.
Hasn't been tested. Only in my head.
Edit, and I think, rotate right 90° would be...replace LSR with ASL and ROL with ROR. (edited about 6 times)
Rotate 1 tile left 90°
LDY #0
LDX #0
Loop:
LDA Source, Y
Loop2:
LSR a
ROL Dest, X
INX
CPX #8
BNE Loop2
LDX #0
INY
CPY #8
BNE Loop
LDX #8
;x and y should be 8 now
Loop3:
LDA Source, Y
Loop4:
LSR a
ROL Dest, X
INX
CPX #16
BNE Loop4
LDX #8
INY
CPY #16
BNE Loop3
Edit, wrote the 2nd half.
Hasn't been tested. Only in my head.
Edit, and I think, rotate right 90° would be...replace LSR with ASL and ROL with ROR. (edited about 6 times)
nesdoug.com -- blog/tutorial on programming for the NES
- battagline
- Posts: 152
- Joined: Wed Sep 05, 2018 11:13 am
- Location: Colorado
- Contact:
Re: Rotating a sprite 90 degrees
It sounds like the best thing to do is just rotate it 90 degrees photoshop and have 2 versions in the .chr
Thanks for your help, was just hoping there was some better way
Thanks for your help, was just hoping there was some better way
A few of my web games
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
https://www.embed.com
Or if you're bored at work
https://www.classicsolitaire.com
Re: Rotating a sprite 90 degrees
It works. I made a demo, with source. Also included flip tile H and flip tile V, which were easier.
It is very slow. About 2250 cycles per tile. (and only 300 cycles for flip V).
It is very slow. About 2250 cycles per tile. (and only 300 cycles for flip V).
- Attachments
-
- ROTATE.zip
- (2.39 KiB) Downloaded 157 times
-
- ROTATE.png (4.46 KiB) Viewed 5149 times
nesdoug.com -- blog/tutorial on programming for the NES
Re: Rotating a sprite 90 degrees
Would it make it faster to use a pre-calculated table of conversion? (I couldn't understand your code, where are you writing to?) edit: oh okay, it's the LSR and ROL. I'm rusty
Last edited by nesrocks on Thu Oct 11, 2018 6:52 am, edited 2 times in total.
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!
https://www.patreon.com/bitinkstudios <- Support me on Patreon!
https://www.patreon.com/bitinkstudios <- Support me on Patreon!
Re: Rotating a sprite 90 degrees
I'm fairely sure at least one of the Dragon Quest/Warrior games does this (in software), could probably be 3 I don't remember. As this is a complex/slow operation they probably do it when loading the graphics on the screen, not on the fly.
Re: Rotating a sprite 90 degrees
A partial unroll (replacing the inner X: lsr A / rol $0300,x / inx / cpx #8 / bne X) speeds up each row from 127 cycles to 64 cycles, speeding it up in total to just 1242 cycles.dougeff wrote:It is very slow. About 2250 cycles per tile.
- rainwarrior
- Posts: 8731
- Joined: Sun Jan 22, 2012 12:03 pm
- Location: Canada
- Contact:
Re: Rotating a sprite 90 degrees
I would only think it should be useful if you need to mass rotate a bunch of tiles, e.g. if you wanted to rotate your world map or something like that. Could save a bunch of ROM space, maybe. Wasn't really suggesting it as a realtime effect, though that's not entirely out of the question.
Re: Rotating a sprite 90 degrees
It could be useful for CHR compression algorithms I suppose.
Re: Rotating a sprite 90 degrees
JRoatch's Donut codec, developed for a forthcoming version of Action 53, has a rotation mode. But it's not for reusing the same tile in unrotated and 90 degree rotated modes; it's for handling non-tile data in CHR ROM.