better solution for jump to sequence by time

MarkusFMarkusF USMember ✭✭

hi,
my goal: a scene with up to 20 "balls", every ball has its own CCSequence with up to 3000 CCMoveTo actions within an array. a clickable timeline to jump forward / backward (like audio play timeline) in the Sequence

first i've a list with time, x and y
List newpos = new List();
newpos.Add(new Positions(1f, 50, 50));
newpos.Add(new Positions(1f, 50, 700));
newpos.Add(new Positions(1f, 1000, 700));
newpos.Add(new Positions(1f, 1000, 50));
newpos.Add(new Positions(1f, 50, 50));
newpos.Add(new Positions(1f, 50, 700));

calculate the time to know how long the sequence run
timeoverall = newpos.Sum(item => item.time);

calculate the pixel to for the timeline within 1sec
barsteps = sreenwith / timeoverall;

move the timeline by time:
Schedule(t =>
{
if(elapsedTime < timeoverall)
{
elapsedTime += t;
string mins = Math.Floor(elapsedTime / 60).ToString("00");
string secs = ((int)elapsedTime % 60).ToString("00");
bar.RunAction(new CCMoveTo(.1f, new CCPoint(elapsedTime * barsteps - bar.BoundingRect.Size.Width, bar.PositionY)));
lbltimer.Text = mins + ":" + secs;
} else
{
}
}, 1f);

timeline touch event:

                if (baroverlay.BoundingBoxTransformedToWorld.ContainsPoint(touchLocation))
                {
                //SET the timeline to the clicked rounded position
                bar.PositionX = (float)(Math.Floor(touches[0].Location.X / barsteps) * barsteps) - bar.BoundingRect.Size.Width;
                //Calculate the the Time of touched position
                var clickedtime = touches[0].Location.X / barsteps;     
                //Get new List with all Items after the clicked time on timeline
                List<Positions> changedlist = jumptotime(clickedtime);

                circle.PositionX = changedlist[0].x;
                circle.PositionY = changedlist[0].y;

                changedlist.RemoveAt(0);

                List<CCMoveTo> actionlist = new List<CCMoveTo>();
                foreach (Positions pos in changedlist)
                {
                    actionlist.Add(new CCMoveTo(pos.time, new CCPoint(pos.x, pos.y)));
                }

                //Assign the new Sequence to the Circle
                CCMoveTo[] actarray = actionlist.ToArray();
                CCSequence seq = new CCSequence(actarray);
                circle.AddAction(seq);
                }




        public List<Positions> jumptotime(float jumptime)
        {
            //Remove all Actions from Circle
            circle.StopAllActions();

            //get the original List with all positions
            List<Positions> templist = new List<Positions>();
            templist.AddRange(newpos);
            float time = 0;
            int indexreached = 0;

            //get all list items after the clicked time
            for (int xx = 0; xx < templist.Count; xx++)
            {
                time += templist[xx].time;
                if(time >= jumptime)
                {
                    elapsedTime = time;
                    indexreached = xx;
                    break;
                }
            }

            //delete items from list
            templist.RemoveRange(0, indexreached);
            return templist;
        }

for sure there is a better solution for my goal...

thanks

Sign In or Register to comment.