In my app I have a stickman, which moves to right when you click a button. Within that time (moving to the right) I want to animate 6 pictures, where you see the stickman running. The purpose of clicking that button is to do it as fast as possible, and I want to let the stickman finish running even when the user clicks the button again. It's a kind of a race to get at the finish as fast as possible. My purpose is to make the running of the stickman look natural, so the running doesn't start again when the stickman is not yet ready with his steps.
Is there anyway to do this??
Thanks in advance,
Joe
That should be very straight forward, just define a (global) variable or a class property that like status that you can set it to running or stopped and when the button is clicked check if (status!=running)
Does this solve your problem?
If you show us some code and point out the exact problem people could better help.
Try this...
say have an
UIImageView *imView1;
NSTimer *timer1;
count = 1;
say images have name as
img1,img2,...,img6 - PNGs.
inside the timer method:
{
count++;
[imView1 setImage:[UIImage imageNamed:[NSString stringWithFormat:#"img%d.png",count]]];
if(count==6) count = 0;
}
If you want to increase or decrease the speed, you can change the time interval. The loop will not break.
Related
I'm currently writing an iOS application for the iPhone with one particular feature that creates a flowchart on the fly. The flowchart that is created is one enormous, scrollable view. Each information node of the flowchart contains buttons that automatically moves the view to the next information node. At any point in time, a user can use a pinch gesture to zoom out of the current information node and see the flowchart in its entirety.
My problem is this: I notice that if a user begins this pinch motion with one of their fingers tapping one of the buttons in an information node then this gesture takes precedence and the next node is shown as opposed the pinch gesture zooming out from the current node.
I've been looking on StackOverflow and have tried several things to fix this, but nothing yet has seemed to work. I was wondering if anyone has had similar issues and if they were able to overcome the issue?
Using #Till's advice and looking into my issue a bit more, I've done something that's worked for me and I thought I would share it here in case anyone else had similar issues or desires.
I was able to create UIViews that I could use to act as semi-buttons. For each of these views, I greated UITapGestureRecognizers and targeted them towards methods that would check to see if the sender's state is StateEnded:
-(void)handleButtonTap:(UITapGestureRecognizer *)sender
{
if(sender.state == UIGestureRecognizerStateEnded)
// Go on and do the code here
}
However, wanting to still maintain the look of the original iOS Buttons I did one step further. For each UIButton that I created, I did not associate a target with these buttons and instead created UIViews for each button. These UIViews were completely blank with a background color of "Clear." In this manner, I can now have my buttons, but still get the functionality I desired.
I hope this helps anyone else with similar issues. Thanks again to #Till for the advice.
I have a series of UIButtons from 0 to N with a background image which is a color. I want to take a sequence of numbers from 0 to N, run through it and flash the corresponding button for each number sequentially. I have thought of changing the background to white and using sleep, but I haven't been able to get it to work. The buttons must flash sequentially with equal time spacing between the flashes. Pseudocode is:
for(i in sequence){
[[buttons objectAtIndex:i] flash];
//The flash must complete before the next button flashes.
}
Is there anyway to simulate the same animation as a button press, because that would be perfect? Basically I'm doing these flashes to show the user the sequence in which to press the buttons, is there a more elegante way to do this? Should I use some custom view instead of UIButton (I need it to be clickable, but I could program that instead of using a button)?
NSTimer is your friend. Check up on the documentation for it. You could have it fire at a set interval and just increment the count each time it fires.
For animation look at the animation methods provided for in UIView's documentation. Should have everything you need.
DO NOT USE sleep under any circumstances. This will make everything completely non responsive while its sleeping. There are all sorts of other more useful methods that allow for delays.
Making a simple card game, and it it should ok when the user is in control since he will push a button. It will call my method assigned to that button and logic will be performed and screen updated.
But when the players turn ends, and i want the AI to run everything for a few seconds, update the screen with its decisions etc. Handle some logic, call some animation before handing the control back to the user.
Is there a method i can override in my Controller class that which is a subclass of NSObject that gets called every loop or at least 5-10times a second? Or how is it you guys handle this?
Thanks
-Code
It doesn't seem like you want a background thread at all (at least not one you make) or a timer.
What you really want to to is visually animate the AI actions, to that end look at the CoreAnimation stuff, to define animations for AI actions and then play them. You can specify a time period an animation is to take.
Look at this project for examples of animation from the simple to the complex:
http://github.com/neror/CA360
Just create a an NSTimer that calls a tick method at whatever frequency you desire. But keep in mind that NSTimer is not guaranteed to be precise, so in order to avoid gradually accumulating errors, you might want to check how much time has actually passed (e.g. if the timer fires an average of 10 ms late over 500 ticks, code that depends on precise timing will be five seconds off).
I have a 3 component dependent picker and I had it working fine until I noticed a strange behavior. If I spin component 1 and then click down with mounse on Conmponent 2, then wait for Component 1 to stop spinning then let the mouse button up, all without moving the mouse or picker wheel at all... didSelectRow does not get called at all!!! Has anyone else seen this behavior and found a work around???
Thanks
Users will use fingers and not mouse :)
You should prefer testing these kinda things on device..
Have you already seen What happens on the device?
It looks like
pickerView:didSelectRow:inComponent:
only gets called once regardless of how many components there are. Seems missleading to me but if you're spinning more than one component, you'll have to cycle through them, calling
pickerView selectedRowInComponent:
for each, regardless of which component gets passed to the method.
I'll try and be as precise as possible here!
Basically, I have an app in the AppStore which is a soundboard. It works great and we've shifted a few copies.
My client now wants to include random sounds when the character's face is clicked on TouchDown. I've got that working fine, using an array.
However, he now wants the button to return, let's say, 10 sounds BEFORE playing random sounds from another batch of 10.
So, in theory, you'd have to hit the button at least 10 times to hear the other sounds.
I was trying to think of a way of counting the number of clicks, to then use a different array of sounds.
Is that even possible?
Any help would be greatly appreciated!
How about using a variable to track number of button taps?