CMUgraphics Sprite

I have this simple graphic package my teacher gave me (cmugraphics).I need to make a game(pokemon).I want to use sprites and a background but the sprites(pokemon) have white background and background is color and my graphic package doesn't make the white on the sprites go away.I have a solution but it isn't efficent any tips on how to improve so the program runs faster.Right now it draws the backgrond and saves each pixel as a color variable in a vector and replaces the whit on the sprite with a pixel from the vector.my sprites are 200x200 so the vector saves 40,000 element which cause it slow down.Any tips or improvements.If anything needs clarifying please ask


This Is my solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
void FixWhiteBoarder(window &testWindow,image &Front,int Drawx,int Drawy,int scalefrontx,int scalefronty)
{
	vector<color> backpic (scalefrontx*scalefronty);
	int syc=Drawy,sxc=Drawx,i=0;
	while(syc!=Drawy+scalefronty)
	{
		while(sxc!=scalefrontx+Drawx)
		{
			backpic[i]=testWindow.GetColor(sxc,syc);
			sxc++;
			i++;
		}
		sxc=Drawx;
		syc++;
	}
	syc=Drawy;
	sxc=Drawx;
	i=0;
	
	testWindow.DrawImage(Front,Drawx,Drawy,scalefrontx,scalefrontx);
	while(syc!=Drawy+scalefronty)
	{
		while(sxc!=scalefrontx+Drawx)
		{
			if(testWindow.GetColor(sxc,syc)==WHITE)
			{
				testWindow.SetPen(backpic[i]);
				testWindow.DrawPixel(sxc,syc);
			}
			sxc++;
			i++;
		}
		sxc=Drawx;
		syc++;
	}
	//testWindow.UpdateBuffer();
	//testWindow.SetBuffering(false);
}
Last edited on
1) Do your graphic package has any way to make specific color on the sprite transparent? Many use purple for transparency for example.
No my graphic can't make colors transparent so I had to use get color function and save the color of each pixel and redraw it where the picture pixel is white.I want to know if there is a way to make the program run faster by improving the code.in worst case I would like to know a really simple graphic package that can make transparency for begginers
really simple graphic package that can make transparency for begginers
SFML
http://www.sfml-dev.org/
closed account (N36fSL3A)
SDL2 is much better in my opinion. If you don't like it then SFML is your only other option.
How do u make background of sprite dissappear in SFML
Either save your images as PNG with correct alpha-channel (transparency) or use void sf::Image::createMaskFromColor() method
http://www.sfml-dev.org/documentation/2.1/classsf_1_1Image.php#a22f13f8c242a6b38eb73cc176b37ae34
Is there a free program or website that can make PNG with correct alph-channel
Paint.NET
Gimp
(both are programs)
Last edited on
Thank you so much for the tip on Paint.net and Sfml.
Topic archived. No new replies allowed.