C# Guitar Hero Clone, Note Animation Timing -
i creating guitar hero clone using c# , having trouble syncing animations , sound.
a rundown of now:
- a read file , note highway, note time , not length (this done correctly)
- the notes put array
- before song starts, generate storyboard, read in entire array of notes, , create doubleanimations make rectangle objects (notes) scroll down screen.
- i set begintime on animation 1 second before expected play time (the duration spent approaching end) , , animation duration 1 second. however, expect happen (the notes playing in sync) inst happening.
here code creating animation:
private void startnote(midinoteevent evnt) { const double length = 0; int[] highwayarray = evnt.highway; (int = 1; <= highwayarray.length; i++ ) { var highway = highwayarray[i-1]; if (highway > 0) { string name = evnt.time.tostring() + "|" + highway.tostring(); var rect = new rectangle {tag=name, height = length+5, width = 50 }; canvas.settop(rect,-6); int offset; if (i == 1) { offset = 20; rect.fill = new solidcolorbrush(colors.green); } else if (i == 2) { offset = 120; rect.fill = new solidcolorbrush(colors.red); } else if (i == 3) { offset = 220; rect.fill = new solidcolorbrush(colors.yellow); } else if (i == 4) { offset = 320; rect.fill = new solidcolorbrush(colors.blue); } else { offset = 420; rect.fill = new solidcolorbrush(colors.orange); } rect.margin = new thickness(offset, 0, 0, 0); guitarcanvas.children.add(rect); var duration = new duration(timespan.fromseconds(1)); var mydoubleanimation2 = new doubleanimation {duration = duration, begintime = timespan.fromseconds(evnt.time-1)}; _notes.children.add(mydoubleanimation2); storyboard.settarget(mydoubleanimation2, rect); // set attached properties of canvas.left , canvas.top // target properties of 2 respective doubleanimations storyboard.settargetproperty(mydoubleanimation2, new propertypath("(canvas.top)")); mydoubleanimation2.to = guitarcanvas.height; mydoubleanimation2.completed += new eventhandler(mydoubleanimation2_completed); // begin animation. //sb.begin(); } } }
i not sure of how fix problem, misunderstanding how animation works? using wrong units? or else entirely? tips appreciated, if complete rewrite of how display notes.
how playing sound? did similar video. started video in same storyboard put other animations they'd on same timer. had storyboard mediatimeline , added other animations same storyboard.
worked great. make sure set slipbehavior "slip" on storyboard.
in actions button click, had:
<beginstoryboard name="playvideosb"> <storyboard slipbehavior="slip" completed="storyboard_completed" fillbehavior="stop"> <mediatimeline source="{binding filename}" storyboard.targetname="video" name="mediatime"/> </storyboard> </beginstoryboard>
i added storyboard in code something this:
booleananimationusingkeyframes bukf = new booleananimationusingkeyframes(); storyboard.settargetproperty(bukf, new propertypath(propertyfoo)); storyboard.settarget(bukf, myobject); bukf.keyframes.add(new discretebooleankeyframe(true, keytime.fromtimespan(start))); bukf.keyframes.add(new discretebooleankeyframe(false, keytime.fromtimespan(end))); playvideosb.storyboard.children.add(bukf);
i happened using boolean animations, should work doubles.
Comments
Post a Comment