if anybody can help me

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
moekkog
Posts: 44
Joined: Tue Feb 24, 2009 6:02 am

if anybody can help me

Post by moekkog »

I have this code

Code: Select all

	/*icon2=0;
	alpha =0;
	while(device->run() && driver &&(icon2<750))
	{
		driver->setTextureCreationFlag(video::ETCF_OPTIMIZED_FOR_QUALITY, true);
		driver->beginScene(true, true, video::SColor(100,0,0,0));
		icon2++;
		if(icon2<254)alpha++;
		if(icon2>500) alpha--;
		driver->draw2DImage(images1, core::position2d<s32>(0,0),
				core::rect<s32>(0,0,1200,800), 0,
				video::SColor(alpha,255,255,255), true);
		driver->endScene();
	}*/
but it is based on the computer velocity if i run it in my computer it runs normal if a put the same code in a older computer it runs slow i just want to know if anybody can help me to convert this code in other one that make reference to time or something to make it run at the same velocity in every computer not just in mine
Last edited by moekkog on Mon Apr 20, 2009 1:31 am, edited 1 time in total.
grumpymonkey
Posts: 222
Joined: Mon Jan 19, 2009 10:03 pm
Location: Miami, Florida
Contact:

Post by grumpymonkey »

that change in speed is called "lagg". and the only way to prevent it is to buy a new computer...or produce console games so that all you're customers have the same type of machine
Image
moekkog
Posts: 44
Joined: Tue Feb 24, 2009 6:02 am

i dont want to prevent it

Post by moekkog »

i dont want to prevent it, i want to chage my code to get a counter of the local time of the computer and each 5 tic the counter raise or something to make the code dependand of the time or something else not the capabilities of the computer
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

I think that you are looking for something like this

Code: Select all

float last_time;
float UpdateTime () 
{
	cur_time = m_Device->getTimer()->getRealTime ();
	delta = (float)((float)(cur_time - last_time) / 1000.0);
	last_time = cur_time;
	return delta;
}

float elapsedTime = UpdateTime()
float alpha =0; 
bool increasing = true;

// we are going from 0 to 254 and back to 0 (500?) in how many seconds?
float SPEED = 10 seconds / 500;
 
driver->setTextureCreationFlag(video::ETCF_OPTIMIZED_FOR_QUALITY, true); 
    
   while(device->run() && driver) 
   { 
      float elapsedTime = UpdateTime()
      driver->beginScene(true, true, video::SColor(100,0,0,0)); 
      
      if (increasing) 
      {
         alpha += elapsedTime*SPEED;
         if (alpha>254) increasing = false; 
      }
      else
      {
         if(alpha>0) alpha -= elapsedTime * SPEED; 
       }

      driver->draw2DImage(images1, core::position2d<s32>(0,0), 
            core::rect<s32>(0,0,1200,800), 0, 
            video::SColor(alpha,255,255,255), true); 

      driver->endScene(); 
   }
for a better understanding, try reading this

http://irrlicht.sourceforge.net/phpBB2/ ... 605#164605


.
.
.
.
.
Last edited by Seven on Mon Apr 20, 2009 2:16 am, edited 4 times in total.
moekkog
Posts: 44
Joined: Tue Feb 24, 2009 6:02 am

yes something like that

Post by moekkog »

but the problem is the numbers of loops is based on a counter that is no dependance of the time, a is the same problem in some computers and in some it ends to quicly in others to late i have tried this code

Code: Select all

	alpha =0;
	u32 time = -1;
	const f32 MOVEMENT_SPEED = 1.f;
	u32 then = device->getTimer()->getTime();
	time = device->getTimer()->getTime();
	u32 start = device->getTimer()->getTime();
	while(device->run() && icon2<170)
	{
		driver->setTextureCreationFlag(video::ETCF_OPTIMIZED_FOR_QUALITY, true);
		driver->beginScene(true, true, video::SColor(100,0,0,0));
		time = device->getTimer()->getTime();
		const u32 now = device->getTimer()->getTime();
		const f32 frameDeltaTime = (f32)(now - then) / 10.f; // Time in seconds
		then = now;
		icon2 += MOVEMENT_SPEED * frameDeltaTime;;
		//if(icon2>1000)increasing =1;
		if(icon2>100)increasing =2;
		if(increasing == 0 &&alpha<255)alpha++;
		if(increasing == 2 &&alpha>1) alpha--;
		driver->draw2DImage(image, core::position2d<s32>(0,0),
				core::rect<s32>(0,0,1200,800), 0,
				video::SColor(alpha,255,255,255), true);
		driver->endScene();
	}
but the time is not constant i dont know why and in some time the splascreen comes out but it take too long to desapear in others it simpli does not appera and i dont know why
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

my posting above is modified.
moekkog
Posts: 44
Joined: Tue Feb 24, 2009 6:02 am

thanks

Post by moekkog »

thanks a lot that what i was looking for i did so little modification but i used as a base code
Post Reply