Share
Introduction
If you're new, to see the first part, go here.Second part here.
Third part here.
Fourth part here.
Fifth part here.
The sixth part of this series will let you move the item you will add. As long as you touch the screen, you can change the position of the bitmap you want to add.
Graphics in Android - Part VI
We simply have to add a temporary class variable in our Panel class.
1 |
private GraphicObject _currentGraphic = null;
|
Modify our onTouchEvent() to behave differently for different motion events.
On ACTION_DOWN we will add a new GraphicObject to our temporary variable with the coordinates of the touch event.
On ACTION_MOVE we will change the coordinates of this temporary bitmap following our movement on the screen.
On ACTION_DOWN we will finally add the temporary bitmap to our ArrayList and null the currentGraphic variable.
We have no check for NullPointerExceptions because the order of the motion events is unchangeable. It should never happen that a ACTION_MOVE is triggered without an ACTION_DOWN triggered before. The same with ACTION_UP.
1 |
@Override |
Our onDraw() just draw what is added to the ArrayList, so we should change the method, too.
We will append a check if the _currentGraphic is null or not, if it is not null we will draw it.
1 |
@Override |
Don’t append logic to updatePhysics() because we don’t want the speed already working on our _currentObject. If you do it anyway you will notice weird behavior if you long touch the screen without moving your finger.
You can fin the full source code of this example below...
Byeee!!!
Go to the last Part (Part VII)





