오늘은 사용자가 우클릭 좌클릭 했는지 검사하는 함수와 우클릭 시 아이템 사용을 하게 만들 계획이다.

메뉴아이템으로 칸을 채웠는데 메뉴아이템은 큰 문제가 있다. 좌클릭만 확인해주고 우클릭은 확인을 해주지 않는다.

인벤토리 만들때 계획을 우클릭은 아이템 사용 좌클릭은 아이템이동으로 세웠기 때문에 우클릭이 필요하다.

우클릭을 사용할 수 있게 만들어야겠다. 우선 제가 사용하는 버전은 0.9입니다. 사용 중인 버전에서 win32API 메시지를 처리하는 곳을 찾아서 정의를 쫓아가다 보니까...

 

CCEXGLView_win32.cpp에서 메시지를 처리하고 있었습니다. 이제 찾았으니까 아주 간단하게 우클릭을 만들 수 있다.

 

위에 사진은 cocos2d에서 만들어놓은 좌클릭인데 

 

사진처럼 캐이스를 2개 추가해주면 우클릭을 눌렀을 때 와 땔 때 들어오는 좌표를 받을 수 있다. 이제 우클릭도 가능하다...

 

 

void Inventory::userClickCheck( NSObject* pSender)

{

if( bLeft ){

switch( ((CCNode*)pSender)->getTag() )

{

case 0: bLeft = false; break;

case 1: bLeft = false; break;

case 2: bLeft = false; break;

case 3: bLeft = false; break;

case 4: bLeft = false; break;

case 5: bLeft = false; break;

case 6: bLeft = false; break;

case 7: bLeft = false; break;

case 8: bLeft = false; break;

case 9: bLeft = false; break;

case 10: bLeft = false; break;

case 11: bLeft = false; break;

case 12: bLeft = false; break;

case 13: bLeft = false; break;

case 14: bLeft = false; break;

case 15: bLeft = false; break;

case 16: bLeft = false; break;

case 17: bLeft = false; break;

case 18: bLeft = false; break;

case 19: bLeft = false; break;

case 50:

Inventoryonoff = false;

this->setIsVisible(false);

break;

}

}

if( bRight ){

int a = 0;

switch( ((CCNode*)pSender)->getTag() )

{

case 0: this->usingItem(0); bRight = false; break;

case 1: this->usingItem(1); bRight = false; break;

case 2: this->usingItem(2); bRight = false; break;

case 3: this->usingItem(3); bRight = false; break;

case 4: this->usingItem(4); bRight = false; break;

case 5: this->usingItem(5); bRight = false; break;

case 6: this->usingItem(6); bRight = false; break;

case 7: this->usingItem(7); bRight = false; break;

case 8: this->usingItem(8); bRight = false; break;

case 9: this->usingItem(9); bRight = false; break;

case 10: this->usingItem(10); bRight = false; break;

case 11: this->usingItem(11); bRight = false; break;

case 12: this->usingItem(12); bRight = false; break;

case 13: this->usingItem(13); bRight = false; break;

case 14: this->usingItem(14); bRight = false; break;

case 15: this->usingItem(15); bRight = false; break;

case 16: this->usingItem(16); bRight = false; break;

case 17: this->usingItem(17); bRight = false; break;

case 18: this->usingItem(18); bRight = false; break;

case 19: this->usingItem(19); bRight = false; break;

}

}

 

}

태그를 사용해서 유저 클릭 체크라는 함수를 만들어서 불값으로 우클릭인지 좌클릭인지를 확인 후 나눠서 사용하면 된다. 우클릭은 일단 usingItem만 넣어뒀다. 좌클릭은 이동을 넣을 생각이다. 아직 못만들었다.

 

클래스 설계하다 한번 꼬여버리니까 힘들었다. 다시 쭉쭉 만들어 봐야겠다.

 

결과 동영상

 

 

타입을 확인하면서 잡템은 걸러버리게 만들었다.

반응형

'Programming > Cocos2D-X' 카테고리의 다른 글

LogoScene 만들기  (0) 2015.05.06
cocos2d 오토액션  (0) 2015.05.05
맵 그리기  (0) 2015.05.03
Inventory 만들기 5  (0) 2015.05.02
Inventory 만들기 3  (0) 2015.04.29
Inventory 만들기2 다시만들 계획  (0) 2015.04.28
Inventory 만들기  (0) 2015.04.27
removeChild 맵에 필요없는 블록 삭제  (0) 2015.04.25