실전 이미지 처리 프로그래밍 Lecture #10. 강의 목차 ▶ 실제 게임을 구현하는 데 필요한 화면 구성을 알아본다. ▶ Canvas 클래스와 Graphics 클래스를 이용해 가장 기본적인 게임 화면을 하나씩 직접 구현해 본다. 2Mobile Programming.

Slides:



Advertisements
Similar presentations
J2ME Form Nesneleri Melih Sakarya. Form Nesnesi Form form= new Form("Giris"); display.setCurrent(form);
Advertisements

Made with love, by Zachary Langley Applets The Graphics Presentation.
Java 2D Training. Basic Tools Java SDK 1.4x Wireless Toolkit 2.x NetBeans IDE + mobility pack Global Code editor Text Comparer Tools Graphics Editor Sprite.
5-3. 세이더 천안천일고등학교 류빈 1.Canvas 와 Paint 객체를 통해 화면에 원하는 도형을 그리고 속성을 변경하는 기본적인 방법에 대해 소개 한다. 2. 토스트로 메시지를 출력하는 방법과 스피커를 통해 소리를 출력하는 방법에.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Albert Johnson Molly Richardson Andrew Kruth.  Threads Runnable interface sleep()  GUIs repaint() paintComponent()
Cosc 4755 Low-level GUI APIs. Low-Level API Composed of Canvas and Graphics classes – GameCanvas will be covered later on Canvas is an abstract class,
A Simple Applet --- Digital Clock import java.awt.*; import java.util.Calendar; public class DigitalColok extends java.applet.Applet implements Runnable.
Java Threads Part II. Lecture Objectives To understand the concepts of multithreading in Java To be able to develop simple multithreaded applications.
Enahnced Digital Clock Applet Setting applet parameters in the web page. The applet tag in HTML:
24-Jun-15 Simple Animation. 2 The bouncing ball The “bouncing ball” is to animation what “Hello world” is to programming With a single Thread, we can.
Starts to load image Delay on network Load some more of the image Time for some word processing Thread 2 Thread 1 Figure 15.1 Two threads sharing the processor.
Developing J2ME Applications Mobile and Wireless Networks.
Java 2 Platform, Micro Edition (J2ME) By Xiaorong Wang.
Java: Animation Chris North cs3724: HCI. Animation? Changing graphics over time Examples: cartoons Clippy, agents/assistants Hour glass Save dohicky Progress.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 Using the KToolbar Rob Pooley
1 Identifiers  Identifiers are the words a programmer uses in a program  An identifier can be made up of letters, digits, the underscore character (
J2ME: M3G/11 Intro to J2ME. Prog. v Objectives: –to introduce M3G; –to start talking about "M3G Chapter 2. An Animated Model" u leave the floor,
Chapter 15 Multithreading F Threads Concept  Creating Threads by Extending the Thread class  Creating Threads by Implementing the Runnable Interface.
Programming for WWW (ICE 1338) Lecture #7 Lecture #7 July 14, 2004 In-Young Ko iko.AT. icu.ac.kr Information and Communications University (ICU) iko.AT.
Internet Software Development Applets Paul J Krause.
PROGARMMING THROUGH JAVA Presentation on IMAGES Group No:3 Presented By: Anthony Narzary (DC2012MCA0002) Chandra Gupta Bora (DC2012MCA0009) Dipankar Saikia.
Online Appointment Book Implement a Client/Server application for an online appointment book. Client should be a Graphical User Interface application.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 13 lcdui and OXO Rob Pooley
tiled Map Case Study: Rendering with JPanel © Allan C. Milne v
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 14 Various MIDlet examples Rob Pooley
망고 100 보드로 놀아보자 -18 Android 메뉴 생성 및 아이콘 생성 (SPDIF,WM8960)
Lecture 16: Multithreaded Programming. public partial class Form1 : Form { Thread ct; Thread rt; public static int circle_sleep = 0; public static int.
Threads in Java. Processes and Threads Processes –A process has a self-contained execution environment. –Has complete set of runtime resources including.
GUI 프로그래밍과 AWT(2) 컴퓨터 공학실험 (I) 인공지능 연구실. 2 AWT Event Model  Java 의 Event Model 1.Event : 사용자가 Program 에 가한 행동 2.Event Source : Event 가 일어난 근원 3.Event.
CSE 219 Computer Science III Image Manipulation. HW 1 Has been posted on Blackboard Making a Game of Life with limited.
5-1. 캔버스 천안천일고등학교 류빈 1.Canvas 와 Paint 객체를 통해 화면에 원하는 도형을 그리고 속성을 변경하는 기본적인 방법에 대해 소개 한다. 2. 토스트로 메시지를 출력하는 방법과 스피커를 통해 소리를 출력하는 방법에.
User Interface Summary Displayable ScreenCanvas FormAlertListTextbox Item DateFieldImageItemTextFieldStringItemGaugeChoiceGroup.
스레드 프로그래밍 Lecture #7.
Threading and Concurrency COM379T John Murray –
모바일 자바 프로그래밍 MIDP RMS Ps lab 오민경. MIDP RMS  RMS (Record Management System)  MIDP 에서 정의하는 영속성을 지닌 자체 데이터 저장 공간  Record Store 의 집합으로 구성된 아주 간단한 데이터베이스.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting.
CHAP 8. 그래픽.
영상 획득 영상 저장 카메라 파라메터 커스텀 이미지
Multimedia Programming 04: 점, 선, 면
목차 한국기술교육대학교 강사: 김 영 준 ㈜헬로앱스 1일차 아두이노 제어 실습
Multithreading and Garbage Collection Session 16.
Custom Widget 2 UNIT 27 로봇 SW 콘텐츠 교육원 조용수. 학습 목표 Custom Widget –Canvas 를 이용하여 Custom Widget 을 만든다. 2.
Visual C 실전 예제 Drawing Tool.
방명록 제작. 목차  기본 레이아웃  DB 구조  방명록 구조  코드 설명  화면 설명.
CHAP 14. 프로세스와 스레드. © 2012 생능출판사 All rights reserved 다중 스레딩 하나의 애플리케이션이 동시에 여러 가지 작업을 하 는 것 이들 작업은 스레드 (thread) 라고 불린다.
1 Introduction to J2ME Outline MIDP Building J2ME Apps- Tool J2ME Wireless Toolkit Demo MIDlet Programming -- MIDlet Transition States -- Midlet Skeleton.
Java Applets Adding Animation. Import Files You still need to include the same files: –import java.applet.*; –import java.awt.*;
Chapter 13: Multithreading The Thread class The Thread class The Runnable Interface The Runnable Interface Thread States Thread States Thread Priority.
게임 API 프로그래밍 Lecture #12. 강의 목차 ▶ 모바일 게임 프로그래밍에 필요한 게임 API 의 개념을 이해 한다. ▶ 주요 게임 API 의 종류와 기본 사용법을 익힌다. ▶ 게임 API 를 이용해 실제 게임 동작을 직접 구현해 본다. 2Mobile Programming.
1 Visual C 영상처리 프로그램 (MDI) BMP 파일 불러오기 이미지 픽셀 다루기.
CHAP 7. 메뉴와 대화상자. © 2012 생능출판사 All rights reserved 메뉴의 종류 옵션 메뉴 : 사용자가 MENU 키를 누를 때 나타난다. 컨텍스트 메뉴 : 컨텍스트 메뉴는 사용자가 화면을 일정 시간 이상으로 길게 누르면 나타나는 메뉴이다.
아주대학교 LifecareScienceLAB Android Seminar 2 nd class Android Software Development 2011/04/13 – p.m. 06:00 – 팔달관 409 호 아주대학교.
Chapter 11: Threaded Programs Situations where the program is following multiple execution paths (how to stop one?) Thread: a line of execution Thread.
 Linux-2.6.x/drivers/input/touchscreen  드라이버를 변경하여 Mouse mode 에서 그림을 그리도록 하자.
모 바 일 임 작 한국 IT 전문학교 박재성 게 제. 7 장 Flying Owl 모 바 일 임 작 게 제.
C 프로그래밍 개발 도구. 컴파일러 gnu c compiler 컴파일 gcc sample.c 실행 a.out 실행 파일 지정 컴파일 gcc –o sample sample.c 실행 sample.
J2ME Programming. Java2 Micro edition Introduction 년 5 월 26 일 CLDC, MIDP 라이브러리 Reference :
CHAP 8. 그래픽. © 2012 생능출판사 All rights reserved 안드로이드에서의 그래픽 XML 파일로 그래픽이나 애니메이션을 정의한다. 그 리는 작업은 안드로이드 시스템이 담당한다. onDraw() 메소드 안에 draw...() 와 같은 메소드를 호.
JAVA 실습 6 주차 Jin-Ho, Jang M.S. Hanyang Univ. HPC&OT Lab. 1HPC & OT Lab.
CSE403: MIDlets and Ant1 MIDlets and Ant April 3, 2003 Shane Cantrell Zach Crisman.
The Record Store ( ) Frank Ducrest. The Record Store 2 The Record Store provides persistence of data between MIDlet runs not quite a DBMS API.
Java N Amanquah.
Kjava Programming.
null, true, and false are also reserved.
JavaScript Reserved Words
Java for Mobile Devices
Agenda Types and identifiers Practice Assignment Keywords in Java
Presentation transcript:

실전 이미지 처리 프로그래밍 Lecture #10

강의 목차 ▶ 실제 게임을 구현하는 데 필요한 화면 구성을 알아본다. ▶ Canvas 클래스와 Graphics 클래스를 이용해 가장 기본적인 게임 화면을 하나씩 직접 구현해 본다. 2Mobile Programming

이미지 처리 개요 (1) ▶ 모바일 게임의 주요 화면 예 3Mobile Programming (e) 게임 로딩 (f) 게임 시작 I (g) 게임 시작 II (h) 게임 시작 III (a) 로고 (b) 공지사항 (c) 게임 타이틀 (d) 메인 메뉴

이미지 처리 개요 (2) ▶ 이미지 처리 관련된 화면 프로그래밍 ▷ (a) 로고 ▷ (b) 공지사항 ▷ (e) 게임 로딩 4Mobile Programming

게임 타이틀 화면 제작 (1) ▶ 로고가 조금씩 나타나는 애니메이션 형식의 로고 화면 ▶ 필요 기능 및 리소스 ▷ 로고 이미지 생성하고 그리기 ▷ 스레드 처리하기 ▷ 색상 및 도형 그리기 ▷ 리소스 : (logo.png 파일 ) 5Mobile Programming

게임 타이틀 화면 제작 (2) ▶ 이미지 생성 ▷ Image 클래스의 createImage( ) 메소드 이용 try { logo_img = Image.createImage("/images/title/logo.png"); // 로고 } catch(IOException e) { System.out.println(" 이미지 파일을 생성할 수 없습니다."); } ▷ 예외 처리 IOException try ~ catch 문 이용 6Mobile Programming

게임 타이틀 화면 제작 (3) ▶ 이미지 그리기 ▷ Graphics 클래스의 drawImage( ) 메소드 이용 g.drawImage(logo_img, getWidth( )/2, getHeight( )/2, Graphics.VCENTER | Graphics.HCENTER); ▶ 스레드 처리하기 ▷ 로고 이미지 반복 처리 ▷ 스레드 처리 과정 ➊ Runnable 인터페이스 구현 [ 예제 8-2] 의 05 행 ➋ 스레드 객체 변수 선언 [ 예제 8-2] 의 08 행 ➌ 스레드 생성 [ 예제 8-2] 의 20 행 ➍ thread.start( ); 호출 [ 예제 8-2] 의 21 행 ➎ run( ) 호출 [ 예제 8-2] 의 23~32 행 7Mobile Programming

게임 타이틀 화면 제작 (4) ➊ Runnable 인터페이스 구현 public class LogoCanvas extends Canvas implements Runnable { ➋ 스레드 객체 변수 선언 private Thread thread; ➌ 스레드 생성 thread = new Thread(this); ➍ thread.start( ); 호출 thread.start( ); ➎ run( ) 호출 public void run( ) { while(true) { try { thread.sleep(200); } catch(InterruptedException e) { System.out.println(e); } repaint( ); // paint( ) 호출 } 8Mobile Programming

게임 타이틀 화면 제작 (5) ▶ 색상 지정하기 g.setColor(255, 255, 255); ▷ 흰색이 지정되어 이후의 그래픽은 모두 흰색으로 처리 ▷ 다른 색으로 처리하고 싶으면 원하는 색상을 다시 지정 ▶ 도형 그리기 g.fillRect(0, 0, getWidth(), getHeight()); ▷ 화면 전체를 흰색으로 채움 9Mobile Programming

게임 타이틀 화면 제작 (6) 10Mobile Programming 01 import javax.microedition.midlet.*; 02 import javax.microedition.lcdui.*; public class LoadingMIDlet extends MIDlet { 05 private Display hiddenDisplay = null; 06 private LoadingCanvas hiddenCanvas = null; 07 public LoadingMIDlet( ) { 08 hiddenDisplay = Display.getDisplay(this); 09 hiddenCanvas = new LoadingCanvas( ); 10 } 11 final public void startApp( ){ 12 hiddenDisplay.setCurrent(hiddenCanvas); 13 } 14 final public void pauseApp( ) { } 15 final public void resumeApp( ){ } 16 final public void destroyApp(boolean flag) { 17 } 18 final public void quit( ) { 19 destroyApp(false); 20 notifyDestroyed( ); 21 } 22 } [ 예제 8-1] LoadingMIDlet.java

게임 타이틀 화면 제작 (7) 11Mobile Programming 01 import javax.microedition.lcdui.*; 02 import java.io.*; 03 import javax.microedition.media.*; public class LogoCanvas extends Canvas implements Runnable { 06 private int logoCount; 07 private byte gameState; 08 private Thread thread; 09 private Image logo_img; 10 static final byte g_LOGO = 1; public LogoCanvas( ) { try { 15 logo_img = Image.createImage("/images/title/logo.png"); // 로고 16 } catch(IOException e) { 17 System.out.println(" 이미지 파일을 생성할 수 없습니다."); 18} [ 예제 8-2] LogoCanvas.java

게임 타이틀 화면 제작 (8) 12Mobile Programming 19 gameState = g_LOGO; 20 thread = new Thread(this); 21 thread.start( ); // run( ) 호출 22 } 23 public void run( ) { 24 while(true){ 25 try{ 26 thread.sleep(200); 27 }catch(InterruptedException e){ 28 System.out.println(e); 29 } 30 repaint( ); // paint( ) 호출 31 } 32} 33 public void paint(Graphics g) { 34 if(gameState == g_LOGO) { 35 draw_logo(g); 36 } 37 } [ 예제 8-2] LogoCanvas.java

게임 타이틀 화면 제작 (9) 13Mobile Programming 38 public void draw_logo(Graphics g) { 39 g.setColor(255,255,255); // 흰색 40 g.fillRect(0, 0, getWidth( ), getHeight( )); // 전체 화면을 흰색으로 41 g.drawImage(logo_img, getWidth( )/2, getHeight( )/2, Graphics.VCENTER | Graphics.HCENTER); 42 int x = getWidth( )/2 - logo_img.getWidth( )/2; 43 int y = getHeight( )/2 - logo_img.getHeight( )/2; 44 g.fillRect(x, y, logo_img.getWidth( ), logo_img.getHeight( )/2-logoCount); 45 g.fillRect(x, getHeight( )/2+logoCount, logo_img.getWidth( ), logo_img.getHeight( )/2-logoCount); 46 if(logoCount < logo_img.getHeight( )/2) logoCount+=1; 47 } 48 } [ 예제 8-2] LogoCanvas.java

공지사항 화면 제작 (1) ▶ 공지사항 화면 제작 ▶ 필요 기능 및 리소스 ▷ 이미지 그리기 ▷ 문자열 그리기 ▷ 이벤트 처리 ▷ 리소스 : 배경 이미지 (bg_img.png 파일 ) 14Mobile Programming

공지사항 화면 제작 (2) ▶ 이미지 그리기 bg_img = Image.createImage("/images/title/bg_img.png"); // 배경... g.drawImage(bg_img, getWidth( )/2, getHeight( )/2, Graphics.VCENTER | Graphics.HCENTER); g.setColor(0, 255, 0); g.fillRect(25, 25, getWidth( )-50, getHeight( )-50); ▷ 배경 이미지 생성 ▷ 배경 이미지 그리기 ▷ 색상 지정 : 녹색 ▷ 녹색 사각형 가로 : getWidth( )-50 세로 : getHeight( )-50 ▷ [ 예제 8-3] 의 24 행, 65~67 행 참조 15Mobile Programming

공지사항 화면 제작 (3) ▶ 문자열 그리기 } else if(gameState == g_NOTICE) { draw_notice(g);... public void draw_notice(Graphics g) {... g.drawString(explainText[6], getWidth()/2, y+50, Graphics.TOP | Graphics.HCENTE R); ▷ 예제 ~48 행, 62 행, 80 행 참조 16Mobile Programming

공지사항 화면 제작 (4) ▶ 이벤트 처리하기 ▷ 명령어 이벤트 처리 소프트 버튼 이용 화면을 이동시키는데 이용 CommandListener 인터페이스를 이용 commandAction() 메소드를 호출해 처리 ▷ 키 이벤트 처리 상하 좌우 버튼 중앙의 FIRE 키 몇 개의 게임 키를 이용 getGameAction() 메소드를 호출해 처리 –keyPressed(int keyCode) –keyReleased(int keyCode) –keyRepeated(int keyCode) 17Mobile Programming

공지사항 화면 제작 (5) ▶ 키 이벤트 처리 예 public void keyPressed(int keyCode) { int gameAction = getGameAction(keyCode); switch(gameAction) { case UP:... break; case DOWN:... break; case LEFT:... break; case RIGHT:... break; default:... break; } ▷ keyPressed() 메소드를 이용 사용자가 선택한 keyCode 값을 가져온다. ▷ getGameAction() 메소드를 이용 keyCode 에 매핑되는 gameAction 값을 가져온다. ▷ gameAction 값에 따라 게임 동작 구현 18Mobile Programming

공지사항 화면 제작 (6) 19Mobile Programming 01 import javax.microedition.lcdui.*; 02 import javax.microedition.media.*; 03 import java.io.*; public class NoticeCanvas extends Canvas implements Runnable { 06 private int logoCount; 07 private byte gameState; 08 private Thread thread; 09 private Image logo_img; 10 private Image bg_img; 11 static final byte g_LOGO = 1; 12 static final byte g_NOTICE = 2; 13 static final byte g_LOADING = 3; 14 private Font largeFont; 15 private Font italicFont; 16 String explainText[] = {" ", " 이 게임은 이용 시 ", " 별도의 비용이 ", " 발생하지 않는 단동형 ", " 게임입니다.", " 안심하고 이용하세요.", " 아무 키나 누르세요."}; 17 /* 이벤트 처리 */ 18 private boolean isKeyPressed = false; 19 private int keyCode; 20 [ 예제 8-3] NoticeCanvas.java

공지사항 화면 제작 (7) 20Mobile Programming 21 public NoticeCanvas( ) { 22 try { 23 logo_img = Image.createImage("/images/title/logo.png"); // 로고 24 bg_img = Image.createImage("/images/title/bg_img.png"); // 배경 25 } catch(IOException e) { 26 System.out.println(" 이미지 파일을 생성할 수 없습니다."); 27 } 28 largeFont = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_LARGE); 29 italicFont = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC | Font.STYLE_UNDERLINED, Font.SIZE_LARGE); 30 gameState = g_LOGO; 31 thread = new Thread(this); 32 thread.start( ); // run( ) 호출 33 } 34 public void run( ) { 35 while(true) { 36 try { 37 thread.sleep(200); 38 } catch(InterruptedException e) { 39 System.out.println(e); 40 } 41 repaint( ); // paint( ) 호출 42 } 43 } [ 예제 8-3] NoticeCanvas.java

공지사항 화면 제작 (8) 21Mobile Programming 44 public void paint(Graphics g) { 45 if(gameState == g_LOGO) { 46 draw_logo(g); 47 } else if(gameState == g_NOTICE) { 48 draw_notice(g); 49 } 50 } 51 public void draw_logo(Graphics g) { 52 g.setColor(255, 255, 255); // 흰색 53 g.fillRect(0, 0, getWidth( ), getHeight( )); // 전체 화면을 흰색으로 54 g.drawImage(logo_img, getWidth( )/2, getHeight( )/2, Graphics.VCENTER | Graphics.HCENTER); 55 int x = getWidth( )/2 - logo_img.getWidth( )/2; 56 int y = getHeight( )/2 - logo_img.getHeight( )/2; 57 g.fillRect(x, y, logo_img.getWidth( ), logo_img.getHeight( )/2-logoCount); 58 g.fillRect(x, getHeight( )/2+logoCount, logo_img.getWidth( ), logo_img.getHeight( )/2-logoCount); 59 if(logoCount < logo_img.getHeight( )/2) logoCount+=1; 60 else gameState = g_NOTICE; 61 } [ 예제 8-3] NoticeCanvas.java

공지사항 화면 제작 (9) 22Mobile Programming 62 public void draw_notice(Graphics g) { 63 g.setColor(255, 255, 255); 64 g.fillRect(0, 0, getWidth( ), getHeight( )); 65 g.drawImage(bg_img, getWidth( )/2, getHeight( )/2, Graphics.VCENTER | Graphics.HCENTER); 66 g.setColor(0, 255, 0); 67 g.fillRect(25, 25, getWidth( )-50, getHeight( )-50); 68 g.setColor(255, 0, 0); 69 g.setFont(largeFont); 70 g.drawString(explainText[0], getWidth( )/2, 35, Graphics.TOP | Graphics.HCENTER); 71 g.setColor(0, 0, 0); 72 int y = 85; 73 g.setFont(italicFont); 74 for(byte i=1; i < explainText.length-1; i++) { 75 g.drawString(explainText[i], getWidth( )/2, y, Graphics.TOP | Graphics.HCENTER); 76 y+=20; 77 } [ 예제 8-3] NoticeCanvas.java

공지사항 화면 제작 (9) 23Mobile Programming 78 g.setColor(0, 0, 255); 79 g.setFont(largeFont); 80 g.drawString(explainText[6], getWidth( )/2, y+50, Graphics.TOP | Graphics.HCENTER); 81 if(isKeyPressed) { 82 switch(getGameAction(keyCode)) { 83 default: 84 gameState = g_LOADING; 85 } 86 } 87 } 88 public void keyPressed(int keyCode) { 89 isKeyPressed = true; 90 this.keyCode = keyCode; 91 } 92 } [ 예제 8-3] NoticeCanvas.java

게임로딩 화면 제작 (1) ▶ 모바일 게임 화면이 나타나는 순서 ▷ 로고 화면 → 공지사항 → 게임 타이틀 → 메인 메뉴 → 게임 로딩 → 게 임 시작 ▷ 게임 타이틀, 메인 메뉴, 게임 시작 화면 : 9 장에서 설명 ▶ 게임 로딩 화면을 만드는 이유 ▷ 게임을 초기화하는데 시간이 걸린다. 게임 시작 전 변수들의 초기값 설정 관련 이미지 생성 ▷ 지루함을 방지하려고 로딩 화면을 두게 된다. 24Mobile Programming

게임로딩 화면 제작 (2) ▶ 로딩 화면 ▶ 필요 기능 및 리소스 ▷ 로딩 애니메이션 ▷ 리소스 : (loading.png 파일 ) 25Mobile Programming

게임로딩 화면 제작 (3) ▶ 로딩 화면 예 01 public void draw_loading(Graphics g) { 02 g.setColor(0, 255, 0); 03 g.fillRect(0, 0, width, height); 04 g.drawImage(loading_img, width/2, height/2, Graphics.VCENTER | Graphics.HCENTER); 05 int x = width/2 - loading_img.getWidth( )/2; 06 int y = height/2 - loading_img.getHeight( )/2; 07 g.fillRect(x, y, loading_img.getWidth(), loading_img.getHeight()/2 - logoCount); 08 g.fillRect(x, height/2 + logoCount, loading_img.getWidth(), loading_img.getHeight( )/2 - logoCount); 09 if(logoCount < 7) logoCount += 1; 10 else logoCount + =2; 11 if(logoCount >= 18) { 12 gameState = g_NEXT; 13 logoCount = 0; 14 } 15 } 26Mobile Programming 01~15 행 : 로딩 애니메이션 화면 만들기. 02 행 : 현재 색상을 녹색으로 설정한다. 03 행 : 화면 전체를 녹색으로 설정한다. 04 행 : 로딩 이미지를 화면 중앙에 그린다. 05~06 행 : 화면 중앙에 위치한 로딩 이미지의 좌측 상단 X, Y 좌표 값을 계산한다. 07~10 행 : logoCount 값이 0 부터 6 까지는 1 씩, 7 에서 18 까지는 2 씩 증가시키면서 화면 중앙부터 로딩 이미지가 조금씩 나타나게 한다. 11~14 행 : 로딩 이미지가 화면에 다 나타나면, 게임 시작 화면이 나타나도록 gameState 를 g_READY_GO 로 변경한다.

게임로딩 화면 제작 (4) 27Mobile Programming 001 import javax.microedition.lcdui.*; 002 import javax.microedition.media.*; 003 import java.io.*; public class GameLoadingCanvas extends Canvas implements Runnable { 006 private int logoCount; 007 private byte gameState; 008 private Thread thread; 009 private Image logo_img; 010 private Image loading_img; 011 private Image bg_img; 012 static final byte g_LOGO = 1; 013 static final byte g_NOTICE = 2; 014 static final byte g_LOADING = 3; 015 static final byte g_NEXT = 4; 016 private Font largeFont; 017 private Font italicFont; 018 String explainText[] = {" ", " 이 게임은 이용 시 ", " 별도의 비용이 ", " 발생하지 않는 단동형 ", " 게임입니다.", " 안심하고 이용하세요.", " 아무 키나 누르세요."}; [ 예제 8-4] GameLoadingCanvas.java

게임로딩 화면 제작 (5) 28Mobile Programming 019 /* 이벤트 처리 */ 020 private boolean isKeyPressed = false; 021 private int keyCode; 022 private int width, height; public GameLoadingCanvas( ) { 025 width = getWidth( ); 026 height = getHeight( ); 027 try { 028 logo_img = Image.createImage("/images/title/logo.png"); // 로고 029 bg_img = Image.createImage ("/images/title/bg_img.png"); // 배경 030 loading_img = Image.createImage("/images/menu/loading.png"); // 로딩 031 } catch (IOException e) { 032 System.out.println(" 이미지 파일을 생성할 수 없습니다."); 033 } 034 largeFont = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_PLAIN, Font.SIZE_LARGE); 035 italicFont = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC | Font.STYLE_UNDERLINED, Font.SIZE_LARGE); 036 gameState = g_LOGO; 037 thread = new Thread(this); 038 thread.start( ); // run( ) 호출 039 } [ 예제 8-4] GameLoadingCanvas.java

게임로딩 화면 제작 (6) 29Mobile Programming 040 public void run( ) { 041 while(true) { 042 try { 043 Thread.sleep(200); 044 } catch(InterruptedException e) { 045 System.out.println(e); 046 } 047 repaint( ); // paint( ) 호출 048 } 049 } 050 public void paint(Graphics g) { 051 if(gameState == g_LOGO) { 052 draw_logo(g); 053 } else if(gameState == g_NOTICE) { 054 draw_notice(g); 055 } else if(gameState == g_LOADING) { 056 draw_loading(g); 057 } 058 } [ 예제 8-4] GameLoadingCanvas.java

게임로딩 화면 제작 (7) 30Mobile Programming 059 public void draw_logo(Graphics g) { 060 g.setColor(255, 255, 255); // 흰색 061 g.fillRect(0, 0, getWidth( ), getHeight( )); // 전체 화면을 흰색으로 062 g.drawImage(logo_img, getWidth( )/2, getHeight( )/2, Graphics.VCENTER | Graphics.HCENTER); 063 int x = getWidth( )/2 - logo_img.getWidth( )/2; 064 int y = getHeight( )/2 - logo_img.getHeight( )/2; 065 g.fillRect(x, y, logo_img.getWidth( ), logo_img.getHeight( )/2-logoCount); 066 g.fillRect(x, getHeight( )/2+logoCount, logo_img.getWidth( ), logo_img.getHeight( )/2-logoCount); 067 if(logoCount < logo_img.getHeight( )/2) logoCount+=1; 068 else gameState = g_NOTICE; 069 } 070 public void draw_notice(Graphics g) { 071 g.setColor(255, 255, 255); 072 g.fillRect(0, 0, getWidth( ), getHeight( )); 073 g.drawImage(bg_img, getWidth( )/2, getHeight( )/2, Graphics.VCENTER | Graphics.HCENTER); 074 g.setColor(0, 255, 0); 075 g.fillRect(25, 25, getWidth( )-50, getHeight( )-50); 076 g.setColor(255, 0, 0); [ 예제 8-4] GameLoadingCanvas.java

게임로딩 화면 제작 (8) 31Mobile Programming 077 g.setFont(largeFont); 078 g.drawString(explainText[0], getWidth( )/2, 35, Graphics.TOP | Graphics.HCENTER); 079 g.setColor(0, 0, 0); 080 int y = 85; 081 g.setFont(italicFont); 082 for(byte i=1; i < explainText.length-1; i++) { 083 g.drawString(explainText[i], getWidth( )/2, y, Graphics.TOP | Graphics.HCENTER); 084 y+=20; 085 } 086 g.setColor(0, 0, 255); 087 g.setFont(largeFont); 088 g.drawString(explainText[6], getWidth( )/2, y+50, Graphics.TOP | Graphics.HCENTER); 089 if(isKeyPressed) { 090 switch(getGameAction(keyCode)) { 091 default: 092 gameState = g_LOADING; 093 } 094 } 095 } [ 예제 8-4] GameLoadingCanvas.java

게임로딩 화면 제작 (9) 32Mobile Programming 096 public void draw_loading(Graphics g) { 097 g.setColor(0, 255, 0); 098 g.fillRect(0, 0, width, height); 099 g.drawImage(loading_img, width/2, height/2, Graphics.VCENTER|Graphics.HCENTER); 100 int x = width/2 - loading_img.getWidth( )/2; 101 int y = height/2 - loading_img.getHeight( )/2; 102 g.fillRect(x, y, loading_img.getWidth( ), loading_img.getHeight( )/2 - logoCount); 103 g.fillRect(x, height/2+logoCount, loading_img.getWidth( ), loading_img.getHeight( )/2-logoCount); 104 if(logoCount < 7) logoCount += 1; 105 else logoCount+=2; 106 if(logoCount >= 18) { 107 gameState = g_NEXT; 108 logoCount = 0; 109 } 110 } 111 public void keyPressed(int keyCode) { 112 isKeyPressed = true; 113 this.keyCode = keyCode; 114 logoCount = 0; 115 } 116 } [ 예제 8-4] GameLoadingCanvas.java