I have tried some things in the touch event call but without any success.
Using java Syntax Highlighting
- @Override
- protected void onDraw(Canvas canvas) {
- canvas.drawColor(Color.WHITE);
- for(MenuButton menuButton : menuButtonSprites) {
- menuButton.onDraw(canvas);
- }
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- float x = event.getX();
- float y = event.getY();
- try {
- switch (event.getAction()) {
- case MotionEvent.ACTION_DOWN:
- synchronized (holder) {
- for(MenuButton mb : menuButtonSprites){
- if(mb.isButtonTouched(x, y)) {
- mb.setButtonState(true);
- moveMenuButton = mb;
- moveDirection = y;
- }
- }
- }
- break;
- case MotionEvent.ACTION_MOVE:
- synchronized (holder) {
- if (moveMenuButton !=null) {
- moveMenuButton.update((int)y);
- }
- }
- break;
- case MotionEvent.ACTION_UP:
- synchronized (holder) {
- if (moveMenuButton !=null){
- moveMenuButton.setButtonState(false);
- }
- moveMenuButton = null;
- }
- break;
- }
- }
- catch(Exception e){
- }
- return true;
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Here is my thread for updating physics and draw
Using java Syntax Highlighting
- @Override
- public void run() {
- long ticksPS = 1000 / FPS;
- long startTime;
- long sleepTime;
- Canvas c = null;
- while (running) {
- startTime = System.currentTimeMillis();
- try {
- c = view.getHolder().lockCanvas();
- synchronized (view.getHolder()) {
- view.onDraw(c);
- }
- }
- finally {
- if (c != null) {
- view.getHolder().unlockCanvasAndPost(c);
- }
- }
- sleepTime = ticksPS - (System.currentTimeMillis() - startTime);
- try {
- if (sleepTime > 0)
- sleep(sleepTime);
- else
- sleep(10);
- }
- catch (Exception e) {
- }
- }
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
And finally some code for my bitmap object that i draw.
Using java Syntax Highlighting
- public void update(int y){
- if(menuButtonPressed)
- {
- this.yPosistion = y;
- menuButtonRectangle.set(xMin, yPosistion-yMin, xMax, yPosistion+yMax);
- }
- }
- public void onDraw(Canvas canvas){
- canvas.drawBitmap(menuButton, null, menuButtonRectangle, null);
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
Any suggestions that I might be missing or how i can speed this up? I'm going to include even more effects to the menu using bitmaps to shadow the menu, but first i want to make a smoother movement of my bitmaps. Is this impossible to do with canvas and should i try to move over to OpenGL instead?
Thx guys!


