Another question about sprites

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
o_O

Another question about sprites

Post by o_O »

I'm just learning about sprites and I'm a little stuck.
When I place my sprite on the screen the colours turn out all messed up.
Here's what I am doing.
I use gifload to load a gif file containg all my sprites, then I GET the sprites into my array. Next I turn the entire screen white, except for where the sprites are which I turn black.

then I GET my mask into a different array, using all the same coordinates i did for the original sprites.( i just copied and pasted the GET code and changed the array name)
Then I GIFLOAD my background, PUT the mask using AND, then PUT the sprite using XOR. According to some tutorial I read, that should work, and not affect my sprite's colours. What is wrong?
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Sounds like you got a pretty good grasp of masking, so I won't need to orientate you on that...but one thing you need to keep in mind is that you're in a paletted mode. Whoever described masking to you neglected to mention that if the palette is different, your colors are going to change. Basically...it sounds like your sprite's palette is different than the palette of the image you're loading. They need to have the same palette. Masking isn't about making sprite colors not change...it's about allowing for sprites with transparent regions. Also, it doesn't matter if the colors of your mask are white or black...we're not dealing with an RGB mode where that method holds true. Again, you're dealing with the palette, so what you would consider black would actually have to be palette index 0, and what you would consider white would be palette index 255.
o_O

Like i said, I'm new so . .

Post by o_O »

I haven't got a grasp on pallette's yet (palette, pallete, pallette?), this is probably one of the first things i should have learned, but it isn't. I never changed the pallette. I stole all my sprites and the background from the same program(as .bmp's) and turned them all into .gif's using PSP8. Like i said, i haven't touched the pallette so that should be the same for my entire program. Also, because my program doesn't work right quite yet, i'll have to ask. Does the Mask eliminate the Black box that surrounds the sprite or is there something else to take care of that?
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Re: Like i said, I'm new so . .

Post by Nodtveidt »

o_O wrote:Does the Mask eliminate the Black box that surrounds the sprite or is there something else to take care of that?
That is its sole purpose. :D
o_O

Not it's sole purpose

Post by o_O »

it is also meant to prevent the colours from become distorted. isn't it?
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Nope. That has absolutely nothing to do with it.

However, if you look at it in the sense of taking an ordinary sprite and PUTting it using the XOR operator, then yeah...I guess you could say it has to do with preserving colors. :D

But since that's not what you're referring to here, then nope...that is a completely unrelated subject.
o_O

But . . .

Post by o_O »

Ok then. Well can you tell me how to, or direct me to a tutorial or something that can show me how to both preserve the colours of my sprite/background and stop that black outline box.
User avatar
Pete
Site Admin
Posts: 887
Joined: Sun Dec 07, 2003 9:10 pm
Location: Candor, NY
Contact:

Post by Pete »

I don't know if this tutorial will be of any help, but you might want to check it out:

http://www.petesqbsite.com/sections/tut ... prite2.htm

The bottom section discusses simple sprite masking techniques.
o_O

I'm sorry

Post by o_O »

I just cannot get this to work Properly. I can eliminat the outline box around my sprite but i cannot get the colours to turn out properly. If I Uploaded my sprites, and background would somebody be able to help me? Both are GIF Format and I am using GIFLOAD.
User avatar
Pete
Site Admin
Posts: 887
Joined: Sun Dec 07, 2003 9:10 pm
Location: Candor, NY
Contact:

Post by Pete »

Actually, upload the whole kit and kaboodle -- your sprites, masks and the source code that's giving you trouble.

Somebody will definitely take a look at it!

Maybe you should even post your source code in this forum.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

One look at the images and I bet I can determine the problem. :D In fact, I'll guarantee I can fix the problem. :D
o_O

There

Post by o_O »

I uploaded the source code, and all associated files. You can find it all at
http://www.angelfire.com/games5/heliostrapolis/ It's called "A Space Quest clone, An on going project That I can't get to work." Thanx for the help.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

No, thank you for outright slaying my browser. What the hell man?

I'll visit your page and check it out when you design a proper webpage. :evil:

GET RID OF THE &*@^#$@#*&$^%*@#^$%^#!@ MUSIC! :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil: :evil:
o_O

Okay, and again, sorry

Post by o_O »

Sorry about crashing your browser, like I said, made the site a couple years ago and never really did any major changes, just enought to keep it active(even though no one ever visits it). I just played with it a bit, I stopped the music and moved the downloads to another page.

http://www.angelfire.com/games5/heliost ... loads.html

sorry )-: But thanx for at least trying to help
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Hehehe dude I was mostly messin' with ya ;) but ya, that page was a real browser-killer. I'll take a look at your stuff though. :D

One thing though is you might want to look up "deadly sins of web design" for some pointers on making effective sites. :D
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Okay, as I said...it wouldn't take me long to discover the problem, and as I suspected, the problem is your palette. Each image has a different palette; that's a no-go when dealing with a paletted mode. Each of your images needs to be using the same colors. I've taken the liberty to create a unified palette for the three images you provided; it's not difficult at all to do, and I did it with Paint Shop Pro. :)

http://www.nodtveidt.net/gifs.zip

That's the reason your sprites have the wrong colors. Now, a couple of suggestions for your code:

* You should get into the habit of indenting code loops. Although it's preference, it makes it easier for others to read your code. For example:

Code: Select all

'although this works...
IF x = 2 THEN
PUT (a, b), rog1mask(z), AND
PUT (a, b), rog1(z), XOR
ELSEIF x = -2 THEN
PUT (a, b), rog2mask(z), AND
PUT (a, b), rog2(z), XOR
ELSEIF y = 2 THEN
PUT (a, b), rog3mask(z), AND
PUT (a, b), rog3(z), XOR
ELSEIF y = -2 THEN
PUT (a, b), rog4mask(z), AND
PUT (a, b), rog4(z), XOR
END IF
'this looks better
IF x = 2 THEN
    PUT (a, b), rog1mask(z), AND
    PUT (a, b), rog1(z), XOR
ELSEIF x = -2 THEN
    PUT (a, b), rog2mask(z), AND
    PUT (a, b), rog2(z), XOR
ELSEIF y = 2 THEN
    PUT (a, b), rog3mask(z), AND
    PUT (a, b), rog3(z), XOR
ELSEIF y = -2 THEN
    PUT (a, b), rog4mask(z), AND
    PUT (a, b), rog4(z), XOR
END IF
* This is a no-no:

Code: Select all

CALL gifload("c:\dos\cart.gif")
NEVER use hard paths. Use absolute paths. Also, you don't need to use CALL for subs that have declares. And if you don't manually write the declares in the QB IDE, the IDE will add them for you.

For the images...a great way of creating a unified palette is to take all the images you're going to need and paste them into one large image, then reduce that image to 256 colors. Save the resulting palette. Now, apply that palette (using Nearest Color) to all of your images. You'll have a perfect unified palette and never have another color problem as long as all your images use that palette. :D
o_O

Thanx

Post by o_O »

Thanks for all the help, and again sorry about the webpage. Like I said in some earlier post (if i din't say it, I should have) I'm pretty much new to sprites and images and palletes. As for the indenting of code, i usually do, but I guess i got lazy and just started typing the code. Thanx again for the help
Post Reply