I'm trying to animate an element by CSS3 transtions using translate3d: JSFiddle.
// for start animation
$("#content")
.css("-webkit-transition", "all 100s");
.css("-webkit-transform", "translate(0, -900px)");
// for stop animation
$("#content")
.css("-webkit-transition", "none");
In desktop Chrome and Safari is good, but in the default browser on Android 4.1.x (SGSII, Galaxy Nexus, etc) this approach does not work - transition does not stop. Additionally, I note that the situation is only a relatively translate3d: with translate and position CSS props (e.g. "top", "left") it works.
The transition implementation on Android 4 seems to be buggy in cases where a transitioning hardware-rendered layer is canceled by adjusting the webkitTransitionDuration to 0 (and setting webkitTransition to 'none' or '' often implies this). This can be circumvented by using a transition duration of .001ms or similar, although this very likely still draws multiple frames.
A more practical work-around on at least certain devices is to use a negative value for the webkitTransitionDelay, forcing a new transition to take effect, but choosing this value such that the transition starts directly in its finished state.
Like so:
e.style.webkitTransition = '-webkit-transform linear 10s';
e.style.webkitTransform = 'translate3d(100px,100px,0)';
# now cancel 10s-long transition in 1s and reset transformation
setTimeout(function() {
e.style.webkitTransitionDelay = '-10s'
e.style.webkitTransform = 'translate3d(0,0,0)';
}, 1000)
Here is what I discovered with some experimentation:
Stopping a running translate2d or 3d on chrome, safari, firefox, and iphone webview can be done by setting a transition of "none" or a transition with a negative or 0 time delay and giving a new translation to the current position as described above.
This however does not work for android webview. The only solution I could find for android was to set the transition delay to a small positive number like .001s and giving a translate for the current position.
Note that in iphone webview the solution of a negative transition delay is preferable to "none" or a small positive number which will flash the final position of the ongoing transition before performing the preempting following transition.
This solves my (very similar) problem:
$el.removeClass('THE_ANIMATION').css('opacity', 0.99);
window.setTimeout(function () {
$el.css('opacity', 1);
}, 0);
Related
Any Android phone has developer options to modify animation speed. Window animation scale, Transition animation scale, and Animator duration scale are the three settings I'm talking about.
The below code snippet ignores your settings:
.delay(200, TimeUnit.MILLISECONDS).subscribe
The code ignores animation settings because "delay" is not inherently tied to animations. In my code's case, it is.
How can I get this code in my app to scale based on the device's developer options animation scale settings?
Do not tie your code to animation using delay in milliseconds.
While this is an easy solution, the animation delay or duration, may differ from the value you set to it. Instead, you can use animation listeners callbacks.
So I found out how to get the system settings for a multiplier...
.delay(getScaledDelayDuration(200), TimeUnit.MILLISECONDS).subscribe
private long getScaledDelayDuration(long delay) {
float multiplier = Settings.System.getFloat(
this.getContext().getContentResolver(),
Settings.System.TRANSITION_ANIMATION_SCALE, 1);
return (long) (multiplier * delay);
}
...but that not only doesn't solve the root issue I'm having, it also is just not a good way to go about this at all. I'm thinking I should just delete the question at this point.
I instantiate the following gameObject, which contains an Animator with the mode "always animate" on, the animation goes for 340ms, after that time I destroy the gameObject.
The gameObject Inspector properties:
I instantiate it using the following code:
instancia = (Instantiate(cardAnimation, new Vector3(0, 0, 0), Quaternion.identity) as GameObject).GetComponent<Image>();
instancia.rectTransform.SetParent(transform);
StartCoroutine(KillOnAnimationEnd());
Here is the Coroutine:
private IEnumerator KillOnAnimationEnd()
{
yield return new WaitForSeconds(0.34f);
DestroyImmediate(instancia);
}
Here is how the animation looks like when simulating in Unity (PC-Windows):
But on android after I open the chest it waits 340ms with nothing happening and then show the information above, does this have something to do with the plataform or is some unity or perhaps code related issue?
NOTE: I also have another animation in another scene that is just a already instantiated gameObject in the Hierarchy with always animated on and it works on Android.
--EDIT--
So I have ran the newest version of the app in a emulator which is almost about 1080x480 and the animation showed just as the PC, also running on a 720p smartphone did the job, the only problem I'm still having is with my QuadHD resolution from Galaxy S6, everything else shows but the animation, I have even tried making the animation run without any script so it runs in a loop, but it doesn't show up in galaxy screen.
Given the news about the issue I think this might change a little bit the perspective of answers and perhaps help someone else solve the same problem in the future.
Okay, figured out the problem, its something to do with "rotation" in animations using Unity3D in 2D mode, gonna be reporting it form Unity so it is fixed.
The solution: Animate your UI only using scale/position, if used rotation it will not show on high resolution display.
I am pretty sure your WaitForSeconds(0.34f) is not working properly because there is no thing such as yield keyword in Java. I recommend you to use a invoke method instead to call your method that destroys your GameObject.
We're using a d3.layout.force on a web app, and I've been investigating a bug report that it is sluggish on Android: it feels like the nodes are in oil, compared to how it works on desktop browsers, or iOS.
(By the way, we only ever have between 4 and 9 nodes, and the sluggishness does not feel different between 4 and 9.)
We set size(), linkDistance() and charge(); so we're using the defaults for friction, theta, alpha, gravity, etc. I experimented with these to try and reproduce the effect on desktop, but couldn't. (friction(0.67), instead of default of 0.9, was closest, but still felt different, somehow.)
I then set up an FPS meter (based on calls to the tick() function). We get 60fps on desktop, and it seems in the 40s and 50s on an ipad. But on Android Chrome (on a Nexus 7) it seems capped at 30fps, and is often half that. Android Firefox was in the 20s normally, but sometimes into the 30s.
So, is it a reasonable hypothesis that are Android devices are just slower? Could there be a cap of 30fps in Android Chrome?
Then how can I fix this? I believe d3.js uses requestAnimationFrame(). Often animation libraries take the time between calls to requestAnimationFrame() to decide how far to move objects (so when the CPU gets overloaded the animation becomes jerkier, but takes the same amount of time to complete). But it appears that d3.js does not do this, and moves everything the same amount by tick, not by elapsed time. What can I do about this?
(Ideally I'd like a solution based on how slow/fast the machine is, rather than having to sniff the browser.)
Curiously, adding more calls to force.tick() in my own requestAnimationFrame() handler (see https://stackoverflow.com/a/26189110/841830), does increase the FPS. That suggests it is not CPU bound, but instead a limit that Android is enforcing (perhaps to save battery?).
Here is the code I'm using, that tries to adapt dynamically to the current fps; it ain't beautiful but seems to be getting the job done in my test android devices, without changing the behaviour in iOS or desktop.
First, where you set up the force layout:
var ticksPerRender = 0;
var animStartTime,animFrameCount;
force.on('start',function start(){
animStartTime = new Date();animFrameCount=0;
});
requestAnimationFrame(function render() {
for(var i = 0;i < ticksPerRender;i++)force.tick();
if(force.alpha() > 0)requestAnimationFrame(render);
});
The above does two things:
sets up the fps counter
sets up our own animation callback, which does nothing by default (ticksPerRender starts off as zero).
Then at the end of your tick handler:
++animFrameCount;
if(animFrameCount>=15){ //Wait for 15, to get an accurate count
var now = new Date();
var fps = (animFrameCount / (now - animStartTime))*1000;
if(fps < 30){
ticksPerRender++;
animStartTime = now;animFrameCount = 0; //Reset the fps counter
}
if(fps > 60 && ticksPerRender >= 1){
ticksPerRender--;
animStartTime = now;animFrameCount = 0; //Reset the fps counter
}
}
This says that if the FPS is low (below 30), do an extra call to tick() on each animation frame. And if it goes high (over 60), remove that extra call.
Each time ticksPerRender is changed, we measure the FPS from scratch.
I'm developing an Android application with a camera-related functionality feature.
First of all, I read a lot of stuff on SO, XDA and so on, then please don't redirect me to other useless posts.
I am trying to implement something like a "fixed focus mode", so that:
I start my application with FOCUS_MODE_AUTO (or something else);
bring into focus an object at an arbitrary distance;
fix the current focus;
move the camera on another object at a different distance which is out of focus.
I tried different solutions, i.e.:
mCamera.cancelAutoFocus() in the AutoFocusCallback to prevent the adjustment of the focus;
set a FocusArea: new Camera.Area(new Rect(-50, -50, 50, 50), 1000) to fix the focus on the current area.
I'm targeting API 20 and I'm working on a Samsung Galaxy S5. On this device, the supported focus modes are:
- auto
- infinity
- macro
- continuous-video
- continuous-picture
The suggestion that I found more frequently is to recompile Android...
"AUTO" mode doesn't mean that the camera continuously focuses - just that when you call the autoFocus command the focus is done automatically with no indication on what result you expect not like "Macro" or "Infinity".
http://developer.android.com/reference/android/hardware/Camera.html#autoFocus(android.hardware.Camera.AutoFocusCallback)
So if you don't have a loop that calls the autoFocus (as many examples do or call it again in the Callback) your focus should stay after it runs once.
If I understand, you want to focus keep the focus of the first object.
Have you tried to change the camera mode to FOCUS_MODE_FIXED after you focus the first object ?
Like that :
Camera.Parameters mParam = mCamera.getParameters();
mParam.setFocusMode(Camera.Parameters.FOCUS_MODE_FIXED);
mCamera.setParameters(mParam);
I have made 2 different animations in Adobe flash professional cs5.5 for an Android aplication.
And I want a code that makes it possible for a user of the app to play the animation as often they want, so if the user wants the animation to play 1 time the first animation will be playes, if the user wants to play it 2 times the animation 1 and 2 will be played, if the user wants the animation 3 times played the animation 1, 2 and 1 will be played and so on.
Can somebody help me with this problem and tell me if this is possible in jquery.
If I was you, the way I would approach this is by having a keyframe after each of the animations where you can type some code.
On the menu page or where ever you have the code for how many times the code should run, define a variable and call it something like "runTimes" which should become the amount of times the animation should run.
At the end of the animations do a simple if statement to check what the value of "runTimes" is and then decrement it. Depending on the value, it should use gotoAndPlay/gotoAndStop.
So, put this on the keyframe after the first animation:
if (runTimes > 0) {
runTimes--;
gotoAndPlay(<FIRST FRAME OF SECOND ANIMATION>);
} else {
gotoAndStop(<FRAME OF MAIN MENU>);
}
and this after the second animation:
if (runTimes > 0) {
runTimes--;
gotoAndPlay(<FIRST FRAME OF FIRST ANIMATION>);
} else {
gotoAndStop(<FRAME OF MAIN MENU>);
}
On the mainmenu frame, let's assume you have a textbox named "numTimes_txt" for the number of times to play and a button "playAnimations_btn" to start the animations.
import flash.events.MouseEvent;
var runTimes:int = 0;
playAnimations_btn.addEventListener(MouseEvent.CLICK, playAnims);
function playAnims(e:MouseEvent):void {
runTimes = parseInt(numTimes_txt.text);
play(); // or gotoAndPlay(<FIRST FRAME OF FIRST ANIMATION>);
}
I haven't tested this as I don't have my IDE on me right now, but this should work if I understand the question properly.