Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9177069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:15:04+00:00 2026-06-17T17:15:04+00:00

I am attempting to make a basic game which requires a serious of buttons

  • 0

I am attempting to make a basic game which requires a serious of buttons to control player movement. Keep in mind I am using cocos-2d. My goal is to have the buttons be holdable and move a sprite when held down. The code i am using now looks like this.

CCMenuItemHoldable.h

@interface CCMenuItemSpriteHoldable : CCMenuItemSprite {
    bool buttonHeld;
}

@property (readonly, nonatomic) bool buttonHeld;

CCMenuItemHoldable.m

@implementation CCMenuItemSpriteHoldable

@synthesize buttonHeld;

-(void) selected
{
    [super selected];
    buttonHeld = true;
    [self setOpacity:128];
}

-(void) unselected
{
    [super unselected];
    buttonHeld = false;
    [self setOpacity:64];
}

@end

and for the set up of the buttons

rightBtn = [CCMenuItemSpriteHoldable itemFromNormalSprite:[CCSprite spriteWithFile:@"art/hud/right.png"] selectedSprite:[CCSprite spriteWithFile:@"art/hud/right.png"] target:self selector:@selector(rightButtonPressed)];


CCMenu *directionalMenu = [CCMenu menuWithItems:leftBtn, rightBtn, nil];
[directionalMenu alignItemsHorizontallyWithPadding:0];
[directionalMenu setPosition:ccp(110,48)];
[self addChild:directionalMenu];

This all seems to work fine but when i do

-(void)rightButtonPressed:(id) sender
{

    if([sender buttonHeld])
            targetX = 10; 
        else{
            targetX = 0; 
        }   
}

The crash has been fixed but I am trying to get my sprite to move. In my game tick function I add the value of targetX to the position of the sprite on a timer, still no movement.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:15:04+00:00Added an answer on June 17, 2026 at 5:15 pm

    Please, always include a crash log when asking questions about crashes.

    In your case, I can guess the problem. You are adding this selector:

    @selector(rightButtonPressed)
    

    Your method is called

    rightButtonPressed:(id)sender
    

    Which would be, as a selector, rightButtonPressed: – note the colon indicating that an argument is passed. Either change the method so it has no argument, or add a colon to the selector when you create the button.

    The crash log would be telling you this – it would say “unrecognised selector sent to…” with the name of the receiving class, and the name of the selector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to make a basic game in cocos2d, and I've gotten to the
While attempting to make a game using Canvas I noticed a few quirks on
I am attempting to make a basic scroll view with a connected page control,
I'm attempting to make a simple linear text game that will display inside a
I am attempting to make my first mobile website by just using a different
I am attempting to make a program in C which presents a GUI and
I'm attempting to represent the basic strategy of a blackjack game as a map
I'm attempting to make an Odata post using odata4j. After dumping the posted xml
I am attempting to make a HTTPS connection to a website using HttpsURLConnection ,
I am attempting to make a pie chart using a php file that gets

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.