animation.start() or animation.startNow() does not start the animation immediately - android

I have a strange issue - from time to time the animation that should fade out my control (ImageButton) does not kick in immediately. I am using the fadeout animation to hide it and then in myListener on its end (onAnimationEnd) I put new resource as the image on the button.
Somewhere in my app code:
Animation a = AnimationUtils.loadAnimation(this,R.anim.fadeout);
a.setAnimationListener(new myListener(location));
buttons[location].setAnimation(a);
a.startNow(); // regardless if its start() or startnNow()
// it will work in most of the cases but not 100% reliable
// I actually can see in debug Log when its late, happens after few more clicks
Then in myListener.onAnimationEnd(Animation a):
buttons[location].setImageResource(R.drawable.standard_button);
Seems there is a rule that the every 4th or 5th animation does not start ...
Thanks for help!

adding
buttons[location].invalidate();
after
a.startNow();
has fixed my issue.

You can also use
buttons[location].startAnimation(a);

Related

CORONA SDK: Create a back to main button stopping the already started scenes.

im developing an APP in corona SDK, it's a serie of tests, so i made every test separately and then i created a main Scene that contains this tests. To handle any click error or misunderstanding i created a "back to intro" button, the problem is, when i start a test (for example test2) i'm in the middle of the test and i use the back to intro button (that takes me to intro, there's no prob with that) the Test2 keeps going and when i try to re-take the test shows an error related to this. I've trying different ways but i can't make it work, here is the code of the button:
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
storyboard.showOverlay( "cerrar sesion", options )
end
end
local button1 = widget.newButton
{
width = 60,
height = 60,
defaultFile = "images/boton_config.png",
overFile = "images/boton_config.png",
label = "",
onEvent = handleButtonEvent
}
-- Center the button
button1.x = display.contentCenterX+550
button1.y = 35
button1.isVisible=true;
storyboard.gotoScene("test0intro")
Plz help :<
I think I may have had this problem. I would advise switching to composer rather than storyboard a lot of these issues are easier to find. I am unsure about storyboard but for composer I know that I had to remove all event listeners, remove the sceneGroup, stop the physics and then remove the scene in the scene:hide method. I'm unsure of what the equivalent of this is in storyboard. Otherwise when I went to restart to the game (as you seem to be doing), the game would crash. Hope that helps!

How to remove sprite after the completion on Animation?

I am using the CCAnimation class for using animation with more than one CCSprite . What I want is :
" Just Remove the sprite after the animation complete "
If anybody work on this, Please Let me Know. What should I do for it.
I know the solution of pktangyue works but I want to add a new answer because this is deprecated in cocos2d-x V3.x Please read the final way to do this it's more easy
Node *nodeSprite =(Node*)layer->getChildByName("BFL_Ready_Label");
MoveTo* animation = MoveTo::create(1.0f,Point(Director::getInstance()->getWinSize().width/2,Director::getInstance()->getWinSize().height*1.5));
CallFunc* animationDone = CallFunc::create(bind(&Node::removeFromParent,nodeSprite));
Sequence* sequence = Sequence::create(animation,animation,NULL);
node->runAction(Sequence);
And like the previous answer using a Sprite.
MoveTo* animation = MoveTo::create(1.0f,Point(Director::getInstance()->getWinSize().width/2,Director::getInstance()->getWinSize().height*1.5));
CallFunc::create(bind(&Sprite::removeFromParent,m_sprite));
Sequence* sequence = Sequence::create(animation,animation,NULL);
m_sprite->runAction(sequence);
Using this the compiler will not tell that you're using deprecated methods. I hope this will useful.
I update this answer because there's a much easy way to do this
when you create a sequence just add the RemoveSelf::create RemoveSelf it's an action so you can add it to the sequence it will destroy the sprite or Node after the animation is complete.
Sequence* sequence = Sequence::create(animation,animation,RemoveSelf::Create(),NULL);
And that's the easy way to destroy the object after
the animation is completed this is very usefull in particles
Suppose m_action is your animation and m_sprite is you sprite node.
Then you can create a CCSequence action, with a CCCallFunc action in the final, like the following code:
CCSequence* seq = CCSequence::create(action,
CCCallFunc::create(m_sprite, callfunc_selector(CCSprite::removeFromParent),
NULL);
m_sprite->runAction(seq);
sprite_name->runAction(Sequence::create(ScaleTo::create(1, 0),RemoveSelf::create(), NULL));

Robotium waitForView to disappear?

I'm using robotium 3.1 and I'd like to wait for a view to disappear, is there some way I can do that easily? My current way involves a ugly busy-loop with sleeps that makes no one happy.
To clarify what I'd like to happen:
waitForView(<View>) //The view appears
//The view is visible for a few seconds
waitForViewNotThere(<View>) //waits until the view has disappeared
The view that appears doesn't contain any text or such either. Any input is very much appreciated.
This is how:
final TextView helloWorldText = solo.getText("Hello world!");
solo.waitForCondition(new Condition() {
#Override
public boolean isSatisfied() {
return helloWorldText.getVisibility() == View.INVISIBLE;
}
}, 10000);
Whatever you do you are probably going to have some sort of sleep in the loop. (If you look at robotiums source it also uses sleeps). You can keep them to a minimum by using the waitforidlesync method on instrumentation that waits for the Ui thread to become idle.
if you want to wait for a view to disappear, use solo.waitForDialogToClose(long timeout).
Parameters :
timeout - the amount of time in milliseconds to wait.
returns : true if the Dialog is closed before the timeout and false if it is not closed.

Sencha Touch 2: switch between two panels with a "fade" animation?

I'm wondering what is the best way to swap out two panels on the screen with a fade effect?
I have two panels which I have positioned over top of each other using CSS. panelOne is visible, panelTwo is hidden.
On click of another button (not on either panel), I want panelOne to fade out and panelTwo to fade in.
I currently have this working using the code below, but I find it's quite laggy on some Android devices we have here for testing. Is there a better way to do it than what I'm currently using? How can I improve this animation?
This code is executed on button tap:
Ext.Anim.run(panelOne, 'fade', {
duration: 100,
after: function() {
panelOne.hide();
}
});
Ext.Anim.run(panelTwo, 'fade', {
out: false,
duration: 100,
before: function() {
panelTwo.show();
}
});
Any help is much appreciated.
Thanks.
It's not necessary to use Ext.Anim such long.
For example, your app has an Ext.Container which contains panelOne and panelTwo as the first and second item, respectively.
Then if you want to navigate from panelOne to panelTwo with a fade animation, just simply use:
Ext.getCmp('your_container_id').animateActiveItem(1,'fade')
or you can do this:
Add showAnimation: 'fadeIn' to your panelTwo's config
Add hideAnimation: 'fadeOut' to your panelOne's config
Hope it helps.
to control other config, such as duration, use:
hideAnimation: {type:'fadeOut', duration: 1000}

Android, How to use animation in order to show blinking?

In my application, I have recording button. I want when user clicks on it each one second i change the background in order to simulate blinking. I created a handler and set it to 1 second therefore each one second this handler runs. Here i change the background. this my code:
mUpdateUITimerTask = new Runnable() {
public void run() {
// Simulating blinking for capture button
if(bolToggle) {
bolToggle = false;
captureButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_record_blink));
} else {
bolToggle = true;
captureButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.btn_record));
}
mHandler.postDelayed(mUpdateUITimerTask, 1000);
}
};
When I run the app i see the changes but its not clear. buttons are like this:
When i run the application, red image is showing ok but for white image, it shows red image with a little white halo around it.
I tried to put captureButton.setBackgroundColor(Color.TRANSPARENT); before setting background but result was same.
any suggestion would be appreciated. Thank you.
Found the answer you need: https://stackoverflow.com/a/4852468/1352556
Basically you want an alpha animation. I believe this will make the entire button flash however, do you only want the red dot flashing?

Categories

Resources