Reply
29 Jun 2012
Member
Playstation Staff

[Help] programming

4 Replies 219 Views Created 29-06-2012

How I can change the scene after X seconds?, 

Please use plain text.
Reply
0 Kudos
Message 1 of 5 (219 Views)
Reply
0 Kudos
Level 6
 
Playstation Staff

Re: [Help] programming

Use a timer, and on the Update loop check to see if its gone past your desired threshold.

Please use plain text.
Reply
0 Kudos
Message 2 of 5 (218 Views)
Reply
0 Kudos
Level 2
 
Playstation Staff

Re: [Help] programming

Ill post mine for you:

 

Look through it and read what its doing so you understand it:

 

Basic use is:

 

Nereid.Timer.Start(60); // Update at 60fps

 

and in your update:

 

if( Nereid.Timer.Update() )
{

     // Update your game logic

}

 

using System;

using System.Diagnostics;

namespace Nereid
{
	public class Timer
	{
		// Statically initialised singleton instance
		private static readonly Timer _instance = new Timer();
		
		const float k_iFPSCap = 1.0f / 30.0f;
		
		private long m_previousTime;
		private long m_elapsedTime;
		private float m_deltaTime;
		
		private long m_TargetFPS;
		private long m_TargetFPSMilliseconds;
		private Stopwatch m_stopWatch;
		
		private Timer ()
		{
			m_previousTime = 0; 
			m_elapsedTime = 0;
			m_deltaTime = 0.0f;
			m_TargetFPS = 60;
			m_TargetFPSMilliseconds = 1000 / m_TargetFPS;
			m_stopWatch = new Stopwatch();
		}
		
		/// <summary>
		/// Updates the timer. If target FPS has passed returns true
		/// </summary>
		public static bool Update()
		{
			long currentTime = _instance.m_stopWatch.ElapsedMilliseconds;
			_instance.m_elapsedTime += currentTime - _instance.m_previousTime;	
			_instance.m_previousTime = _instance.m_stopWatch.ElapsedMilliseconds;
			
			if( _instance.m_elapsedTime > _instance.m_TargetFPSMilliseconds )
			{
				_instance.m_deltaTime = (float)_instance.m_elapsedTime / 1000.0f;
				_instance.m_elapsedTime = 0;
				
				// Clamp any huge time elapses
				if( _instance.m_deltaTime > k_iFPSCap )
					_instance.m_deltaTime = k_iFPSCap;
				
				return true;
			}
			else
				return false;
		}
		
		#region Properties
		public static float DeltaTime { get{ return _instance.m_deltaTime; } }
		
		public static long TargetFPS 
		{ 
			get 
			{ 
				return _instance.m_TargetFPS; 
			} 
			set 
			{ 
				_instance.m_TargetFPS = value; 
				_instance.m_TargetFPSMilliseconds = 1000 / _instance.m_TargetFPS; 
			} 
		}
		#endregion
		
		public static void Start( long fps ) { TargetFPS = fps; _instance.m_previousTime = 0; _instance.m_stopWatch.Start(); }
		public static void Stop() { _instance.m_stopWatch.Stop(); }
	}
}

 

Please use plain text.
Reply
Message 3 of 5 (214 Views)
Reply
Level 7
 
Playstation Staff

Re: [Help] programming

Hi,

 

The tutorials are a good place to start. Additionally many of the samples use timers.

 

 

PlayStation®Mobile Dev Team
I am like you, I have no name.
Please use plain text.
Reply
Message 4 of 5 (206 Views)
Reply
Level 1
 
Playstation Staff

Re: [Help] programming

thanks for the replys

Please use plain text.
Reply
0 Kudos
Message 5 of 5 (182 Views)
Reply
0 Kudos