startfinish.java

来自「Programming java 2 microedition symbian 」· Java 代码 · 共 62 行

JAVA
62 行
字号
/*
 * Copyright 2003, 2004 Symbian Ltd.
 * For License terms see http://www.symbian.com/developer/techlib/codelicense.html
 */

package demoracer;

/**
 * <p>Title: DemoRacer</p>
 * <p>Description: Game API Demo for Symbian MIDP 2.0 Book.</p>
 * @author Alan Newman - alan@sensibledevelopment.net
 * @version 1.0
 */


 /*
  * This is a rather simple Sprite class which forms the StartFinish line graphic.
  * This has been separated from the tiled background to allow for collision detection.
  */
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

public class StartFinish extends Sprite {
    // set the frame set dimensions
    static final int FRAME_COLS=1;
    static final int FRAME_WIDTH=1;
    private int xInitial;
    private int yInitial;
    private int frequency;
    private boolean lapComplete=false;
    
    public StartFinish(Image image, int width, int height, int x, int y) {
        super(image,width,height);
        this.setPosition(x,y);
        xInitial=x;
        yInitial=y;
        frequency = 4*Background.TILE_WIDTH;
    }
    
    public boolean getLapComplete(){return lapComplete;}
    public void setLapComplete(boolean bln){lapComplete=bln;}
    
    // move the start finish line from right to left along with the tiled background.
    public void tick() {
        if (frequency == 0) {
            setPosition(xInitial, yInitial);
            frequency = 4*Background.TILE_WIDTH;
        } else{
            move(Background.xMove, Background.yMove);
        }
        
        // set to invisible if the sprite is off screen.
        if(getX() + getWidth() <= 0) {//definitely outside Canvas clip area
            setVisible(false);
        } else {
            setVisible(true);
        }
        
        frequency--;
    }
    
}

⌨️ 快捷键说明

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