deactivating/activating a UGUI button leaves it in pressed state - unity3d

I have a button with "animation" transition type. When I click it, I call SetActive(false) on its gameObject. Then, by clicking another button, I call SetActive(true) to activate the deactivated button, but the animation does not reset: it's still in pressed state (like it was when I deactivated it, because I was pressing it), and it does not back to idle state.
EDIT: I realized I have not set the sprite for "normal" state in the animation. But I don't understand why before deactivate/activate, the button is showing default sprite for idle state, and after deactivate/activate, is showing pressed sprite for idle state.

Related

Get notification when user pauses dragging

is there a way to get notified when user stops dragging over the screen (using GestureDetector) when the finger is still on the screen? After lifting the finger I do get DragEndDetails event. What I need is sort of "user paused scrolling". Current behaviour is: while moving the finger I do get DragUpdateDetails but when I stop dragging (finger on the screen, drag velocity is 0) neither DragUpdateDetails nor DragEndDetails are fired.
Cheers.
You could just setup a timer (e.g. 1 second) when you receive a drag update event.
If no drag update occurs during that time (or only minimal drag occurs), trigger your callback. Otherwise, if there is significant movement, restart the timer...
When the drag is cancelled or the finger is removed or the widget is disposed, cancel the timer.

Difference between pausing and resetting a game Spritekit / Swift?

Right now I've got it where if I click on the pause button I've made, it goes to my pause menu. When I go back to the game screen via the button I made to do that, the game has reset itself to the beginning.
I've got a "go back to the game button" and a reset the game button.
How do I get those two to act correctly?
I don't even really know where to begin with this because I don't know if the game is clearing when I'm initially leaving the screen or when I'm going back to it. I thought I had read the default behavior was to save the state of a screen when you navigated off of it.
When you change your game view controller (gameVC) to your menu view controller (menuVC), if there isn't any reference remaining everything gets deallocated. Therefore, when you go back to your gameVC you're allocating new objects (scene, nodes, ...).
What you might be looking for, to pause your game, is the paused property.
On your SKScene (which is a SKNode) : https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKNode_Ref/index.html#//apple_ref/occ/instp/SKNode/paused
paused
A Boolean value that determines whether actions on the node and its descendants are processed.
If the value is YES, the node (and all of its descendants) are skipped when a scene processes actions.
On you SKView : https://developer.apple.com/library/prerelease/mac/documentation/SpriteKit/Reference/SKView/index.html#//apple_ref/occ/instp/SKView/paused
paused
A Boolean value that indicates whether the view’s scene animations are paused.
If the value is YES, the scene’s content is fixed onscreen. No actions are executed and no physics simulation is performed.
The update: method won't be called if the SKView is paused.

ccTouchesMoved and selector:#selector(ButtonTapped:)

Ill try and keep this as simple as possible.
I have a guy which you drag around the screen
I have a shoot button which fires bullets
To drag the guy around the screen im using ccTouchesMoved, basically get the users finger movement and set the guy to that place. Done.
I have a button which is a CCMenuItemImage and if it is tapped then is called a selector to run a method. The method simply fires some bullets. Done.
Now my problem is i cant have these two things work at the same time. I would like the player to be able to drag around the guy and shoot at the same time. Im assuming the button is not being tapped becuase the user is touching and dragging around the player.
How can i fix this? Still be able to drag around with one finger and press the shoot button with the other and they both work together?
You might want to implement your fire button using a sprite. You can handle ccTouchesBegan and ccTouchesEnded to check for a press within the bounds of your button, to swap it with a pressed state (on begin) or to implement the fire action (on end).
In your ccTouchesMoved handler, you can iterate over the set of touches and determine if the touch that moved is the one over the button, or the touch that should change the character position.

iphone - forcing button to acknowledge touch programmatically

When you touch a UIButton it hides for a fraction of second and then it executes its action. This fast "blink" is the feedback the user needs to know that the button has been clicked.
In the project I am doing, I need to select the button programmatically, as if the user had clicked it. In other words, the same behavior has the button had been clicked by the user... a fast blink and execution of its action.
Is this possible to do?
thanks for any help.
The change in the appearance of the button is effected by setting the button's highlighted property. The property is automatically set to YES when the user touches down on the button, and back to NO when she releases.
The highlighted property is writable, so you can set it YES yourself to simulate a touch down. You'll probably want to use +[NSTimer scheduledTimerWithTimeInterval:invocation:repeats:] to set it back to NO after a short interval.
It is pretty simple, and probably there is a better solution.
First, use images to your button, and when you have to fire the button, you just change the button's image in the normal state to the pressed image, and after that, replace it back to the original. You can simply do it with a timer.

UIButton subclass continuously highlighted after an popping up and UIAlertView

I am subclassing a UIButton and detecting finger movements, if the user swipes his finger in a certain way I will pop up an UIAlerView.
All good, except that after dismissing the UIAlertView... when the user next touches the UIButton the button goes to it's highlighted state and gets stuck there, continuously highlighted, even when no finger touching it.
Pressing the button again the UIButton begins to behave normally (only highlights when touched).
So I can only presume that an alert during a swipe, screws up the process of events, the touchesEnded never firing perhaps?
If anyone has any ideas on how to 'reset' the button after the swipe so that it behaves as it should, I would be grateful.
Are you resetting your state in touchesCancelled?