Touch in cocos2d?

Discussion in 'iOS Programming' started by azg442, May 20, 2009.

  1. azg442 macrumors newbie

    Joined:
    May 10, 2009
    #1
    I already have the menuItemImage on the screen and a void hooked up to it but, I only want the void to go off when the persons finger is on the image (kind of like touch down) not when the persons finger is off the image. Thanks in advance!
     
  2. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #2
    This is just about the most rude thing you can possibly do, myself and RobertBlackburn pretty much answered this question for you in your previous thread and to disregard what we have said and ask the same question again slightly reworded is just rude.

    How do you hook a void up to anything?? The return type of a method is not how you refer to it in discussion
     
  3. RobertBlackburn macrumors newbie

    Joined:
    Oct 7, 2008
    #3
    Why have you opened a new thread for the same question?

    If the answers in your other thread are not to your liking maybe you should explain exactly what you wish to achieve as your question makes no sense. "A Void" is nothing so how can you hook nothing up to a menuitem?
     
  4. azg442 thread starter macrumors newbie

    Joined:
    May 10, 2009
    #4
    I'm sorry that I offended you and this is not the same question. I solved that last problem already and now I have a new one. I realize that both of these questions have been worded badly which is where the misunderstanding occurred.

    Code:
    		image = [MenuItemImage itemFromNormalImage:@"image1.png" selectedImage:@"image2.png" target:self selector:@selector(step1:)];
    		Menu *menu = [Menu menuWithItems:image, nil];
    		image.position = cpv( -135, -185);
    		[self addChild: menu z:2];
    step1 is a void defined to do something later in the code. My problem isn't that step1 doesn't work, my problem is that step1 goes when the user touches up inside button. I would like it to work when the user touches down inside button.

    I am only 12 which could be the reason why my questions are worded so bad and are kind of confusing. Sorry again.

    EDIT: Thanks for your help in the last thread. Whether you know it or not you guys helped me a ton!
     
  5. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #5
    You're welcome for the help

    I wasn't offended I just really hate it when people start new threads asking the same question as though the original reply wasn't good enough. I see what you mean now though and it is a different question. It usually pays to spend a couple of extra minutes wording things properly to avoid confusion as it did seem you were asking the same question again.

    The selector on a cocos2d menu item (and most other buttons in various API's) is only called when the touch ends as its the easiest and most accurate way of determining that the user intended to press that button. The only other way round it would be to track the touches position using normal touch functions and trigger a method when the touch location falls into the MenuItems rect. If you are going to do that though you are better off having a nil selector for the menu item as it will call things twice then. There are plenty of examples of this on the forum and on the internet of tracking touch positions, if you look at my previous posts I typed something about it last night in response to another guys post and that will get you on the right track
     

Share This Page