I’m new to AndEngine and I want to draw a line by using my finger coordinates in the onSceneTouchEvent I did all what I knew and I think its right but there is something that keeps it from working I don’t know what, I can’t detect the problem :/
private Scene scene;
float startX;
float startY;
float lastX;
float lastY;
int lineUsageCount = 0;
@Override
public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
switch (pSceneTouchEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
startX = pSceneTouchEvent.getX();
startY = pSceneTouchEvent.getY();
lineUsageCount = 0 ;
break;
case MotionEvent.ACTION_MOVE:
lineUsageCount++;
lastX = pSceneTouchEvent.getX();
lastY = pSceneTouchEvent.getY();
break;
case MotionEvent.ACTION_UP:
if (lineUsageCount <= 5) {
final Line line = new Line(startX, startY, lastX,
lastY, this.getVertexBufferObjectManager());
line.setLineWidth(1);
line.setColor(255, 255, 255);
scene.attachChild(line);
}
break;
}
return true;
}
};
it should get the first coordinates startX, startY and then on the Action_Move it gets the lastX, lastY and draw the line but it doesn’t seem to work 😐
Problem is in this line of code:
if (lineUsageCount <= 5) {While you move your finger,
lineUsageCountwill be much more then 5. Debug this variable and than change it in “IF” or remove this “IF” from your code.