This time I would like to ask if anybody had such strange problem with disabling button (CCMenuItemImage) in cocos2d. I have in-App-Purchase connected and when purchase is done following function is triggered
- (void)productPurchased:(NSNotification *)notification {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
waitingForStore = FALSE;
[loop setVisible:FALSE];
[buyItem setVisible:FALSE];
// setAccessibilityElementsHidden:YES];
NSString *productIdentifier = (NSString *) notification.object;
NSLog(#"Purchased: %#", productIdentifier);
}
waitingForStore = FALSE;
[loop setVisible:FALSE];
This two operation works fine, but the problem is with the third one. I would like to make the 'BUY' button invisible.
[buyItem setVisible:FALSE];
This one does not do anything at this place( the button is still visible and accessible). If I will use it on the other part of code it works just fine- but here .... not. Trying to change position doesn't work neither.
Could it be connected with inAppPurchase thread or something?
I have found the reason. It was my mistake when making two calls to the apple store and creating two buttons. :) So, it could be closed.
I understand your problem. If you you want to disable menuitem you can set menuitem.isEnabled property.
And if you want to hide button, you can set property menuitem.visible = NO.
If this is not working for you can also use [menuitem runaction:[CCFadeOut actionWithDuration:1.0f] ]. Then use FadeIn as per your requirement.
This is alternative option for you.
Related
I'm learning objective-C, and have started off by making a simple calculator. I've hit a couple of walls though. I have 2 displays, the current number being typed in, and a smaller one that displays everything that has been typed in thus far. I also have a "clear" button.
I want it so that if a user hits the "clear" button once, it clears the main display, and changes it's title to "AC" (all clear). If it is then hit again I want it to clear the smaller display of everything that has been typed in so far.
That all works fine, but I'm having issues because I want the button to go back to being just "clear" when the user starts typing in another number.
I have an #property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
and an #synthesize for that property.
How can I make it so that whenever userIsInTheMiddleOfEnteringANumber == YES, I can set the clear button (or the #property (nonatomic) BOOL allClear) that I have to change?
One solution is to not #synthesize the userIsInTheMiddleOfEnteringANumber property, and write the code for it yourself.
Add a private BOOL variable to your class, and write the userIsInTheMiddleOfEnteringANumber and setUserIsInTheMiddleOfEnteringANumber: methods. The getter should return the "backing" variable; the setter should check the old and the new value to see if the old value is NO and the new value is YES. When this is the case, the setter should change the title of the button as appropriate.
in the method viewdidload add the name of the button title as clear
- (void)viewDidLoad{
[super viewDidLoad];
[myButton setTitle:#"Clear" forState:UIControlStateNormal];
}
and in the method which clears everything make the button title to AC
- (void)clearAllAndACMethod{
if(userIsInTheMiddleOfEnteringANumber==Yes)
{
[myButton setTitle:#"AC" forState:UIControlStateNormal];
userIsInTheMiddleOfEnteringANumber=NO;
}
else{
another type code and
[myButton setTitle:#"Clear" forState:UIControlStateNormal];
userIsInTheMiddleOfEnteringANumber=YES;
}
//remaining method with
}
CHange the bool value according to your need because i didnt get you bool value correctly I think. try this it will work fine
I've recently added the CCLayerPanZoom cocos2d extension to my project and got my game scene zooming and scrolling just like I want. Now when the player takes certain actions, I want to be able to disable the pan/zoom temporarily while they perform an action but can't figure out how to do it. I searched around and found the following code in a forum but it doesn't work or I don't know how to use it.
Does anyone know how to do this properly either with different code or the code below?
-(void)enableTouches:(BOOL)enable {
if(enable) {
[[CCTouchDispatcher sharedDispatcher] addStandardDelegate:self priority:0];
_panZoomLayer.isTouchEnabled = YES;
CCLOG(#"LayerPanZoom enabled.");
} else {
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
_panZoomLayer.isTouchEnabled = NO;
CCLOG(#"LayerPanZoom disabled.");
}
}
I finally figured it out and figured I would post the answer back up here to share. The code I posted wasn't working because I was sending back self instead of the _panZoomLayer. So here are the steps to get this working yourself.
Implement the CCLayerPanZoom into your project as described by the documentation.
Add the following code as a method to call on your new CCLayerPanZoom class.
-(void)enableTouches:(BOOL)enable {
if(enable) {
[[CCTouchDispatcher sharedDispatcher] addStandardDelegate:_panZoomLayer priority:0];
CCLOG(#"LayerPanZoom enabled.");
} else {
[[CCTouchDispatcher sharedDispatcher] removeDelegate:_panZoomLayer];
CCLOG(#"LayerPanZoom disabled.");
}}
NOTE: Make sure to put the instance of the parent class as the delegate to remove.
In order to re-enable and have it function properly, you have to remove all the entries from the array in the CCLayerPanZoom class before calling to re-register the delegate. I created a new method in the CCLayerPanZoom class as follows and just call it right before the addStandardDelegate method above.
-(void)removeTouchesFromArray {
[self.touches removeAllObjects];
}
Then it all works great! Took me a while to learn how to use this extension but it works perfect once you figure it all out. I can single finger pan, double finger zoom/pan, set center location for entire scene, limit panning past edges, and set min/max scales. I know people have had a lot of issues with this but it is a great extension, just takes some messing around with to understand it. Let me know if you have any questions. Hope this helps someone else.
I have made a button so that when it's pressed by the user and a particular row(s) are selected it does something.
So far I have this:
if (pickerView selectedRowInComponent:0) {
[mailComposerTwo setToRecipients:[NSArray arrayWithObjects:#"email#blah.com",nil]];
}
It works on its own. But when I do the if statement multiple times it crashes.
An ways of making it work?
Any help appreciated, thanx.
The problem probably lies with your mail composer, not the picker view. When you show the composer, make sure that you only create it if it hasn't already created.
Also, make sure you release it after you show it:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
...[configure the picker]
[rootContainer presentModalViewController:picker animated:YES];
[picker release];
NSArray *finalList = [[NSArray alloc]init];
//put all your if statements
if (pickerView selectedRowInComponent:0)
{
[finalList arrayByAddingObjectsFromArray:#[#"email#address.com",#"second#address.com",...];
}
if (pickerView selectedRowInComponent:1)
{
[finalList arrayByAddingObjectsFromArray:#[#"another#address.com",#"fourth#address.com",...];
}
//end of if statements
[mailComposerTwo setToRecipients:finalList];
[self presentViewController:yourInitializedMessageController animated:YES completion:^{NSLog(#"message controller is presented");}];
This will do a single method call rather than continually reassigning which for some odd reason is causing your exception. presentModalViewController:animated: has been deprecated as of iOS 6.0? if not 7.0 I believe.
NOTE! Make the message controller a property of the main view controller. It is good practice so that it is not auto-released by iOS if you need to bring it back up. However if you use MFMessageComposer iOS will keep messenger allocated or running in a thread somewhere so initializing a view controller for it is quick.
How to remove animation from object in raphael?
var animation = Raphael.animation({opacity:.2}, 1000);
var circle = paper.circle(0, 0, 5).animate(animation.repeat(Infinity));
I want to perform animation on object until some moment in time. And the question is how to remove/stop animation in that specific moment?
Well, I really don't know why, but the fiddle works if don't pass any arguments to the stop method. Despite what Raphael's documentation says, I found a working example of an animation stopping in this site (is not the most beatiful site, by the way, but they have an example for each raphael method!)
Here you have the Fiddle working. http://jsfiddle.net/fKxqS/2/
Enjoy!
If you want to stop the animation after a specific timelapse...
setTimeout(circle.stop(animation), 500) //500 is milliseconds, so it's 0.5s
If you want to stop the animation after an event, such as a click
circle.click(function(){
circle.stop(animation)
})
Edit: Seems Raphael doesn't stop if repeat is set to Infinite, perhaps somebody knows a workaround, here's the fiddle: http://jsfiddle.net/fKxqS/
I don't quite understand, but basically I am trying to click a button and have a value added to my NSMutableArray myArray which is a property. I thought my method that would be called when a button is pressed would be something like:
- (IBAction)addInterval {
NSString *string = #"test";
[self.myArray addObject:string];
}
But I don't understand why this doesn't work?
Also, is Wifi, volume control, and bluetooth all not in our sandbox to be used?thanks.
In general, in order for your IBAction to get called, it must have a parameter, e.g.
-(IBAction) addInterval: (id)sender {
}
Also, make sure you have bound the action to the button correctly inside the UI Designer - you should see it as an action outlet for the button.
To make sure your method is being called, stick a line in the method like:
NSLog(#"Called addInterval action");
Bluetooth will not work in sandbox, WiFi will work in the sense that the network connection will function, and the reachability example should help you here.
Could be one of a few things but the classic problem here is forgetting to connect the button to the action in interface builder. Have you checked that?
I'm also assuming that you've synthesized the myArray property so that you can use the dot notation.