레이블이 touch인 게시물을 표시합니다. 모든 게시물 표시
레이블이 touch인 게시물을 표시합니다. 모든 게시물 표시

2014년 7월 10일 목요일

Cocos2d-x [Touch Listener] addListener instead of SetTouchEnabled(true)

SetTouchEnabled is deprecated.
It still works. But you do not want another warning.
Here is the key to avoid the warning.


auto listener = cocos2d::EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    
    listener->onTouchBegan = [&](cocos2d::Touch* touch, cocos2d::Event* event)
    {
        Point p = touch->getLocation();
        cocos2d::Rect rect = this->getBoundingBox();
        
        if(rect.containsPoint(p))
        {
            this->onTouchBegan(touch, event);
            return true; // to indicate that we have consumed it.
        }
        
        return false; // we did not consume this event, pass thru.
    };
    
    listener->onTouchEnded = [=](cocos2d::Touch* touch, cocos2d::Event* event)
    {
        this->onTouchEnded(touch, event);
    };
    

    cocos2d::Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(listener, 30);


Check my game.
Mr Boss




2011년 8월 16일 화요일

[IPhone Dev] Get point from touch

 Getting location for touch!
 
Get the position!

-(void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint location = [touch locationInView:touch.view]; 
}



Mayday Timeattack - Free on Appstore