button tapping speed, two buttons, to increase points - objective-c

im trying to make a simple game on cocos2d box2d, its basically got two buttons and a label with the points. the points increment by +1 every second.
what im trying to do is, the player taps both buttons sequentially so it has to be 'button1' then 'button2' then 'button1' then 'button2' .....
if this is done properly then the points increment speed should increase, and the faster the buttons are tapped sequentially, the faster the points should increase.
how can i go about doing this? any ideas?

The idea is simple: you only increment the score when the other button was the last pressed button. That's it. So:
Keep track of the last pressed button.
If button1 is pressed, and button2 was not the last pressed button, don't do anything, otherwise increment the score by some amount.
Do the same kind of check for button2.
Does this make sense?

Related

App Inventor: Making one button change more than one variable

This is about App Inventor 2, i had a button which could change depending on what image sprite had been activated. However, i deleted this button accidentally and lost all of the blocks assigned to it. I cannot remember how to do it. Could someone please tell me how I create a button that can change the value of more than one variable depending on what image sprite has been activated?
You can set specific counter for specific sprite. Just set the counter when the sprite is touched. Then, when the button is clicked, you need to use if and else function to check for what sprite is touched. Below is an example of code, yet it is not complete:

How to check if surrounding buttons are disabled

I have an onscreen keyboard, if a user mistakenly types the wrong letter and presses backspace that letter/button is disabled.
I want to make it that if three buttons are pressed and deleted surrounding one button, it should make the inside button be pressed. This should only happen if the button is surrounded on three sides by mistake buttons.
1) The Size of the buttons change so I can't check with buttons locations
2) I can manually type in every possible combination, but I wanted to know if there is a quicker, and more concise way to write this?
One way to handle this is to have a link on each button to each of its neighbors. Left and right will be easy to initialize, but you may need to initialize vertical neighbors "manually" because of special cases. At run time, just use the links to check buttons.

How do I trigger an event when a UIImageView reaches a certain location?

I have a UIImageView that moves around the screen, and I am trying to trigger a method when it is within a certain distance of another UIImageView, also moving. There is not necessarily any specific time I want to check, I want to know anytime it is within that distance. Help!
EDIT: I have multiple objects(the enemies) moving down the screen while the player is at the bottom of the screen. When the user taps the screen, it "shoots"(a new projectile object is created and the animation to move it up the screen is started). I am trying to detect when the "projectiles" hit the "enemies" and triggering an event(i.e. killing the enemy). I have no idea where to put the code to do this, or even what to do. Do I want to use the Notification System, or do I want to calculate if the projectile will hit the enemy as soon as it is fired?
You probably want to use Key-Value Observing. Here's an example.

Multiple Instances of the Same UIButton?

The Problem
I'm creating a custom UIView, where I need multiple instances of a UIButton. I'm hoping to save memory (and code!) through creating one instance of each button, and then using tags to identify which button is which. I could be creating new 'up' and 'down' buttons, but I'd like to see if I can do this smarter.
The way I have it setup is 3 (should work for any number, however) UILabels, with a 'up' and 'down' button below or above each button respectively. I'm also using a count for the CGPoint location of each button, to match up with the corresponding UILabel.
What I'm doing
So what I am doing is setting the xCount to the default value, creating the 1st label, and then creating the 1st 'up' and 'down' buttons before adding the label and buttons as subviews.
Next I increase the xCount, and change the tags and set the frame for each the label, and both buttons. However, this moves the once 1st button(s) over to the new frame (as expected).
What I've tried:
I've tried setting each button to be a copy of itself after each use (after the 1st label and buttons are added to the subview), but this gives errors upon run.
button = [button copy];
This is more of a code formatting issue, rather than a problem, but I'm looking for some smarter insight onto the problem :).
This project is using Automatic Reference Counting, if that changes anything.
Thanks in advance!
First, your concerns about memory are unfounded. Just create the number of buttons you need.
Second, if you change the frame of a button (or any view), then it moves. You can't have one button in two places.
Third, copying an object uses the same amount of memory as creating two from scratch; new memory has to be allocated for the copy.
Fourth, UIButtons don't conform to NSCopying, so you can't copy them.
Fifth, your concerns about memory are unfounded. Just create the number of buttons you need.

How to pause execution for few seconds and continue the loop?

I am creating a small applicaiton for simulating dice roll. To simulate bounces I change the position of the picture randomly. Now to simulate more than one bounce, I used a for loop to continuously change the position of the picture box. But it is not happening as I planned, the form only displays the position of the last loop. I even tried using System.Threading.Thread.Sleep(1000) hoping to show the bounces, but even they show the last loop only.
For bounceCount As Integer = 1 To bounces
bounce(pb_dice1)
bounce(pb_dice2)
System.Threading.Thread.Sleep(3000) 'I need to pause here and show the recent change in position then continue after 3 seconds
Next
the bounce method changes the position of the PictureBox.
How can I pause my for loop, display the newly positioned dices, and then continue after 3 seconds?
Controls don't refresh their graphics until event handlers finish executing. Otherwise, if several changes were made to one or more controls, they would refresh repeatedly when all you really want is the end result.
To force a control to refresh it's graphics, you need to insert the following line before sleeping:
PictureBox1.Refresh()
You may have to change PictureBox1 to the name of another control, of course. Also, it may be worth refreshing the parent control (ie. the control that contains the dice.)
I guess you should use Application.DoEvents() before calling Sleep().