⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gamecanvas.java

📁 现在大部分手机都不支持WTK2.0
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 * Rendering operations do not appear on the display until flushGraphics()	 * is called; flushing the buffer does not change its contents (the pixels	 * are not cleared as a result of the flushing operation).	 * <p>	 * A new Graphics object is created and returned each time this method is	 * called; therefore, the needed Graphics object(s) should be obtained	 * before the game starts then re-used while the game is running.	 * For each GameCanvas instance, all of the provided graphics objects will	 * render to the same off-screen buffer.	 * <P>	 * <P>The newly created Graphics object has the following properties:	 * </P>	 * <ul>	 * <LI>the destination is this GameCanvas' buffer;	 * <LI>the clip region encompasses the entire buffer;	 * <LI>the current color is black;	 * <LI>the font is the same as the font returned by	 * <A HREF="../../../../javax/microedition/lcdui/Font.html#getDefaultFont()"><CODE>Font.getDefaultFont()</CODE></A>;	 * <LI>the stroke style is <A HREF="../../../../javax/microedition/lcdui/Graphics.html#SOLID"><CODE>SOLID</CODE></A>; and	 * <LI>the origin of the coordinate system is located at the upper-left	 * corner of the buffer.	 * </ul>	 * <p>	 * 	 * @return the Graphics object that renders to this GameCanvas'  off-screen buffer	 * @see #flushGraphics()	 * @see #flushGraphics(int, int, int, int)	 */	//#if polish.blackberry		//# protected Graphics getPolishGraphics()	//#else	protected Graphics getGraphics()	//#endif	{		return this.bufferedImage.getGraphics();	}	/**	 * Gets the states of the physical game keys.  Each bit in the returned	 * integer represents a specific key on the device.  A key's bit will be	 * 1 if the key is currently down or has been pressed at least once since	 * the last time this method was called.  The bit will be 0 if the key	 * is currently up and has not been pressed at all since the last time	 * this method was called.  This latching behavior ensures that a rapid	 * key press and release will always be caught by the game loop,	 * regardless of how slowly the loop runs.	 * <p>	 * For example:	 * <code>	 * <pre>	 * 	 * // Get the key state and store it	 * int keyState = getKeyStates();	 * if ((keyState & LEFT_KEY) != 0) {	 * 		positionX--;	 * }	 * else if ((keyState & RIGHT_KEY) != 0) {	 * 		positionX++;	 * }	 * 	 * </pre>	 * </code>	 * <p>	 * Calling this method has the side effect of clearing any latched state.	 * Another call to getKeyStates immediately after a prior call will	 * therefore report the system's best idea of the current state of the	 * keys, the latched bits having been cleared by the first call.	 * <p>	 * Some devices may not be able to query the keypad hardware directly and	 * therefore, this method may be implemented by monitoring key press and	 * release events instead.  Thus the state reported by getKeyStates might	 * lag the actual state of the physical keys since the timeliness	 * of the key information is be subject to the capabilities of each	 * device.  Also, some devices may be incapable of detecting simultaneous	 * presses of multiple keys.	 * <p>	 * This method returns 0 unless the GameCanvas is currently visible as	 * reported by <A HREF="../../../../javax/microedition/lcdui/Displayable.html#isShown()"><CODE>Displayable.isShown()</CODE></A>.	 * Upon becoming visible, a GameCanvas will initially indicate that	 * all keys are unpressed (0); if a key is held down while the GameCanvas	 * is being shown, the key must be first released and then pressed in	 * order for the key press to be reported by the GameCanvas.	 * <p>	 * 	 * @return An integer containing the key state information (one bit per  key), or 0 if the GameCanvas is not currently shown.	 * @see #UP_PRESSED	 * @see #DOWN_PRESSED	 * @see #LEFT_PRESSED	 * @see #RIGHT_PRESSED	 * @see #FIRE_PRESSED	 * @see #GAME_A_PRESSED	 * @see #GAME_B_PRESSED	 * @see #GAME_C_PRESSED	 * @see #GAME_D_PRESSED	 */	public int getKeyStates()	{		int states = this.keyStates;	    this.keyStates &= ~this.releasedKeys;	    this.releasedKeys = 0;	    return states;	}	//#ifdef tmp.extendsPolishScreen		//# public void paintScreen( Graphics g)	//#else	/**	 * Paints this GameCanvas.  By default, this method renders the	 * the off-screen buffer at (0,0).  Rendering of the buffer is	 * subject to the clip region and origin translation of the Graphics	 * object.	 * 	 * @param g the Graphics object with which to render the screen.	 * @throws NullPointerException if g is null	 * @see Canvas#paint(Graphics) in class Canvas	 */	public void paint( Graphics g)	//#endif	{		//#if tmp.extendsPolishScreen && polish.FullCanvasSize:defined			//#= g.setClip( 0, 0, ${polish.FullCanvasWidth}, ${polish.FullCanvasHeight} );		//#endif		if (this.setClip) {			g.clipRect( this.clipX, this.clipY, this.clipWidth, this.clipHeight);			this.setClip = false;		}		g.drawImage(this.bufferedImage, 0, 0, Graphics.TOP | Graphics.LEFT );	}	/**	 * Flushes the specified region of the off-screen buffer to the display.	 * The contents of the off-screen buffer are not changed as a result of	 * the flush operation.  This method does not return until the flush has	 * been completed, so the app may immediately begin to render the next	 * frame to the same buffer once this method returns.	 * <p>	 * If the specified region extends beyond the current bounds of the	 * GameCanvas, only the intersecting region is flushed.  No pixels are	 * flushed if the specified width or height is less than 1.	 * <p>	 * This method does nothing and returns immediately if the GameCanvas is	 * not currently shown or the flush request cannot be honored because the	 * system is busy.	 * <p>	 * 	 * @param x the left edge of the region to be flushed	 * @param y the top edge of the region to be flushed	 * @param width the width of the region to be flushed	 * @param height the height of the region to be flushed	 * @see #flushGraphics()	 */	public void flushGraphics(int x, int y, int width, int height)	{		this.setClip = true;		this.clipX = x;		this.clipY = y;		this.clipWidth = width;		this.clipHeight = height;		//#if polish.Bugs.displaySetCurrentFlickers			MasterCanvas.instance.repaint();			MasterCanvas.instance.serviceRepaints();					//#else			repaint();			serviceRepaints();					//#endif	}	/**	 * Flushes the off-screen buffer to the display.  The size of the flushed	 * area is equal to the size of the GameCanvas.  The contents	 * of the  off-screen buffer are not changed as a result of the flush	 * operation.  This method does not return until the flush has been	 * completed, so the app may immediately begin to render the next frame	 * to the same buffer once this method returns.	 * <p>	 * This method does nothing and returns immediately if the GameCanvas is	 * not currently shown or the flush request cannot be honored because the	 * system is busy.	 * <p>	 * 	 * @see #flushGraphics(int,int,int,int)	 */	public void flushGraphics()	{		//#if polish.Bugs.displaySetCurrentFlickers			MasterCanvas.instance.repaint();			MasterCanvas.instance.serviceRepaints();					//#else			repaint();			serviceRepaints();					//#endif	}	//#ifdef tmp.extendsPolishScreen	protected boolean handleKeyPressed( int keyCode, int gameAction ) {		if (gameAction != 0) {			int bit = 1 << gameAction;			this.keyStates |= bit;	        this.releasedKeys &= ~bit;		}		return false;	}	//#else	protected void keyPressed(int keyCode) {		int gameAction = getGameAction(keyCode);		if (gameAction != 0) {			int bit = 1 << gameAction;			this.keyStates |= bit;	        this.releasedKeys &= ~bit;		}	}	//#endif		//#if polish.midp1 && !tmp.extendsPolishScreen		/* (non-Javadoc)	 * @see javax.microedition.lcdui.Canvas#setFullScreenMode(boolean)	 */	public void setFullScreenMode(boolean enable) {		// ignore call				}	//#endif			/* (non-Javadoc)	 * @see javax.microedition.lcdui.Canvas#keyReleased(int)	 */	public void keyReleased(int keyCode) {		int gameAction = getGameAction(keyCode);		if (gameAction != 0) {			this.releasedKeys |= 1 << gameAction;		}	}		//#if tmp.extendsPolishScreen &&  polish.useDynamicStyles		protected String createCssSelector() {		return "gamecanvas";	}	//#endif}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -