모바일 오유 바로가기
http://m.todayhumor.co.kr
분류 게시판
베스트
  • 베스트오브베스트
  • 베스트
  • 오늘의베스트
  • 유머
  • 유머자료
  • 유머글
  • 이야기
  • 자유
  • 고민
  • 연애
  • 결혼생활
  • 좋은글
  • 자랑
  • 공포
  • 멘붕
  • 사이다
  • 군대
  • 밀리터리
  • 미스터리
  • 술한잔
  • 오늘있잖아요
  • 투표인증
  • 새해
  • 이슈
  • 시사
  • 시사아카이브
  • 사회면
  • 사건사고
  • 생활
  • 패션
  • 패션착샷
  • 아동패션착샷
  • 뷰티
  • 인테리어
  • DIY
  • 요리
  • 커피&차
  • 육아
  • 법률
  • 동물
  • 지식
  • 취업정보
  • 식물
  • 다이어트
  • 의료
  • 영어
  • 맛집
  • 추천사이트
  • 해외직구
  • 취미
  • 사진
  • 사진강좌
  • 카메라
  • 만화
  • 애니메이션
  • 포니
  • 자전거
  • 자동차
  • 여행
  • 바이크
  • 민물낚시
  • 바다낚시
  • 장난감
  • 그림판
  • 학술
  • 경제
  • 역사
  • 예술
  • 과학
  • 철학
  • 심리학
  • 방송연예
  • 연예
  • 음악
  • 음악찾기
  • 악기
  • 음향기기
  • 영화
  • 다큐멘터리
  • 국내드라마
  • 해외드라마
  • 예능
  • 팟케스트
  • 방송프로그램
  • 무한도전
  • 더지니어스
  • 개그콘서트
  • 런닝맨
  • 나가수
  • 디지털
  • 컴퓨터
  • 프로그래머
  • IT
  • 안티바이러스
  • 애플
  • 안드로이드
  • 스마트폰
  • 윈도우폰
  • 심비안
  • 스포츠
  • 스포츠
  • 축구
  • 야구
  • 농구
  • 바둑
  • 야구팀
  • 삼성
  • 두산
  • NC
  • 넥센
  • 한화
  • SK
  • 기아
  • 롯데
  • LG
  • KT
  • 메이저리그
  • 일본프로야구리그
  • 게임1
  • 플래시게임
  • 게임토론방
  • 엑스박스
  • 플레이스테이션
  • 닌텐도
  • 모바일게임
  • 게임2
  • 던전앤파이터
  • 마비노기
  • 마비노기영웅전
  • 하스스톤
  • 히어로즈오브더스톰
  • gta5
  • 디아블로
  • 디아블로2
  • 피파온라인2
  • 피파온라인3
  • 워크래프트
  • 월드오브워크래프트
  • 밀리언아서
  • 월드오브탱크
  • 블레이드앤소울
  • 검은사막
  • 스타크래프트
  • 스타크래프트2
  • 베틀필드3
  • 마인크래프트
  • 데이즈
  • 문명
  • 서든어택
  • 테라
  • 아이온
  • 심시티5
  • 프리스타일풋볼
  • 스페셜포스
  • 사이퍼즈
  • 도타2
  • 메이플스토리1
  • 메이플스토리2
  • 오버워치
  • 오버워치그룹모집
  • 포켓몬고
  • 파이널판타지14
  • 배틀그라운드
  • 기타
  • 종교
  • 단어장
  • 자료창고
  • 운영
  • 공지사항
  • 오유운영
  • 게시판신청
  • 보류
  • 임시게시판
  • 메르스
  • 세월호
  • 원전사고
  • 2016리오올림픽
  • 2018평창올림픽
  • 코로나19
  • 2020도쿄올림픽
  • 게시판찾기
  • 오유인페이지
    개인차단 상태
    세레니드님의
    개인페이지입니다
    가입 : 12-11-20
    방문 : 77회
    닉네임변경 이력
    회원차단
    회원차단해제
    게시물ID : programmer_14833
    작성자 : 세레니드
    추천 : 0
    조회수 : 566
    IP : 183.108.***.12
    댓글 : 1개
    등록시간 : 2015/12/07 05:45:13
    http://todayhumor.com/?programmer_14833 모바일
    [안드로이드] OnTouch 작동이 왜 안할까요..?
    옵션
    • 본인삭제금지
    <pre style="color:rgb(0,0,0);font-family:'굴림체';font-size:9pt;background-color:rgb(255,255,255);"><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(0,0,128);font-weight:bold;">public class </span>GameView <span style="color:rgb(0,0,128);font-weight:bold;">extends </span>View <span style="color:rgb(0,0,128);font-weight:bold;">implements </span>View.OnTouchListener {<br><br><span style="color:rgb(0,0,128);font-weight:bold;">int </span><span style="color:rgb(102,14,122);font-weight:bold;">width</span>, <span style="color:rgb(102,14,122);font-weight:bold;">height</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 화면의 폭과 높이<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(0,0,128);font-weight:bold;">static int </span><span style="color:rgb(102,14,122);font-style:italic;">x</span>, <span style="color:rgb(102,14,122);font-style:italic;">y</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터의 현재 좌표<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(0,0,128);font-weight:bold;">int </span><span style="color:rgb(102,14,122);font-weight:bold;">dx</span>, <span style="color:rgb(102,14,122);font-weight:bold;">dy</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터가 이동할 방향과 거리<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(0,0,128);font-weight:bold;">int </span><span style="color:rgb(102,14,122);font-weight:bold;">charaterWidth</span>, <span style="color:rgb(102,14,122);font-weight:bold;">charaterHeight</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터의 폭과 높이<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(0,0,128);font-weight:bold;">int </span><span style="color:rgb(102,14,122);font-weight:bold;">counter</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 루프 카운터<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span>Bitmap <span style="color:rgb(102,14,122);font-weight:bold;">character</span>[] = <span style="color:rgb(0,0,128);font-weight:bold;">new </span>Bitmap[<span style="color:rgb(0,0,255);">2</span>]; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터의 비트맵 이미지<br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"> //-----------------------------------<br></span><span style="color:rgb(128,128,128);font-style:italic;"> // Constructor - 게임 초기화<br></span><span style="color:rgb(128,128,128);font-style:italic;"> //-----------------------------------<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(0,0,128);font-weight:bold;">public </span>GameView(Context context) {<br><span style="color:rgb(0,0,128);font-weight:bold;">super</span>(context);<br><br> Display display = ((WindowManager) context.getSystemService(Context.<span style="color:rgb(102,14,122);font-style:italic;font-weight:bold;">WINDOW_SERVICE</span>))<br> .getDefaultDisplay();<br><span style="color:rgb(102,14,122);font-weight:bold;">width </span>= display.getWidth(); <span style="color:rgb(128,128,128);font-style:italic;">// 화면의 가로폭<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-weight:bold;">height </span>= display.getHeight(); <span style="color:rgb(128,128,128);font-style:italic;">// 화면의 세로폭<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-style:italic;">x </span>= <span style="color:rgb(0,0,255);">100</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터의 현재 x위치<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-style:italic;">y </span>= <span style="color:rgb(0,0,255);">100</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터의 현재 y위치<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-weight:bold;">dx </span>= <span style="color:rgb(0,0,255);">4</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터가 x축으로 이동할 거리<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-weight:bold;">dy </span>= <span style="color:rgb(0,0,255);">6</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터가 y축으로 이동할 거리<br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"> // 캐릭터의 비트맵 읽기<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-weight:bold;">character</span>[<span style="color:rgb(0,0,255);">0</span>] = BitmapFactory.<span style="font-style:italic;">decodeResource</span>(getResources(), R.mipmap.<span style="color:rgb(102,14,122);font-style:italic;font-weight:bold;">ic_launcher</span>);<br><span style="color:rgb(102,14,122);font-weight:bold;">character</span>[<span style="color:rgb(0,0,255);">1</span>] = BitmapFactory.<span style="font-style:italic;">decodeResource</span>(getResources(), R.mipmap.<span style="color:rgb(102,14,122);font-style:italic;font-weight:bold;">ic_launcher</span>);<br><br><span style="color:rgb(102,14,122);font-weight:bold;">charaterWidth </span>= <span style="color:rgb(102,14,122);font-weight:bold;">character</span>[<span style="color:rgb(0,0,255);">0</span>].getWidth() / <span style="color:rgb(0,0,255);">2</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터의 폭/2<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-weight:bold;">charaterHeight </span>= <span style="color:rgb(102,14,122);font-weight:bold;">character</span>[<span style="color:rgb(0,0,255);">0</span>].getHeight() / <span style="color:rgb(0,0,255);">2</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 캐릭터의 높이/2<br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-weight:bold;">mHandler</span>.sendEmptyMessageDelayed(<span style="color:rgb(0,0,255);">0</span>, <span style="color:rgb(0,0,255);">10</span>);<br> }<br><br><span style="color:rgb(128,128,128);font-style:italic;">//-----------------------------------<br></span><span style="color:rgb(128,128,128);font-style:italic;"> // 실제 그림을 그리는 부분<br></span><span style="color:rgb(128,128,128);font-style:italic;"> //-----------------------------------<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(0,0,128);font-weight:bold;">public void </span>onDraw(Canvas canvas) {<br><span style="color:rgb(102,14,122);font-style:italic;">x </span>+= <span style="color:rgb(102,14,122);font-weight:bold;">dx</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 가로 방향으로 이동<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-style:italic;">y </span>= <span style="color:rgb(102,14,122);font-weight:bold;">height </span>- <span style="color:rgb(102,14,122);font-weight:bold;">charaterHeight</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 세로 위치 세팅<br></span><span style="color:rgb(128,128,128);font-style:italic;"> // y += dy; // 세로 방향으로 이동<br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(0,0,128);font-weight:bold;">if </span>(<span style="color:rgb(102,14,122);font-style:italic;">x </span>< <span style="color:rgb(102,14,122);font-weight:bold;">charaterWidth </span>|| <span style="color:rgb(102,14,122);font-style:italic;">x </span>> <span style="color:rgb(102,14,122);font-weight:bold;">width </span>- <span style="color:rgb(102,14,122);font-weight:bold;">charaterWidth</span>) <span style="color:rgb(102,14,122);font-weight:bold;">dx </span>= <span style="color:rgb(0,0,255);">0</span>; <span style="color:rgb(128,128,128);font-style:italic;">// 좌우의 벽이면 방향을 바꿈<br></span><span style="color:rgb(128,128,128);font-style:italic;"> //if (y < charaterHeight || y > height - charaterHeight) dy = -dy; // 천정이거나 바닥이면 방향을 바꿈<br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-weight:bold;">counter</span>++;<br><span style="color:rgb(0,0,128);font-weight:bold;">int </span>n = <span style="color:rgb(102,14,122);font-weight:bold;">counter </span>% <span style="color:rgb(0,0,255);">20 </span>/ <span style="color:rgb(0,0,255);">10</span>;<br><br><br><br> canvas.drawBitmap(<span style="color:rgb(102,14,122);font-weight:bold;">character</span>[n], <span style="color:rgb(102,14,122);font-style:italic;">x </span>- <span style="color:rgb(102,14,122);font-weight:bold;">charaterWidth</span>, <span style="color:rgb(102,14,122);font-style:italic;">y </span>- <span style="color:rgb(102,14,122);font-weight:bold;">charaterHeight</span>, <span style="color:rgb(0,0,128);font-weight:bold;">null</span>);<br> } <span style="color:rgb(128,128,128);font-style:italic;">// onDraw 끝<br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"> //------------------------------------<br></span><span style="color:rgb(128,128,128);font-style:italic;"> // Timer Handler<br></span><span style="color:rgb(128,128,128);font-style:italic;"> //------------------------------------<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span>Handler <span style="color:rgb(102,14,122);font-weight:bold;">mHandler </span>= <span style="color:rgb(0,0,128);font-weight:bold;">new </span>Handler() { <span style="color:rgb(128,128,128);font-style:italic;">// 타이머로 사용할 Handler<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(0,0,128);font-weight:bold;">public void </span>handleMessage(Message msg) {<br> invalidate(); <span style="color:rgb(128,128,128);font-style:italic;">// onDraw() 다시 실행<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(102,14,122);font-weight:bold;">mHandler</span>.sendEmptyMessageDelayed(<span style="color:rgb(0,0,255);">0</span>, <span style="color:rgb(0,0,255);">10</span>); <span style="color:rgb(128,128,128);font-style:italic;">// 10/1000초마다 실행<br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span>}<br> }; <span style="color:rgb(128,128,128);font-style:italic;">// Handler<br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"> </span><span style="color:rgb(128,128,0);">@Override<br></span><span style="color:rgb(128,128,0);"> </span><span style="color:rgb(0,0,128);font-weight:bold;">public boolean </span>onTouch(View v, MotionEvent event) {<br><span style="color:rgb(0,0,128);font-weight:bold;">if</span>(event.getAction()==MotionEvent.<span style="color:rgb(102,14,122);font-style:italic;font-weight:bold;">ACTION_DOWN</span>) {<br><br><span style="color:rgb(102,14,122);font-style:italic;">x </span>= <span style="color:rgb(102,14,122);font-style:italic;">x </span>- <span style="color:rgb(0,0,255);">1000 </span>;<br> invalidate();<br> }<br><span style="color:rgb(0,0,128);font-weight:bold;">return true</span>;<br> }<br>} <span style="color:rgb(128,128,128);font-style:italic;">// GameView 끝<br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;">// 프로그램 끝</span></pre> <div> </div> <div><em><font color="#808080" face="굴림체"></font></em> </div> <div> X 의 위치가 변화 되어야 할 거 같은데 인식이 안되네요..</div><pre style="color:rgb(0,0,0);font-family:'굴림체';font-size:9pt;background-color:rgb(255,255,255);"><span style="color:rgb(128,128,128);font-style:italic;"><br></span><span style="color:rgb(128,128,128);font-style:italic;"><br></span></pre>

    이 게시물을 추천한 분들의 목록입니다.
    푸르딩딩:추천수 3이상 댓글은 배경색이 바뀝니다.
    (단,비공감수가 추천수의 1/3 초과시 해당없음)

    죄송합니다. 댓글 작성은 회원만 가능합니다.

    번호 제 목 이름 날짜 조회 추천
    12
    저의 꿈을 차렸습니다. [32] 세레니드 23/06/09 12:09 465 18
    11
    요리할때 맨손으로 [3] 세레니드 17/11/21 17:01 152 0
    10
    게임 이름좀 알려주시겠어요 ~? [5] 본인삭제금지 세레니드 17/10/22 11:55 257 3
    9
    쿼리문에서 UPDATE 사용시 값변경 질문이요 !! 짧아요 글 [17] 본인삭제금지 세레니드 16/01/02 21:09 27 0
    8
    하.......... 이걸 몇시간동안 헤매다니 [2] 세레니드 16/01/01 05:11 47 1
    7
    안드로이드 궁금한게 있습니다. [1] 본인삭제금지 세레니드 15/12/10 15:03 20 0
    [안드로이드] OnTouch 작동이 왜 안할까요..? [1] 본인삭제금지 세레니드 15/12/07 05:45 27 0
    5
    [안드로이드] 프레임레이아웃 온클릭?? [4] 본인삭제금지 세레니드 15/12/04 15:49 28 0
    4
    [안드로이드] 질문있습니다. 객체관련 [2] 본인삭제금지 세레니드 15/11/06 18:13 19 0
    3
    [android] 스레드 사용에서 무반응입니다. [2] 본인삭제금지 세레니드 15/11/02 02:17 28 0
    2
    cpp 아주 기초적인 질문입니다 ㅜㅜ [1] 본인삭제금지 세레니드 15/10/18 20:14 35 0
    [1]
    단축키 운영진에게 바란다(삭제요청/제안) 운영게 게시판신청 자료창고 보류 개인정보취급방침 청소년보호정책 모바일홈