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

📄 layer.java

📁 该源码实现了j2me中用midp1.0实现的midp2.0的game类
💻 JAVA
字号:
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Copyright(c) 2003-2004 Jordi Martin Perez
*/
package org.piratis.j2me.core.game;

import javax.microedition.lcdui.Graphics;

import org.piratis.j2me.core.BBox2D;


/**
 * Abstract class representing a visual element of a game. 
 * Each Layer has its Bounding Box (position plus width and height)
 * and visibility features. It is mandatory for subclasses to implement 
 * the paint(Graphics) method!<br>
 * <br>
 * Bear in mind that the layer's position is always relative to the Graphics 
 * coordinate system.
 * 
 * @author		Jordi Mart韓
 * @copyright	Copyright (c) 2003-2004
 * @created 	24-jun-2004
 * @version		$Id: Layer.java,v 1.2 2004/07/01 22:16:44 piratis Exp $
 */

public abstract class Layer
{
    public static int TOP_LEFT = Graphics.TOP | Graphics.LEFT;

    /**
     * Own's bbox (initially empty!)
     */
    protected BBox2D bbox = new BBox2D();
    
    /**
     * Visibility management
     */
    protected boolean visible = true;
    
    /**
     * Returns own bounding box, always in pixel values
     * @return the Layer's bounding box
     * @see BBox2D
     */
    public BBox2D getBbox()
    {
        return this.bbox;
    }
    
    /**
     * Gets the visibility of this layer
     * @return <code>true</code> if the layer is visible, <code>false</code>otherwise.
     */
    public boolean isVisible()
    {
        return this.visible;
    }
    /**
     * Sets the visibility of the layer. Will or won't be rendered according to
     * this property value.
     * @param newVisible <code>true</code> to make this layer visible, 
     * 	<code>false</code> otherwise.
     */
    public void setVisible(boolean newVisible)
    {
        this.visible = newVisible;
    }
    
    /**
     * Moves the current layer the given horizontal and vertical distances.
     * @param dx horizontal axis distance (positive to the right, negative to the left)
     * @param dy vertical axis distance (positive downwards, negative upwards)
     */
    public void moveBy(int dx, int dy)
    {
        this.bbox.x += dx;
        this.bbox.y += dy;
    }
    
    /**
     * Moves the layer's top-left corner at the given (x,y) coordinates
     * @param x the horizontal position
     * @param y the vertical position
     */
    public void moveTo(int x, int y)
    {
        this.bbox.x = x;
        this.bbox.y = y;
    }

    /**
     * Paints this layer if it is visible.<br>
     * <br>
     * Implementors are responsible of checking this condition before 
     * painting the layer: must do nothing when it is not visible. They must
     * also ensure that the attributes of the Graphics object are not modified
     * when returning from the call of this method!
     * 
     * @param g the graphics object for rendering this layer
     */
    public abstract void paint(Graphics g);
}

⌨️ 快捷键说明

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