Timed events writer


(Mike Evmm) #1

I’m sorry for the vague title, but it was the best I could come with, which is also why I can’t google this.
I want to make a music synced game, but it would be a pain to hard-code all the timing in it. I know I could use alarms, but is there any software/file format that’d make timing setting/tuning easier?
I realise this isn’t strictly an FP question, so sorry abut that too.
Thanks in advance.


(Martí Angelats i Ribera) #2

There is a class called Timer wich does exactly that.


(Mike Evmm) #3

I know; what I’m looking for is something like OGMO but that would allow me to set timed events and tweak them more easily.
I.e. use software to set flags -> export file with timing data -> use FP to parse file into timers
I thought of using a MIDI writer and then parsing the exported file, but it doesnt seem to be a very well handled file format by most languages.


(Martí Angelats i Ribera) #4

Oh, now i understand. I don’t think there is any editor. Well we’ll have to create a simple one ;).

BTW, I have this fucntion that callsback to the function you want after the specified time. It may help.

package  
{
	import net.flashpunk.FP;
	import net.flashpunk.Tweener;
	/**
	 * ...
	 * @author Copying
	 */
	public class MultiTimer extends Tweener
	{
		
		
		public function MultiTimer() 
		{
			_callbacks = new Vector.<Time>;
		}
		
		override public function update():void
		{
			var t:Time;
			for each (t in _callbacks)
			{
				t.timer -= FP.elapsed;
				if (t.timer <= 0)
				{
					t.callback.call();
					deleteCallback(t);
				}
			}
		}
		
		public function addCallback(time:Number, callback:Function):Time
		{
			var t:Time;
			t.time = time;
			t.callback = callback;
			
			var x:int = 0;
			while (true)
			{
				if (!_callbacks[x])
				{
					_callbacks[x] = t;
				}
				else x++;
			}
			
			return t;
		}
		
		public function deleteCallback(t:Time):void
		{
			var x:int = _callbacks.indexOf(t);
			if (x >= 0)
			{
				_callbacks[x] = null;
			}
		}
		
		private var _callbacks:Vector.<Time>;
	}

}
package  
{
	public class Time 
	{
		public var callback:Function;
		public var time:Number;
	}

}

(Mike Evmm) #5

Hey, thanks, that’ll definitely come in handy when parsing, but it’s not quite what I was looking for, I might go with MIDI reading after all.


(Martí Angelats i Ribera) #6

I’m glad it will be usefull to you.

If you tell me your exact case i can try to find a better solution (I’m thinking about create a simple editor that saves the information into an XML).


(Ben Pettengill) #7

Not sure if this would be helpful, but if you’re trying to sync something with music, Audacity has something called Label Tracks that let you attach plain text labels to any point in time. They can be exported as text files that are easy to read. It might be simpler to work with than MIDI (I was thinking about using something like this to do the timing in cutscenes, but I never got around to it).


(Mike Evmm) #8

This seems exactly what I was looking for. Thank you!


(Martí Angelats i Ribera) #9

WOW, didn’t know it ether! Good to know.