1 / 26

IIC3686 - Creación de Videojuegos

IIC3686 - Creación de Videojuegos. Programación de juegos en J2ME para celulares. Sebastián Montabone. Introducción. Java J2SE: Standard Edition J2EE: Enterprise Edition J2ME: Micro Edition Configuraciones Máquina virtual, interfaz de programación básica

shirlyn
Download Presentation

IIC3686 - Creación de Videojuegos

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. IIC3686 - Creación de Videojuegos Programación de juegos en J2ME para celulares Sebastián Montabone

  2. Introducción • Java • J2SE: Standard Edition • J2EE: Enterprise Edition • J2ME: Micro Edition • Configuraciones • Máquina virtual, interfaz de programación básica • Connected Limited Device Configuration (CLDC) • CLDC 1.1 • CLDC 1.0 • Connected Device Configuration (CDC)

  3. Introducción (cont.) • Perfiles • Interfaz de más alto nivel • Mobile Information Device Profile(MIDP) 1.0 • Mobile Information Device Profile(MIDP) 2.0 • Próximamente MIDP 3.0… • Cada celular implementa una configuración y un perfil • Esto define las posibilidades de programación que el desarrollador tiene disponible.

  4. Introducción (cont.) • MIDP1.0 • No tiene soporte para audio • No hay pintado de pantalla completa • No soporta transparencias • Conectividad sólo vía HTTP • Todos los celulares actuales soportan MIDP1.0 • MIDP2.0 • Soporte multimedia • Soporte para pintado a pantalla completa • Soporte para transparencias • Conectividad ampliada (HTTP, sockets, etc…) • Mejoras específicas para desarrollo de juegos • Sólo algunos celulares soportan MIDP2.0

  5. Programación en J2ME • Clases públicas • javax.microedition.midlet • startApp() • pauseApp() • destroyApp()

  6. Programación en J2ME (cont.) • Ciclo de vida de un MIDlet • Activo • El MIDlet está siendo ejecutado y tiene control sobre los recursos del sistema • Destruido • El MIDlet fue destruido por el AMS. Todos sus recursos han sido liberados. • Pausado • El MIDlet está corriendo en el fondo. No puede responder a ningún evento de la interfaz de usuario, pero puede ser devuelto a Activo por el AMS

  7. Programación en J2ME (cont.) • javax.microedition.lcdui.Display • Display representa a la pantalla LCD del celular • Display.getDisplay(MIDlet m) • Obtiene el Display asociado al MIDlet • Display.setCurrent(Displayable d) • Setea el objeto que se quiere desplegar en la pantalla LCD

  8. Programación en J2ME (cont.) • javax.microedition.lcdui.Displayable • Displayable representa un objeto que puede ser desplegado en la pantalla LCD • Displayable • Screen • Form • ChoiceGroup • DateField • ImageItem • Gauge • StringItem • TextField • Alert • List • TextBox • Canvas

  9. Programación en J2ME (cont.) • Displayable.setCommandListener(CommandListener cl) • Especifica quién interpretará los comandos recibidos por el objeto Displayable • El intérprete debe implementar el método abstracto CommandListener • Displayable.addCommand(Command c) • Agrega un comando a la pantalla • Displayable.removeCommand(Command c) • Elimina un comando de la pantalla

  10. Programación en J2ME (cont.) • Canvas permite interpretar el input del usuario • void keyPressed(int keycode) • void keyReleased(int keycode) • void keyRepeated(int keycode) • int getGameAction(int keycode) • Posee constantes para comparar • KEY_NUM0 • KEY_NUM9 • KEY_STAR • KEY_POUND • LEFT, RIGHT, UP, DOWN, FIRE • GAME_A, GAME_B, GAME_C, GAME_D

  11. Programación en J2ME (cont.) • La clase que extienda Canvas tiene que implementar el método abstracto Paint(Graphics g) • En esa función definimos lo que queremos pintar • Cada vez que queremos que se refresque la pantalla, llamamos al método repaint()

  12. Programación en J2ME (cont.) • setColor • setStrokeStyle • … • Graphics • drawImage • drawString • drawRect • drawRoundRect • drawLine • drawArc • fillRect • fillRoundRect • fillArc

  13. Programación en J2ME (cont.) • Game Loop • Leer Input del usuario • Simular el mundo (IA, colisiones, etc.) • Dibujar el resultado • Esperar para completar el tiempo del frame • Hasta ahora, todo lo visto se puede implementar en MIDP1.0

  14. Programación en J2ME (cont.) • Game API • javax.microedition.lcdui.game.* • GameCanvas • Layer • LayerManager • Sprite • TiledLayer • Sólo disponible desde MIDP2.0

  15. Programación en J2ME (cont.) • GameCanvas • Extiende a Canvas • Agrega un buffer fuera de pantalla • Permite hacer polling a las teclas • El método getGraphics() retorna el buffer • Al finalizar de pintar el frame fuera de la pantalla, se llama a flushGraphics() • setFullScreenMode(Boolean)

  16. Programación en J2ME (cont.) • GameCanvas • int getKeyStates() • UP_PRESSED • DOWN_PRESSED • LEFT_PRESSED • RIGHT_PRESSED • FIRE_PRESSED • Cómo usarlo? • keyStates=getKeyStates(); • If(keyStates & LEFT_PRESSED != 0) • Usuario presionó izquierda…

  17. Programación en J2ME (cont.) • Layer • Base para Sprite y TiledLayer • void setPosition(int x, int y) • void setVisible(int x, int y) • boolean isVisible() • void move(int dx, int dy) • int getHeight() • int getWidth() • int getX() • int getY()

  18. Programación en J2ME (cont.) • Sprite • Extiende Layer agregando animación, detección de colisión, transformaciones de imagen • Sprite(Image imagen) • Sprite(Image imagen, int frameWidth, int frame Height) • Sprite(Sprite s) • collidesWith(Image imagen, int x, int y, bool pixelLevel) • collidesWith(Sprite s, bool pixelLevel) • collidesWith(TiledLayer t, bool pixelLevel) • defineCollisionRectangle(int x, int y, int width, int height)

  19. Programación en J2ME (cont.) • Animación del Sprite • void setFrameSequence(int[] sequence) • Establece una secuencia a partir de los frames de la imagen original del sprite • int getFrameSequenceLength() • Retorna el número de frames que tiene la secuencia actual • int getRawFramesCount() • Retorna el número de frames que tiene la imagen original del sprite

  20. Programación en J2ME (cont.) • Animación del Sprite • void setFrame(int sequenceIndex) • Selecciona un frame en particular de la secuencia para el próximo paint del sprite • void nextFrame() • Selecciona el siguiente frame en la secuencia • void prevFrame() • Selecciona el frame anterior en la secuencia • int getFrame() • Retorna el número de frame dentro de la secuencia que está selecconado actualmente • void paint(Graphics g) • Pinta el Sprite. El pixel de referencia es el de arriba a la izquierda

  21. Programación en J2ME (cont.) • Transformaciones del Sprite • defineReferencePixel(getWidth()/2, getHeight()/2) • setTransform(transformación) • TRANS_NONE • TRANS_ROT90 • TRANS_ROT180 • TRANS_ROT270 • TRANS_MIRROR • TRANS_MIRROR_ROT90 • TRANS_MIRROR_ROT180 • TRANS_MIRROR_ROT270

  22. Programación en J2ME (cont.) • TiledLayer • TiledLayer(int columns, int rows, Image image, int tileWidth, int tileHeight) • Especifica las columnas y filas del fondo, imagen donde estás los tiles y sus dimensiones • Void setCell(int col, int row, int tileIndex) • Pinta en (col, row) con el tile tileIndex (parte de 1, el 0 es transparente) • Void fillCells(int col, int row, int numCols, int numRows, int tileIndex) • setCell pero en un rectángulo

  23. Programación en J2ME (cont.) • LayerManager • Sirve para pintar grupos de Layers • Void append(Layer l) • Void insert(Layer l, int index) • Int getSize() • Void remove(Layer l) • Void setViewWindow(int x, int y, int width, int height) • Void paint(Graphics g, int x, int y) • Layer getLayerAt(int index)

  24. Programación en J2ME (cont.) • Esperar para completar el tiempo del frame • 15 FPS o menos • Aprox. 70 milisegundos por frame elapsed=startTime; startTime=System.currentTimeMillis(); elapsed=startTime-elapsed; If(elapsed < MILLISECS_PER_FRAME) { thread.sleep(MILLISECS_PER_FRAME-elapsed); } Else { thread.yield(); }

  25. Links a sitios de desarrollo • Nokiahttp://forum.nokia.com/ • Siemens.http://www.siemens-mobile.com/developer • Sony Ericsson.http://developer.sonyericsson.com/ • Motorola.http://www.motocoder.com/

  26. Instalación • NetBeans 5.0 + J2SE v1.4.2.http://java.sun.com/j2se/1.4.2/download-netbeans-50.html • NetBeans Mobility Pack (incluye Wireless Toolkit 2.2).http://www.netbeans.org/products/mobility/ Extra: • Tabla comparativa de celulares con sus configuraciones, perfiles, y otros datos.http://developers.sun.com/techtopics/mobility/device/device

More Related