Welcome! Log In Create A New Profile

Advanced

sprite zoom problem

Posted by g_man 
sprite zoom problem
April 14, 2010 05:08AM
My game is almost working :D, but I have one final problem(for now). When I try to shrink a sprite at just disapears, but when i grow it it is fine. I'll give some code later, but I know this isn't a problem with libwiisprite, because, using the same sprite, I tested it. I just made a simple program that shrinked and grew my planet sprite. This test worked fine, the planet never dissapered from the screen. Here are some pictures from the problem. The only difference in the code is that in the first one, the radius of the planet is set to 50, and in the second one the radius is set to 49.
R=50
R=49
Here is my source:
Source Removed
The problem should be in the file called levels.cpp in the function runLevel in this section:
for(i=0;i<levelList[lvlnum].numPlanets;i++){	//For every planet that exists
		planets.SetImage(&planet1img);																//Set the image
		planets.SetZoom(levelList[lvlnum].planetR/50);											//Set the zoom 
		planets.SetPosition(levelList[lvlnum].planetX-50,levelList[lvlnum].planetY - 50);	//Set the position
		manager.Append(&planets);																	//Add to the layer manager
	}
What I did was my original planet has a radius of 50, so took the new planet radius and devided it by 50. This gives me a ratio of planet sizes, which libwiisprite uses.
Thank you for any feedback.
EDIT: This doesn't aonly happen for the planet, but also for the target sprite. When the radius size is set smaller than the radius of the sprite, the sprite doesn't appear.



Edited 2 time(s). Last edit at 04/15/2010 12:26AM by g_man.
Re: sprite zoom problem
April 14, 2010 06:09AM
Could this be some kind of a common effect accross graphics libraries...I think I had the same problem using GRRLIB when resizing a sprite to a smaller size (size smaller than the initial texture).

I ended up solving the problem the brute force method...re-creating the smaller texture using my own code...but I think there is probably a way around this.
Re: sprite zoom problem
April 14, 2010 06:49AM
Like I said before, It has shrunken the image before, but now it doesn't want to. I could just make the image base smaller, but if I get too small the larger circles won't look like circles.
Re: sprite zoom problem
April 14, 2010 09:20AM
Hi there g_man. How long have you been programming in C? According to your Level struct, levelList[lvlnum].planetR is an integer. When you divide an integer by an integer (i.e. levelList[lvlnum].planetR/50), it carries out integer arithmetic, meaning only the integer part of the result is kept. So for example, 49/50 = 0.98 = 0.

If you want to carry out floating point division, then at least one of the numbers must be of floating point type. Try the following:
planets.SetZoom(levelList[lvlnum].planetR / 50f);

Oh but wait, some of these antiquated compilers will complain; you may need to write 50.0f instead of 50f.

Cheers,
Cale
Re: sprite zoom problem
April 14, 2010 11:30AM
Hmmm...I'll have to check back to see if that was my problem too...I doubt it but you never know until you check...
Re: sprite zoom problem
April 14, 2010 12:15PM
Quote
calvinss4
Hi there g_man. How long have you been programming in C? According to your Level struct, levelList[lvlnum].planetR is an integer. When you divide an integer by an integer (i.e. levelList[lvlnum].planetR/50), it carries out integer arithmetic, meaning only the integer part of the result is kept. So for example, 49/50 = 0.98 = 0.

If you want to carry out floating point division, then at least one of the numbers must be of floating point type. Try the following:
planets.SetZoom(levelList[lvlnum].planetR / 50f);

Oh but wait, some of these antiquated compilers will complain; you may need to write 50.0f instead of 50f.
Good compilers will still complain about an implicit cast.

I suggest:
planets.SetZoom(float(levelList[lvlnum].planetR) / 50.0f);
Re: sprite zoom problem
April 14, 2010 03:17PM
I've been programming for a good ammount of time, but bugs like that still get to me, so I never would have thought of that. Thank you
Sorry, only registered users may post in this forum.

Click here to login