I have a MenuItem button that I want to fire bullets while being held down. Is this possible? If not, how can I accomplish button hold down with ccTouchesBegan? Any help is appreciated. I looked around but could not find anything.
How to repeat action while MenuItem button held down?
(7 posts) (6 voices)-
Posted 2 years ago #
-
You could subclass your MenuItem button and override -selected and -unselected
-(void) selected
{
[super selected];
//start firing
}-(void) unselected
{
[super unselected];
//stop firing
}hth, Codemattic
Posted 2 years ago # -
I'll try that. Thanks.
Posted 2 years ago # -
I'm trying to subleases CCMenuItem, and I'm getting this error:
CustomMenuItemImage may not respond to itemFromNormalImage.Here is my code:
--
CustomMenuItemImage.h (subclass of CCMenuItem):
#import "CCMenuItem.h" @interface CustomMenuItemImage : CCMenuItem { } -(void) selected; -(void) unselected; @end---
CustomMenuItemImage.m
@implementation CustomMenuItemImage -(void) selected { [super selected]; } -(void) unselected { [super unselected]; } @end--
At some point in my Scene.m file, I have:
downArrow = [CustomMenuItemImage itemFromNormalImage:@"downArrow.png" selectedImage:@"downArrow.png" target:self selector:@selector(onDown:)];downArrow is a CustomMenuItemImage. Am I doing something wrong?
Posted 1 year ago # -
Hi,
I think you want:
@interface CustomMenuItemImage : CCMenuItemImageCCMenuItemImage, not CCMenuItem, right?
-Mark
Posted 1 year ago # -
Huge thread revival,
but I am using the above subclassed CCMenuItemImage and am able to successfully log output to the console when
(void) selected;is called.
However, my problem is now that I need to run a function in my main game layer or in another class when the above method is called. How would I achieve this?
I only know how to do this:
GameLayer * myLevelObject = [[GameLayer alloc] init]; [myLevelObject testing];Which is totally ridiculous, as it is allocating and initializing my entire game scene each time the selected method is called!
What I ideally want to do is to call a method that counts up an integer while the button is held down, but this method is in the other class.
What is the best way of doing this?
Posted 8 months ago # -
You could declare your Gamelayer as a global variable, you could then access it from any class that includes it. Its difficult to say the best way of doing it for you as we don't know how your classes and such are connected.
Posted 8 months ago #
Reply
You must log in to post.