안드로이드 개발 질문/답변
(글 수 45,052)
우분투에서 이클립스에 안드로이드 게임을 만들고 있습니다.
// helloworldScene.h
....
virtual void ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
.....
//helloworldScene.cpp
bool HelloWorld::init()
{
...
this->setIsTouchEnabled(true);
...
}
void HelloWorld::ccTouchesBegan(cocos2d::CCSet* touches, cocos2d::CCEvent* event)
{
CCTouch* touch = (CCTouch*)touches;
CCPoint touchPoint =touch->locationInView(touch->view());
touchPoint = CCDirector::sharedDirector()->convertToGL(touchPoint);
touchflag ="777777";
CCLog("%f",touchPoint.y);
return;
}
//콘솔창의 내용입니다.
make: Entering directory `/home/songjinyoung/SDKs/cocos2d/cocostest/android'
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Install : libcocos2d.so => libs/armeabi/libcocos2d.so
Install : libcocosdenshion.so => libs/armeabi/libcocosdenshion.so
Compile++ thumb : game_logic <= HelloWorldScene.cpp
jni/../../Classes/HelloWorldScene.cpp: In member function 'virtual void HelloWorld::ccTouchesBegan(cocos2d::CCSet*, cocos2d::CCEvent*)':
jni/../../Classes/HelloWorldScene.cpp:118: error: 'touchPoint' was not declared in this scope
make: *** [obj/local/armeabi/objs-debug/game_logic/HelloWorldScene.o] 오류 1
make: Leaving directory `/home/songjinyoung/SDKs/cocos2d/cocostest/android'
레이어에 간단히 터치 했을때 터치 로그를 띄우고 싶은데 도저히 안되네요. ;;
어제 오늘 내내 밤샜습니다;;
어떻게 구현해야 하나요?
2012.05.04 17:22:35
CCSetIterator it = touches->begin();
CCTouch* touch = (CCTouch*)(*it);
CGPoint location = touch->locationInView(touch->view());
CGPoint convertedLocation = CCDirector::sharedDirector()->convertToGL(location);
2012.05.04 17:54:44
void SelectScene::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent)
{
CCSetIterator iter;
CCTouch *touch;
for (iter = pTouches->begin(); iter != pTouches->end(); ++iter)
{
touch = (CCTouch *)(*iter);
CCPoint location = touch->locationInView(touch->view());
}
}
제가 사용하는 방법 입니다. for 안에 쓰시면 되고, location.x 와 location.y 가 x,y좌표가 되겠네요.
그리고 cocos2d 최신버전에선 CCPoint location = touch->locationInView(touch->view());
빨간색 밑줄친 부분을 삭제해주셔야 됩니다. 바꼈어요.



