Page 1 of 1

New SpriteLoader Class, but did I need to?

Posted: July 9th, 2012, 3:47 pm
by Asimov
Hi Chilli,

My animated sprite routine worked, but I was worried. You see it did the delay between frames by using Time=Time+1; As you know a commnd like this on a machine twice as fast as my computer would run that command faster. So I had a go at updating my animated sprite function.

I just found a command which is in time.h called clock(); It seems to count the milliseconds passed since the program has started. Anyway now I have updated it. I can actually time my sprite animation in milliseconds.

This is my old routine

Code: Select all

bool SpriteLoader::Sprite(double x,double y, int Frametime,D3DGraphics* gfx)
{
		DrawSprite(x,y,gfx);
		
		if (Time==Frametime) {
			Frame=Frame+1;
			Time=0;
		} 

		if (Frame==NumberOfFrames) {
			Frame=0;
			return false;
		} // This starts the animation again
		Time=Time+1;
		return true;
}
And now this is my new sprite routein

Code: Select all

bool SpriteLoader::Sprite(double x,double y, float Frametime,D3DGraphics* gfx)
{
		DrawSprite(x,y,gfx);

		if (Time==0)
		{
			endtime= clock()+Frametime;
			Time=1;
		}
		
		if (clock()>=endtime) {
			Frame=Frame+1;
			Time=0;
		} 

		if (Frame==NumberOfFrames) {
			Frame=0;
			return false;
		} // This starts the animation again
		return true;
}
It seems to work ok, but could I have done this a better way.
Also in my Missile routine. I have a velocity, but I am also thinking this might compute faster on a faster computer. So do you think I should do something like velocity * time; I think I had to do something like this in XNA.

Asimov

Re: New SpriteLoader Class, but did I need to?

Posted: July 11th, 2012, 11:16 am
by chili
Asimov wrote: Also in my Missile routine. I have a velocity, but I am also thinking this might compute faster on a faster computer. So do you think I should do something like velocity * time; I think I had to do something like this in XNA.

Asimov
You don't need to this, but it wouldn't hurt. The difference in speed between computers will usually not be because of processing speed, but because of the refresh rate of the monitor.

Re: New SpriteLoader Class, but did I need to?

Posted: July 11th, 2012, 4:17 pm
by Asimov
Hi Chilli,

Do you think the way I did this was the best way, or is there a better way.
I found the Clock() command after much googling LOL.

I think Lux once said that using the frames to do the speed wasn't the best way.
What is the alternative? and is it easy to implement?

I must watch the rest of the classes tutorial, but I have been a little tired the last couple of days. Back at work after a 2 week holiday.

Been looking at your endframe code. I see the loop there, and that must be what sends the buffer to the screen. Not sure which parts syncs it will the monitor refresh though. Might play with for some fun LOL.

Asimov

Re: New SpriteLoader Class, but did I need to?

Posted: July 11th, 2012, 4:41 pm
by LuX
The refresh rate is initialized at D3DGraphics as "d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;" There are a couple of alternatives like _TWO to _FOUR but I can't remember their differences.

Re: New SpriteLoader Class, but did I need to?

Posted: July 12th, 2012, 7:54 pm
by Asimov
Hi Lux,

Thanks I will look into that.

Asimov