Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > clipping sprites
2010-06-01 11:06
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
2010-06-01 11:43
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..
2010-06-01 11:48
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...
2010-06-01 12:08
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.
2010-06-01 12:50
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.

2010-06-01 13:51
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..)
2010-06-01 13:55
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. :)
2010-06-01 14:01
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..
2010-06-01 17:10
doynax
Account closed

Registered: Oct 2004
Posts: 212
Quoting WVL
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..
You can also save a fair bit by only bit-masking the one column which needs it.
2010-06-02 06:57
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 :)
2010-06-02 08:14
enthusi

Registered: May 2004
Posts: 677
I would go for a 'dumb' routine as well.
But check for dx and dy optionally.
2010-06-02 12:17
Oswald

Registered: Apr 2002
Posts: 5094
24 columns horizontally, now aint that fullscreen minus last row ? where on raster irq solves the problem: change sprite pointer to an empty sprite.
2010-06-02 12:20
JackAsser

Registered: Jun 2002
Posts: 2014
Quote: 24 columns horizontally, now aint that fullscreen minus last row ? where on raster irq solves the problem: change sprite pointer to an empty sprite.

"24 columns horizontally" is like WTF! Either u have columns or rows, period.
2010-06-03 08:31
WVL

Registered: Mar 2002
Posts: 902
As a sidenote..

Are diagonal kefrens the same as horizontal columns or more like vertical rows?
2010-06-03 08:39
Steppe

Registered: Jan 2002
Posts: 1510
That depends on the angle. ;-)
2010-06-03 08:56
enthusi

Registered: May 2004
Posts: 677
Quote: That depends on the angle. ;-)

That's probably what makes proper roto-zooms so tough ;-)
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
iAN CooG/HVSC
A3/AFL
zscs
Acidchild/Padua
TheEnemy/TREX/THD
Chesser/Blazon
Andy/AEG
Paladin/G★P
The Human Co../Maste..
Guests online: 99
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 Dawnfall V1.1  (9.5)
7 Rainbow Connection  (9.5)
8 Onscreen 5k  (9.5)
9 Morph  (9.5)
10 Libertongo  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top NTSC-Fixers
1 Pudwerx  (10)
2 Booze  (9.7)
3 Stormbringer  (9.7)
4 Fungus  (9.6)
5 Grim Reaper  (9.3)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.043 sec.