onTouchesBegan - sprite -> position is not right and moving?

Hi,

I’m a littebit confused… If I click on the button the LOG shows me that the code is not sesrching for the right coordinates… And If I move my world it seemed that the position to click also is moveing …

This is my code:

void myClass::onTouchesBegan(const std::vector<Touch*>& touches, Event* event)
{
    if(touches.size() < 1){
        //Do nothing and return
        return;
    }
    
    Touch* touch = touches[0];
    touchLocation = touch->getLocation();
    touchLocation = this->getGameWorldNode()->convertToNodeSpace(touchLocation);
    
  //Levelhelper Camera
    LHCamera* swipe = (LHCamera*)this-> getChildNodeWithName("mainCamera");
    cameraStartPosition = swipe->getPosition();
    
    //all other Sprites in Game-World
    //this->handleNodesAtLocation(touchLocation);
    
    
    //HUD-Layer (in other CPP FILE later)
    
    HUD_layerLocation       = touch->getLocation();
    location_store_diamonds = touch->getLocation();
    location_store_coins    = touch->getLocation();
    location_store_language = touch->getLocation();
    location_userSettings   = touch->getLocation();
    location_settingsTest   = touch->getLocation();
    location_notification_coins= touch->getLocation();
    location_notification_diamonds= touch->getLocation();
    location_notification_unlock= touch->getLocation();
    
    
    Point location = touch->getLocationInView();
    location = this->getGameWorldNode()->convertToNodeSpace(location);
    this->handleNodesAtLocation(location);
    
    
    userTestHandler->userTest::handle_userTestSettings(location_settingsTest);

    
    HUDlayerHandler->handleHUDlayer(HUD_layerLocation);
    storeCoinsAssetHandler->handleStore_coins(location_store_coins);
    storeDiamondsAssetHandler->handleStore_diamonds(location_store_diamonds);
    storeLanguageAssetHandler->handleStore_language(location_store_language);
    userSettingsHandler->handle_userSettings(location_userSettings);
    notificationCoinsAssetHandler->handleNotification_coins(location_notification_coins);
    notificationDiamondsAssetHandler->handleNotification_diamonds(location_notification_diamonds);
    notificationUnlockAssetHandler->handleNotification_unlock(location_notification_unlock);
    
    //userTestHandler->handle_userTestSettings(location_settingsTest);
    //load function from other cpp
    //loadFromOtherFile.handleHUDlayer(HUD_layerLocation);

    
    HUDlayerHandler->showOrHideAds();
    
    
    //dont forget to call super
    LHScene::onTouchesBegan(touches, event);
    
    
    
}

-----------------------*/

void myClass::handleNodesAtLocation(Point screenLocation)
{
    CCLOG(FILE "-> WOLRLD - CLICK");
    Point sceneLocation = this->getGameWorldNode()->convertToNodeSpace(screenLocation);
    
    
    CCWorld *_farmWorld = CCSoomlaLevelUp::getInstance()->getWorld(WORLD_FARM_ID);
   
       
    /*----*/
    if(_farmWorld->canStart()) {
        CCLOG(FILE "TOUCH AKTION" );
        
        {
            LHSprite* btn_farm = (LHSprite*)this->getChildNodeWithName("farm_world_shape");
            
            Point localPoint = btn_farm->getParent()->convertToNodeSpace(screenLocation);
            if(btn_farm && btn_farm->getBoundingBox().containsPoint(localPoint))
            
            {
                //CCLOG(FILE "-> WOLRLD - CLICK");
                if(_farmWorld->canStart()) {
                    CCLOG(FILE "World is unlocked." );
                }
                
                else {
                    CCLOG(FILE "World is locked. -> show Notification with Store" );
                }
            }
        }
    }
    else {CCLOG(FILE "KEINE TOUCH AKTION" );}
    /*----*/
    
    
    
}

WHAT IS WRONG???

Just use Touch instead of Touches.

Also, just return true in onTouchBegan() and move your code to __onTouchEnd()_. To touch a button you just need a single touch, not multiples. Make this simple for yourself.

Hi @slackmoehrle,

thanks for your help, but… the LOG with coordinates) is still the same…
And if I use onTochBegann instead of onTouchesBegann I got the Info from LevelHelper that onTouchBegann is deprecated hmmm but the code works…

I do not understand why the position of the sprite I see at the screen is probably not the same with the area I click on. It seemed that the sprite area and the click area are shifted… and if I scroll (move) my world to the top, right etc… it seemd that the shifting becomes bigger… and it is more wordse if I use parent or parent with Childs sprites…