New SpriteLoader Class, but did I need to?

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

New SpriteLoader Class, but did I need to?

Post by Asimov » July 9th, 2012, 3:47 pm

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
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

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

Post by chili » July 11th, 2012, 11:16 am

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.
Chili

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

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

Post by Asimov » July 11th, 2012, 4:17 pm

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
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

User avatar
LuX
Posts: 1492
Joined: April 22nd, 2012, 12:33 pm
Location: Finland

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

Post by LuX » July 11th, 2012, 4:41 pm

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.
ʕ •ᴥ•ʔ

User avatar
Asimov
Posts: 814
Joined: May 19th, 2012, 11:38 pm

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

Post by Asimov » July 12th, 2012, 7:54 pm

Hi Lux,

Thanks I will look into that.

Asimov
----> Asimov
"You know no matter how much I think I have learnt. I always end up hitting brick walls"
http://www.asimoventerprises.co.uk

Post Reply