LibBlade.java
package game.pak;
import game.CGame;
import game.config.dConfig;
import java.util.ArrayList;
import java.util.List;
import android.util.Log;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.cl.libgdxjar.LibgdxGraphics;
import com.clmobi.SinCity.en.EngineActivity;
import com.clmobi.SinCity.en.MyGame;
public class LibBlade {
static List<Point> pointTouch;
LibgdxGraphics gl_touchBack;
LibgdxGraphics gl_touch;
SpriteBatch touchBackBatch;
SpriteBatch touchBatch;
final static int RemPointNum=12;
public static int pointerXX, pointerYY;
public LibBlade(){
touchBackBatch=new SpriteBatch(); //实例化
touchBatch=new SpriteBatch(); //实例化
gl_touchBack= new LibgdxGraphics(touchBackBatch);
gl_touch= new LibgdxGraphics(touchBatch);
pointTouch = new ArrayList<Point>(RemPointNum);
}
public void draw() {
GL10 gl = Gdx.graphics.getGL10();
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
drawTouch();
}
public void drawTouch() {
for (int i = 0; i < pointTouch.size(); i++) {
if (i != 0) {
int addX;
int addY;
int startX = pointTouch.get(i - 1).x;
int startY = pointTouch.get(i - 1).y;
int stopX = pointTouch.get(i).x;
int stopY = pointTouch.get(i).y;
addX = getXY(stopX - startX, stopY - startY)[0];
addY = getXY(stopX - startX, stopY - startY)[1];
stopY += addY;
stopX += addX;
gl_touchBack.setColor(0xff8a9cae);
gl_touch.setColor(0xffffffff);//0xffffffff 0xff8a9cae
if (i > (pointTouch.size() / 2)) {
float width = (pointTouch.size() - i) * 3f + 3;
if (width > 15) {
width = 15;
}
if(width<1){
width=1;
}
gl_touchBack.setLineWidth((int)width+1);
width = (pointTouch.size() - i) * 2f;
if (width > 10) {
width = 10;
}
if(width<1){
width=1;
}
gl_touch.setLineWidth((int)width);
} else {
float width = i * 3f + 3;
if (width > 15) {
width = 15;
}
if(width<1){
width=1;
}
gl_touchBack.setLineWidth((int)width+1);
width = i * 2f;
if (width > 10) {
width = 10;
}
if(width<1){
width=1;
}
gl_touch.setLineWidth((int)width);
}
gl_touchBack.drawLineWidth2(startX, startY, stopX, stopY,10);
gl_touch.drawLineWidth2(startX, startY, stopX, stopY,10);
}
if(i<=pointTouch.size()-1){
pointTouch.get(i).time++;
if (pointTouch.get(i).time > 7)
pointTouch.remove(i);
}
}
}
public int[] getXY(int x, int y) {
int addY = (int) (3 * y / Math.sqrt(y * y + x * x));
int addX = (int) (3 * x / Math.sqrt(y * y + x * x));
int[] rt = new int[2];
rt[0] = addX;
rt[1] = addY;
return rt;
}
public void touchDown(){
pointTouch.clear();
}
public void touchDragged(int arg0, int arg1, int arg2){
pointerXX = (int) arg0 * dConfig.S_WIDTH / EngineActivity.ScreenW;
pointerYY = (int) arg1 * dConfig.S_HEIGHT / EngineActivity.ScreenH;
Point point = new Point(pointerXX, pointerYY);
if (pointTouch.size() > RemPointNum) {
pointTouch.remove(0);
}
pointTouch.add(point);
}
public void touchUp(){
pointTouch.clear();
}
}
class Point {
public int x;
public int y;
public int time;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getTime() {
return time;
}
public void setTime(int time) {
this.time = time;
}
}