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

📄 frametrigger.java

📁 一个基于J2ME的pacman游戏
💻 JAVA
字号:
/**

 * PacMan for J2ME Devices

 * CS 327 - Design Project, Fall 2002

 * University of Illinois, Urbana-Champaign

 * 

 * file: FrameTrigger.java 

 * contact: Braden Kowitz

 * date: 11/24/02

 **/



//----------------------------------------------------------------------------//



import javax.microedition.lcdui.*;

import javax.microedition.midlet.*;





/**

 * This trigger is responsible for calling advanceFrame() on a GrameCanvas

 * object.

 **/

public class FrameTrigger extends Thread

{



	/**

	 * The GameCanvas where we call advanceFrame.

	 **/

	GameCanvas game_;	

	

	/**

	 * Time is miliseconds between frames

	 **/

	private int frameDelay_;



	/**

	 * Value which is true if the thread is to be stopped.

	 **/

	private boolean stopped;



	/**

	 * Constructor

	 * @param g Canvas for wich to trigger frame updates.

	 * @param frameDelay time in MS between frame updates.

	 **/

	public FrameTrigger(GameCanvas g, int frameDelay)

	{

		game_ = g;

		frameDelay_ = frameDelay;

		stopped = true;

	}



	/**

	 * Stops the trigger from functioning.

	 * (stops execution of the thread)

	 **/

	public void stopTrigger()

	{ stopped = true; }

	

	/**

	 * starts the trigger

	 */

	public void startTrigger()

	{ stopped = false; }



	/**

	 * Starts the trigger running.

	 * - To be called by the thead start() function call.

	 **/

	public void run()

	{

		//stopped=false; // having this might cause problems

		while (!stopped)

		{	

			game_.advanceFrame();

			try {

                    		sleep(frameDelay_);

                	} catch (InterruptedException ie) {}

		}

		System.out.println("FrameTrigger Thread Stopped");

	}



}

//----------------------------------------------------------------------------//

⌨️ 快捷键说明

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