Re: Sprites
>How do you put sprites on the screen in SVGA modes without destroying the
>background (with color 0 being transparent)? The only way that I could
figure
>out was to check the color of each pixel in the image, and write the
nonzero
>pixels to the screen. This works, but is much too slow.
>Thanks in advance.
Split the sprite up in pieces of horizontal lines and store the complete
offset of every set of those lines. The use pixel to display every set. If
you want to poke () and do the bank-switches yourself, you're better off
replacing the {x,y} position wiht a fixed calculated position, an offset to
add to the begin offset in memory.
This is the theory behind the compiled sprites in my GFX.
Here I remade a simplified version of those routines:
function make_cs (sequence pic, index trans_color)
sequence ret
index pos, prev
ret = {}
for index = 1 to length(pic) do
prev = 0
pos = find (trans_color, pic[index])
while pos do
ret = append(ret, {{prev, index}, pic[index][1..pos-1]
if not length(ret[length(ret)][2]) then
ret = ret[1..length(ret)-1]
end if
prev = pos
pos = find (trans_color, pic[index][pos+1..length(pic[index])]
end while
if length(pic[index]) then
ret = append (ret, {{prev, index},pic[index]})
end if
return ret
end function
procedure display_cs (sequence cs, sequence pos)
sequence item
for index = 1 to length(cs) do
item = cs[index]
pixel (cs[1]+pos, cs[2])
end for
end procedure
See, the best optimization trick in games and most other stuff is to see
when we calculate something or make a decision.. always ask youself : Can
this calculation, decision or part of this decision be made fewer times ?
Like calculating an offset, you only need to do this when a position
changes, _not_ everytime you want to draw a sprite, etc.
Ralf Nieuwenhuijsen
nieuwen at xs4all.nl
|
Not Categorized, Please Help
|
|