| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
clipping sprites
Hi
I am coding a game with a screen of 24 columns horizontaly, and one of the sprites might leave that window and I need to to clip it, I thought of using a black sprite to cover the other one, but unfortunately can't waste a sprite for that. Also I thought of creating new frames for the sprite to simulate that but that would inflate the number of frames a lot. Is there another way?
Thanx |
|
| |
HCL
Registered: Feb 2003 Posts: 728 |
Sounds hard.. I assume that you need the sprites to be of higher priority than the background, in that case you can not cover the sprites with any kind of char/bitmap gfx outside the game-screen.
Do you have a char-screen of bitmap? Is it scrolling with d016? Perhaps some more details would show some possibility, who knows.. |
| |
enthusi
Registered: May 2004 Posts: 677 |
Many games (e.g. Maniac Mansion =) apply sprite-clipping in real-time.
If the movements of the sprite are 'simple' that would be rather easy to do and not THAT cpu-wasty...
Naive approach:
if sprite = max_x+1:
AND every (n*3)th sprite-byte with #%11111110
etc... |
| |
WVL
Registered: Mar 2002 Posts: 902 |
Just clip it in realtime, it shouldnt cost a lot of time at all, especially when you want to clip a column. Then the clipping is the same for every row.
lda spritedata,x
and #%00001111
sta sprite,x
lda spritedata+1,x
and #%11111111
sta sprite+1,x
lda spritedata+2,x
and #%11111111
sta sprite+2,x
dex dex dex
bpl loop
That's only 819 cycles, or +- 14 rasterlines.. and you only have to set the 3 AND values in advance.
|
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
@HCL: I am using char mode at the moment but it might go bitmap, I'm not sure yet. And no scrolling.
@enthusi, WVL: Thank you for the tips. I was hoping that might exist some magic to get this going...
I think ANDing the sprite's gfx will be the only option I have. It might not eat much rastertime, I will try.
|
| |
WVL
Registered: Mar 2002 Posts: 902 |
How many colors do you need in your char gfx?
There's another way if you use multicolor mode. If you set your sprites behind char gfx in multicolor mode, the sprite ONLY goes behind %11 and %10 colors, but stays in front of %00 and %01 colors.
So if you make your border from %11 or %10 colors and the graphics using only %00 or %01 colors, then you're set. It *does* greatly limit the colors in your gfx area though (basically it leaves you with singlecolor gfx in 2x1 resolution..). Btw, that also works with bitmap graphics.
You can also make your sprite the same color as the borders, then you will not see it ;) (this limits your sprite color, or forces you to pick another border color..) |
| |
Iapetus/Algarbi/Wood
Registered: Dec 2004 Posts: 71 |
Quote: How many colors do you need in your char gfx?
There's another way if you use multicolor mode. If you set your sprites behind char gfx in multicolor mode, the sprite ONLY goes behind %11 and %10 colors, but stays in front of %00 and %01 colors.
So if you make your border from %11 or %10 colors and the graphics using only %00 or %01 colors, then you're set. It *does* greatly limit the colors in your gfx area though (basically it leaves you with singlecolor gfx in 2x1 resolution..). Btw, that also works with bitmap graphics.
You can also make your sprite the same color as the borders, then you will not see it ;) (this limits your sprite color, or forces you to pick another border color..)
Thx WVL
That is too much restrictive, I will use the AND method to clip sprite. :) |
| |
WVL
Registered: Mar 2002 Posts: 902 |
Darnit.. I typed a whole lotta extra text and then was refused to edit my previous post ;)
What I wanted to say is that in the interference part in Pearls for Pigs I used the 2nd option : make the sprites-to-be-clipped the same color as the border.. Which is the reason for the lousy purple-colored border :D
I could have made the border any color, but I couldnt since I'm storing sprite images in those border areas. (so there were all color combos in the bitmap data).
May I ask if you use multicolor or singlecolor chars? and how many colors?
Ooh! and this is a nice excuse for the SAX command :D
ldx #andvalue_for_left_column
lda fromsprite+0
sax tosprite+0
lda fromsprite+3
sax tosprite+3
lda fromsprite+6
sax tosprite+6
...
ldx #andvalue_for_middle_column
lda fromsprite+1
sax tosprite+1
lda fromsprite+4
sax tosprite+4
lda fromsprite+7
sax tosprite+7
...
ldx #andvalue_for_right_column
lda fromsprite+2
sax tosprite+2
lda fromsprite+5
sax tosprite+5
lda fromsprite+8
sax tosprite+8
...
which is about 510 cycles ~ 9 rasterlines. Unrolling and SAX will save you +- 5 rasterlines.. maybe that's worthwhile to you! You can save even more if you're OK with storing the clipped sprite in the 0page, in which case you can get down to 447 cycles, about 8 rasterlines.. |
| |
doynax Account closed
Registered: Oct 2004 Posts: 212 |
Quoting WVLwhich is about 510 cycles ~ 9 rasterlines. Unrolling and SAX will save you +- 5 rasterlines.. maybe that's worthwhile to you! You can save even more if you're OK with storing the clipped sprite in the 0page, in which case you can get down to 447 cycles, about 8 rasterlines.. You can also save a fair bit by only bit-masking the one column which needs it. |
| |
WVL
Registered: Mar 2002 Posts: 902 |
True, but then you need also some if-then-else to copy back columns that dont need to be masked anymore. Basically an if-then-else per column, deciding if the column is already ok, needs to be restored to original or needs to be clipped. (restoring and clipping is just the same code except the ldx #bla, if you use the SAX routine)
Also that doesnt work if your sprite is animated ofcourse :) |
| |
enthusi
Registered: May 2004 Posts: 677 |
I would go for a 'dumb' routine as well.
But check for dx and dy optionally. |
... 5 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 - Next |