Does the play() function in Flash:
move the playhead of the MovieClip to the next frame -- as soon as play() is called
change the MovieClip's state to "playing" -- actually move MovieClip to next frame, when movie moves to next frame
In normal circumstances it would be option 2. However, it is possible to have the frame re-drawn immediately. There is a catch though, you can only do this within mouse move and timer interval handlers. In AS3 have a look at the MouseEvent.updateAfterEvent and the TimerEvent.updateAfterEvent methods. In AS 2 there is a global updateAfterEvent function you can call with the same restrictions.
I think its 2. change the MovieClip's state to "playing"
Related
I use SCNTransaction to move game objects. More specifically, when the player taps somewhere on the screen, the object will move towards that destination. But sometimes the player may make a wrong move, so I want to create a button which can terminate all SCNTransactions.
However, unlike SKAction, which can be terminated with a simple line - self.removeAllActions(), SCNTransaction cannot be terminated or even paused from the outside according to the Apple Developer Documentation. Even worse, I find that before the object reaches its destination, its position has already changed to the destination's position, so I cannot simply use another SCNTransaction to counteract the ongoing one after knowing the object's current position.
Can anybody give me some hints? Thanks a lot.
SCNTransaction and its animation principles follow the one of Core Animation and CATransaction. To stop an animation you will have to set the model value to the current presentation value. For instance:
node.position = node.presentation.position
But if you are familiar with SKAction and would like to implement the same logic in your SceneKit app, you might want to have a look at SCNAction. They work identically.
I'm building an app around gesture recognition.
I've already built my code with recognition of taps, swipes (even with multiples fingers), pinches.
Now I'd like to recognize long press gesture without using UILongPressGestureRecognizer because it enters in conflit with my recognition of other gesture after (I tried).
What I'm currently doing is that I get the time in touchesBegan, in touchesMoved i calculate the time difference, and if it's greater than 400ms (for exemple), i call a function.
The thing is that this function is only called when the finger moved a bit and not when it's perfectly static.
Another option is to set a kind of delay in the touchesBegan and check if the finger is still on the screen after 400ms and then call the function.
How could I do that without blocking the rest of the gesture recognition ?
The aim of this long press would be to do a variation of intensity of a light or something like that (from 0 to 1s, light increase until max is reach, and then lower until minimum etc).
Next, I'll try to recognize a rotation gesture (with only one finger), so if you also have an answer for this, that'd be perfect.
Thanks !
Do not set delay. Start a timer that will fire after 400ms. In touchesEnded invalidate the timer, in case it was called before 400ms. When the timer fires, call the desired function.
As to your second question, probably you will need to calculate the trajectory of the points in touchesMoved method. If somehow the moves resemble rotation (you will need some kind of threshold for that), call the appropriate function.
If you have a child movieclip on stage with an animation in it, can you have the main timeline play the child movieclip at a certain timeline?
mc_child is a 20 frame animation with this.stop() at frame one so that it is paused at the beginning.
If you add the code this.mc_child.play() or this.mc_child.gotoAndPlay(5) you get an error in createJS. "Uncaught TypeError: Cannot read property 'play' of undefined."
How do you make child movieclips play at a certain frame?
You can use gotoAndPlay(5);
Have a look at the EaselJS documentation:
http://www.createjs.com/docs/easeljs/classes/MovieClip.html
So I'm making a simple trivia game and I have a timerView that shrinks as time passes. When the user selects an answer, it needs to stop shrinking immediately - it must be very responsive. I give the user 10 seconds per question. Originally I would animate 10 times (with a duration of 1.0f), calling the next "segment" of animation in the completion block of the previous animation. In the completion block I would check to see if the user has tapped an answer, and if so I don't continue the chain. That solution works fine except that it's not very responsive because it's on a per second basis-- user taps an answer at the start of the second segment and the bar has a noticeable continuation.
My solution to THAT problem was to instead have 1000 animation calls with a duration of 0.01f. After doing that, the responsiveness was on point - the view stops animating as soon as I tap an answer -- the issue though, is that it's not actually 10 seconds, it takes more like 20.
So question number 1: what's the smallest time interval animateWithDuration can actually process properly?
Question number 2: is there a better way to accomplish what I'm trying to do accomplish?
ill answer question two: yes there definitely is a better way, have a look at CADisplayLink
use it to shrink your view a little bit each frame, and end the display link when you need to
the most responsive way is: the user taps an answer, you response in the touch callback, remove animations. you can remove animations by CALayer's removeAllAnimations method
Another way to do it is to set the view to shrinking using a single animation with linear timing, and then set the speed of the view's layer to 0 to pause the animation. When you set the speed on the layer to 0 the animation pauses instantly.
This works because under the covers, UIView animation actually creates and installs CAAnimation objects on the view's layers. It's possible to pause and continue an in-flight UIView animation just like you can a CAAnimation.
I have a project called KeyframeViewAnimations (link) on github that allows you to pause, continue, or "scrub" UIView and CAAnimations back and forth with a slider. You could use that technique. The tricky bit will be figuring out how far along the animation is.
My chart is adding points to its series in certain interval using addPoint(). I've set its animation duration via chart.animation.duration - is there any way of calling my custom callback after animation is completed? I want to make it look more "live". I know about events.redraw(), however this is being fired on the beginning of the animation.
You can also catch redraw function (api.highcharts.com/highstock#chart.events.redraw) and use setTimeout() which will have the same time as animation time.