Aufrufen von "setContentView" in einer anderen Klasse

H

Hoffimh

Neues Mitglied
0
Hallo,

ich arbeite seit einigen Tagen an einem kleinen Android-Spiel. Dies hab ich in 2 Grundlegende Klassen geteilt(MainActivity.java und SpielActivity.java). Nun möchte ich in der SpielActivity.java eine neue"Seite" aufrufen ("setContenView(R.layout.gameover)"). Dies ist allerdings meines Wissens nach nicht möglich, da dazu die Klasse von "ActionBarActivity" Erben müsste. Allerdings erbt die Klasse SpielActivity.java bereits von "View". Und somit kann ich in der SpielActivity.java keine neue "Seite" aufrufen.
Oder gibt es doch eine möglichkeit dies zu tun ?
Vielen Dank im Vorraus.

MfG Hoffimh



Code:
package hoffimh.GicLo.de;


import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;



public class MainActivity extends ActionBarActivity {

public int b;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.menu_main);

    }

    public void spielstarten(View view) {
        setContentView(new SpielActivity(this));


    }


    public void credits(View view) {
        setContentView(R.layout.credits);

    }

    public void einstellungen(View view) {
        setContentView(R.layout.einstellungen_main);

    }

    public void spielbeenden(View view) {
        System.exit(1);
    }


    public void gameover() {
      setContentView(R.layout.gameover);
        }


    }


Code:
package hoffimh.GicLo.de;

import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.MotionEvent;
import android.view.View;

import java.util.Random;
import java.util.concurrent.TimeUnit;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

/**
* Created by Hoffimh and Lukas on 19.08.2015.
*/
public class SpielActivity extends View {

    private int[] xrandom, yrandom;
    private int punkte = 0;
    private Ball ball1, ball2, ball3, ball4, ball5, ball6, ball7,ballrandom;
    private RedBall redball, redball2, redball3, redball4, redball5;
    private GreenBall greenball;
    private boolean angeklickt = false;
    private boolean angeklickt2 = false;
    private boolean angeklickt3 = false;
    private boolean angeklickt4 = false;
    private boolean angeklickt5 = false;
    private boolean angeklicktrandom = false;
    public boolean angeklicktred2 = false;
    public boolean angeklicktred3 = false;
    public boolean angeklicktred = false;
    private  boolean angeklickt6 = false;
    private  boolean angeklickt7 = false;
    public boolean angeklickt8 = false;
    public  boolean angeklickt9 = false;
    public boolean druck= true;
    private final int a1 = 1;
    public int b1;


    private  boolean angeklicktgreen = false;
    private MotionEvent event;
    private Canvas canvas;
    private Random random = new Random();
    private Background bg;
    public static final int WIDTH = 1920;


    final Handler h = new Handler() {
        @Override
        public void close() {

        }

        @Override
        public void flush() {

        }

        @Override
        public void publish(LogRecord record) {

        }
    };
    private Context context;


    public SpielActivity(Context context) {


        super(context);
        Random random = new Random();
        int[] xrandom = {random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1};
        int[] yrandom = {random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1, random.nextInt(900) + 1};
        this.xrandom = xrandom;
        this.yrandom = yrandom;




            bg = new Background(BitmapFactory.decodeResource(getResources(), R.drawable.background));
            bg.setVector(-5);

            ball1 = new Ball(getResources(), xrandom[0], -700);
            ball2 = new Ball(getResources(), -100, yrandom[1]);
            ball3 = new Ball(getResources(), -600, yrandom[2]);
            ball4 = new Ball(getResources(), xrandom[3], -400);
            ball5 = new Ball(getResources(), xrandom[4], -100);
            ball6 = new Ball(getResources(), xrandom[9],  2000);
            ball7 = new Ball(getResources(), xrandom[10],  2100);
            redball4 = new RedBall(getResources(), xrandom[11],  2100);
            redball5 = new RedBall(getResources(), xrandom[12],  2050);
            ballrandom = new Ball(getResources(), -300, yrandom[5]);
            redball = new RedBall(getResources(), -600, yrandom[6]);
            redball2 = new RedBall(getResources(), -300, yrandom[7]);
            redball3 = new RedBall(getResources(), xrandom[5], -400);
            greenball = new GreenBall(getResources(), 1100,xrandom[14] );
        }






    public boolean onTouchEvent(MotionEvent event) {
        if (ball1.getangezeigt() && (ball1.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 1;
            ball1.setAngezeigt(false);
            angeklickt = true;


            int xrandom = random.nextInt(900) + 1;
            ball1.setAngezeigt(false);

            ball1 = new Ball(getResources(), xrandom, -700);
            ball1.setAngezeigt(true);
        }

        if (ball2.getangezeigt() && (ball2.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 1;
            ball2.setAngezeigt(false);
            angeklickt2 = true;

            int yrandom4 = random.nextInt(900) + 1;
            ball2.setAngezeigt(false);

            ball2 = new Ball(getResources(), -800, yrandom4);
            ball2.setAngezeigt(true);
        }
        if (ball3.getangezeigt() && (ball3.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 1;
            ball3.setAngezeigt(false);
            angeklickt3 = true;

            int yrandom3 = random.nextInt(900) + 1;
            ball3.setAngezeigt(false);

            ball3 = new Ball(getResources(), -600, yrandom3);
            ball3.setAngezeigt(true);
        }

        if (ball4.getangezeigt() && (ball4.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 1;
            ball4.setAngezeigt(false);
            angeklickt4 = true;

            int xrandom2 = random.nextInt(900) + 1;
            ball4.setAngezeigt(false);

            ball4 = new Ball(getResources(), xrandom2, -400);
            ball4.setAngezeigt(true);
        }

        if (ball5.getangezeigt() && (ball5.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 1;
            ball5.setAngezeigt(false);
            angeklickt5 = true;

            int xrandom3 = random.nextInt(900) + 1;
            ball5.setAngezeigt(false);

            ball5 = new Ball(getResources(), xrandom3, -100);
            ball5.setAngezeigt(true);

        }
        if (ball6.getangezeigt() && (ball6.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 1;
            ball6.setAngezeigt(false);
            angeklickt6 = true;

            int xrandom4 = random.nextInt(900) + 1;
            ball6.setAngezeigt(false);

            ball6 = new Ball(getResources(), xrandom4,  2000);
            ball6.setAngezeigt(true);
        }
        if (ball7.getangezeigt() && (ball7.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 1;
            ball7.setAngezeigt(false);
            angeklickt7 = true;

            int xrandom4 = random.nextInt(900) + 1;
            ball7.setAngezeigt(false);

            ball7 = new Ball(getResources(), xrandom4,  2000);
            ball7.setAngezeigt(true);
        }
        if (greenball.getangezeigt() && (greenball.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 3;
            greenball.setAngezeigt(false);
        }
        if (ballrandom.getangezeigt() && (ballrandom.isTouched(event.getX(), event.getY()))) {
            punkte = punkte + 1;
            ballrandom.setAngezeigt(false);
            angeklicktrandom = true;

            Random random = new Random();
            int yrandom2 = random.nextInt(900) + 1;
            ballrandom.setAngezeigt(false);

            ballrandom = new Ball(getResources(), -300, yrandom2);
            ballrandom.setAngezeigt(true);
        }

        if (redball.getangezeigt() && (redball.isTouched(event.getX(), event.getY()))) {
            redball.setAngezeigt(false);
            angeklicktred = true;




        }

        if (redball2.getangezeigt() && (redball2.isTouched(event.getX(), event.getY()))) {
            redball2.setAngezeigt(false);
            angeklicktred2 = true;




            }
        if (redball3.getangezeigt() && (redball3.isTouched(event.getX(), event.getY()))) {
            redball3.setAngezeigt(false);
            angeklicktred3 = true;





            }
        if (redball4.getangezeigt() && (redball4.isTouched(event.getX(), event.getY()))) {
            redball4.setAngezeigt(false);
            angeklickt8 = true;




            }
        if (redball5.getangezeigt() && (redball5.isTouched(event.getX(), event.getY()))) {
            redball5.setAngezeigt(false);
            angeklickt9 = true;



            if ((redball.isTouched(event.getX(), event.getY())) || (redball2.isTouched(event.getX(), event.getY()) || (redball3.isTouched(event.getX(), event.getY()))) || (redball4.isTouched(event.getX(), event.getY())) || (redball5.isTouched(event.getX(), event.getY()))) {
                    b1 = a1 +1;
            }
        }


      /*  if (angeklicktred = true && redball.isTouched(event.getX(), event.getY())) {
            System.exit(1);

        }
        if (angeklicktred2 = true&& redball2.isTouched(event.getX(), event.getY())) {

            System.exit(1);
        }
        if (angeklicktred3 = true&& redball3.isTouched(event.getX(), event.getY())) {

            System.exit(1);
        }
        if (angeklickt8 = true&& redball4.isTouched(event.getX(), event.getY())) {

            System.exit(1);
        }
        if (angeklickt9 = true&& redball5.isTouched(event.getX(), event.getY())) {

            System.exit(1);
        }*/


        this.event = event;
        return super.onTouchEvent(event);
    }

    private void startActivity(Intent myIntent) {
    }
/*  public boolean angeklicktredneu = angeklicktred;
    public boolean angeklicktred2neu = angeklicktred2;
    public boolean angeklicktred3neu = angeklicktred3;
    public boolean angeklickt8neu = angeklickt8;
    public boolean angeklickt9neu = angeklickt9;

*/

    public boolean druckneu = druck;

    @Override
    protected void onDraw(Canvas canvas) {




        if (canvas != null) {
            bg.draw(canvas);

        }

        String diepunkte = null;


        Integer.toString(punkte);

        if (ball1.getangezeigt() == true) {
            ball1.drawBitmap(canvas);
        }

        if (ball2.getangezeigt() == true) {
            ball2.drawBitmap(canvas);
        }

        if (ball3.getangezeigt() == true) {
            ball3.drawBitmap(canvas);
        }

        if (ball4.getangezeigt() == true) {
            ball4.drawBitmap(canvas);
        }

        if (ball5.getangezeigt() == true) {
            ball5.drawBitmap(canvas);
        }
        if (ball6.getangezeigt() == true) {
            ball6.drawBitmap(canvas);
        }
        if (ball7.getangezeigt() == true) {
            ball7.drawBitmap(canvas);
        }
        if (greenball.getangezeigt() == true) {
            greenball.drawBitmap(canvas);
        }
        if (ballrandom.getangezeigt() == true) {
            ballrandom.drawBitmap(canvas);
        }
        if (redball.getangezeigt() == true) {
            redball.drawBitmap(canvas);
        }
        if (redball2.getangezeigt() == true) {
            redball2.drawBitmap(canvas);
        }
        if (redball3.getangezeigt() == true) {
            redball3.drawBitmap(canvas);
        }
        if (redball4.getangezeigt() == true) {
            redball4.drawBitmap(canvas);
        }
        if (redball5.getangezeigt() == true) {
            redball5.drawBitmap(canvas);
        }
        this.canvas = canvas;
        Paint paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setTextSize(30);
        new Paint.FontMetrics();
        diepunkte = Integer.toString(punkte);

        canvas.drawText("Punkte", 10, 35, paint);
        canvas.drawText(diepunkte, 110, 35, paint);
        //canvas.drawText(diezeit, 10, 35, paint);
        Thread test = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Random random = new Random();
                    int[] geschwindigkeitrandom = {random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1, random.nextInt(10) + 1};
                    int geschwindigkeitrandomgreen = random.nextInt(16) + 1;


                    TimeUnit.MILLISECONDS.sleep(5);
                    if (ball1.addy(geschwindigkeitrandom[0])) {

                    }
                    if (ball2.addx(geschwindigkeitrandom[1])) {
                        ball2 = new Ball(getResources(), -100, yrandom[1]);
                    }
                    if (ball3.addx(geschwindigkeitrandom[2])) {
                        ball3 = new Ball(getResources(), -600, yrandom[2]);
                    }
                    if (ball4.addy(geschwindigkeitrandom[3])) {
                        ball4 = new Ball(getResources(), xrandom[3], -400);
                    }
                    if (ball5.addy(geschwindigkeitrandom[4])) {
                        ball5 = new Ball(getResources(), xrandom[4], -100);
                    }
                    if (ball6.addy(-geschwindigkeitrandom[5])) {
                        ball6 = new Ball(getResources(), xrandom[9],2000);
                    }
                    if (ball7.addy2(-geschwindigkeitrandom[6])) {
                        ball7 = new Ball(getResources(), xrandom[10],2100);
                    }
                    if (greenball.addx(-geschwindigkeitrandomgreen)) {
                        greenball = new GreenBall(getResources(),1100,xrandom[14]);
                    }
                    if (ballrandom.addx(geschwindigkeitrandom[7])) {
                        ballrandom = new Ball(getResources(), -300, yrandom[5]);
                    }
                    if (redball.addx(geschwindigkeitrandom[8])) {

                    }
                    if (redball2.addx(geschwindigkeitrandom[9])) {

                    }
                    if (redball3.addy(geschwindigkeitrandom[10])) {

                    }
                    if (redball4.addy2(-geschwindigkeitrandom[11])) {

                    }
                    if (redball5.addy2(-geschwindigkeitrandom[12])) {

                    }
                    postInvalidate();

                } catch (InterruptedException e) {

                }
            }

        });
        test.start();
    }


    public void updtae() {

        bg.update();
    }



}
 
Zuletzt bearbeitet:
Hi dein grundlegender Aufbau ist falsch gewählt meiner Ansicht nach.
Normalerweise baue ich Spiele so auf:
MainActivity
MainView
MainThread
UtiliyClasses

MainView ist eine SurfaceView
Diese beinhaltet den Thread der sie aktualisiert.

Die Spiellogik sollte nicht auf dem UI Thread der MainActivity stattfinden.

Möchtest du aber jetzt Wahnwitzigerweise deine komplette ViewHierarchy ändern mit setContentView() wie du es in der Überschrift erwähnst dann mache dazu eine Methode in deiner Activity und darin ein runOnUiThread, falls der call zu dieser aus einem nicht-UI thread erfolgt. Den rufst du dann auf und änderst dein Content der Activity.

Dabei wird deine komplette View Hierarchy Garbage Collected, falls keine weiteren Referenzen mehr gehalten werden(das würde sonst ein Memory Leak verursachen) und eine komplett neue Hierarchy aufgebaut. Das kann eine kleine Weile dauern.

Wenn du mehr zum Thema Spieleentwicklung oder wie man das am Besten aufbaut wissen möchtest, frag einfach

Wenn du möchtest kann ich dir auch eine Hülse hier hinschreiben für ein Spiel da ist alles drin was du brauchst dann musst du einfach nur noch dein Code da reinschreiben....

lg

Jaiel
[DOUBLEPOST=1441157017,1441156125][/DOUBLEPOST]Hier mal ein Beispiel :

MainActivity

Code:
package de.jaielsoft.activities;



//import android.content.Intent;
import android.R.anim;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import de.jaielsoft.drawableobjects.MenuFrame;
import de.jaielsoft.drawableobjects.MenuObject;
import de.jaielsoft.surfaceviews.MainView;
import de.jaielsoft.surfaceviews.MainView.Mode;




public class MainActivity extends Activity {
 
    MainView mView;
    SharedPreferences prefs;
    public boolean specialThing=false;
    public SoundPool soundPool;
    public int buttonClickSoundID;
    public boolean buttonClickSoundLoaded;
    public int beepSoundID;
    public boolean beepSoundLoaded;
    public int menuEnterSoundID;
    public boolean menuEnterSoundLoaded;
    public int menuExitSoundID;
    public boolean menuExitSoundLoaded;
 
 
 
     
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
     

        if(savedInstanceState==null)
        {
            prefs=getSharedPreferences("myPrefs",0);
            setVolumeControlStream(AudioManager.STREAM_MUSIC);
            setUpSounds();
            mView=new MainView(this);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                                 WindowManager.LayoutParams.FLAG_FULLSCREEN);
            setContentView(mView);

        }
    }
 
 
 
    @Override
    protected void onResume()
    {
        super.onResume();
        if(mView!=null&&mView.mThread!=null)
        {
            mView.mThread.isPaused=false;
            if(mView.mediaPlayer!=null)
            {
                if(mView.musicOn)
                {
                    mView.startMediaPlayer();
                }
            }
        }
    }
 
 
    @Override
    public void onStop()
    {
        super.onStop();
    }
 
 
    @Override
    public void onPause()
    {
        super.onPause();
        if(mView!=null&&mView.mThread!=null)
        {
            mView.mThread.isPaused=true;
            if(mView.mediaPlayer!=null)
            {
                mView.pauseMediaPlayer();
            }
        }
        setSharedPrefs();
    }
 
 
    @Override
    public void onDestroy()
    {
        super.onDestroy();
        Log.e("","onDestroy()");
        mView.killMainThread();
        soundPool.release();
        soundPool=null;
        setSharedPrefs();
    }
 
 
    @Override
    public void onBackPressed()
    {
        if(mView==null)return;
        mView.playButtonClick();
        if(mView.mode==Mode.MAIN_MODE)
        {
            MenuObject.setAnchorX((float)(-0.3f*mView.screenWidth));
            mView.mode=Mode.EXIT_MODE;
            mView.mThread.exitModeMenuFrame.anchorY=(float)mView.screenHeight/2f;
            mView.mThread.exitModeMenuFrame.moving=true;
            mView.playMenuEnterSound();
        }
        else if(mView.mode==Mode.STATISTICS_MODE)
        {
            mView.mode=Mode.ME_MODE;
            MenuFrame.symbolLabel=mView.mThread.meButton.buttonLabel;
            mView.mThread.menuFrame.symbolBitmap=mView.mThread.meSymbol;
        }
        else if(mView.mode==Mode.EXIT_MODE)
        {
            mView.mThread.exitModeMenuFrame.anchorY=(float)mView.screenHeight+(float)mView.mThread.menuFrame.height/2f;
            mView.mThread.exitModeMenuFrame.moving=true;
            mView.playMenuExitSound();
        }
        else
        {
            mView.mThread.menuFrame.anchorY=(float)mView.screenHeight+(float)mView.mThread.menuFrame.height/2f;
            mView.mThread.menuFrame.menuFrameMoving=true;
            mView.playMenuExitSound();
        }
    }

 
    /**
     * loads shared preferences
     */
    public void loadSharedPrefs()
    {
        mView.soundOn=prefs.getBoolean("sound", true);
        mView.musicOn=prefs.getBoolean("music", true);
        mView.soundFXOn=prefs.getBoolean("soundFX", true);
        mView.notificationOn=prefs.getBoolean("notification", true);
        mView.vibrationOn=prefs.getBoolean("vibration", true);
     
        mView.highScore=prefs.getInt("highScore",0);
        mView.starPoints=prefs.getInt("starPoints",0);
        mView.gamesPlayed=prefs.getInt("gamesPlayed",0);
        mView.dotsPopped=prefs.getInt("dotsPopped",0);
        mView.timePlayed=prefs.getInt("timePlayed",0);
        mView.soundInt=prefs.getInt("soundInt", 0);
     
        if(mView.notificationOn)
            setAlarmForNotification();
        else
            cancelAlarmForNotification();
     
    }
 
 
    /**
     * sets shared preferences
     */
    public void setSharedPrefs()
    {
        SharedPreferences.Editor editor = prefs.edit();

        editor.putBoolean("sound", mView.soundOn);
        editor.putBoolean("music",mView.musicOn);
        editor.putBoolean("soundFX",mView.soundFXOn);
        editor.putBoolean("notification",mView.notificationOn);
        editor.putBoolean("vibration",mView.vibrationOn);
        editor.putInt("soundInt", mView.soundInt);
        editor.putBoolean("specialThing", specialThing);
        editor.commit();
    }
 
 
    /**
     * sets an alarm for a notification
     */
    public void setAlarmForNotification()
    {
        long alarmTime=System.currentTimeMillis()+86400000;
        Intent dotBroadcastReceiverIntent=new Intent(this,DotBroadcastReceiver.class);
        AlarmManager alarmManager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
        alarmManager.set(AlarmManager.RTC, alarmTime,PendingIntent.getBroadcast(this,
                            1,dotBroadcastReceiverIntent,PendingIntent.FLAG_UPDATE_CURRENT));
    }

 
    /**
     * cancels an alarm for a notification
     */
    public void cancelAlarmForNotification()
    {
        AlarmManager alarmManager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
        alarmManager.cancel(PendingIntent.getBroadcast(this,
                            1,new Intent(this,DotBroadcastReceiver.class),PendingIntent.FLAG_UPDATE_CURRENT));
    }
 
 
    /**
     * finishes the activity
     */
    public void finishActivity()
    {
        finish();
        overridePendingTransition(anim.fade_in, anim.fade_out);
    }
 
 
    /**
     * sets up the sounds
     */
    @SuppressWarnings("deprecation")
    public void setUpSounds()
    {
        soundPool=new SoundPool(20,AudioManager.STREAM_MUSIC,0);
        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener()
        {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId,int status)
            {
                if(sampleId==beepSoundID)
                {
                    if(status==0)
                    {
                        beepSoundLoaded=true;
                    }
                }
                else if(sampleId==buttonClickSoundID)
                {
                    if(status==0)
                    {
                        buttonClickSoundLoaded=true;
                    }
                }
                else if(sampleId==menuEnterSoundID)
                {
                    if(status==0)
                    {
                        menuEnterSoundLoaded=true;
                    }
                }
                else if(sampleId==menuExitSoundID)
                {
                    if(status==0)
                    {
                        menuExitSoundLoaded=true;
                    }
                }
            }
         
        });
        buttonClickSoundID=soundPool.load(this,R.raw.buttonclick, 0);
        beepSoundID=soundPool.load(this, R.raw.beep,0);
        menuEnterSoundID=soundPool.load(this, R.raw.menuenter,0);
        menuExitSoundID=soundPool.load(this, R.raw.menuexit,0);
    }
}
[DOUBLEPOST=1441157089][/DOUBLEPOST]MainView:

Code:
package de.jaielsoft.surfaceviews;



import android.R.anim;
import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.media.MediaPlayer;
import android.os.Vibrator;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.widget.Toast;
import de.jaielsoft.activities.MainActivity;
import de.jaielsoft.activities.PlayActivity;
import de.jaielsoft.activities.R;
import de.jaielsoft.drawableobjects.BackgroundParticle;
import de.jaielsoft.drawableobjects.MenuFrame;
import de.jaielsoft.drawableobjects.MenuObject;
import de.jaielsoft.threads.MainThread;

public class MainView extends SurfaceView implements SurfaceHolder.Callback
{ 
    public MainThread mThread;
 
    public MainActivity mAct;
 
    public SurfaceHolder sHolder;
 
    public Canvas canvas;
 
    public Vibrator deviceVibrator;
 
    public Mode mode=Mode.MAIN_MODE;
 
    public MediaPlayer mediaPlayer;
 
    public boolean surfaceReady;
    public boolean soundOn;
    public volatile boolean playButtonDown;
    public boolean meButtonDown;
    public boolean highscoreButtonDown;
    public boolean settingsButtonDown;
    public boolean soundButtonDown;
    public boolean exitButtonDown;
    public boolean closeButtonDown;
    public volatile boolean dragMode;
    public volatile boolean menuTouched;
 
    //neu
    public boolean musicOn;
    public boolean soundFXOn;
    public boolean notificationOn;
    public boolean vibrationOn;
    //neu
 
    public float touchPosX;
    public float touchPosY;
    public float curTouchPosX;
    public float curTouchPosY;
    public float oldTouchPosX;
    public float oldtouchPosY;
 
 
    public int screenWidth;
    public int screenHeight;
    public int pID=-1;
    public int highScore;
    public int starPoints;
    public int gamesPlayed;
    public int dotsPopped;
    public int timePlayed;
    public int soundInt;
 
    public String highScoreString;
    public String starPointsString;
    public String gamesPlayedString;
    public String dotsPoppedString;
    public String timePlayedString;
    public String reactionString;
    public String avgScoreString;
    public String avgRoundString;
 
 
    public enum Mode
    {
        MAIN_MODE,ME_MODE,STATISTICS_MODE,LEADERBOARD_MODE,SETTINGS_MODE,EXIT_MODE;
    }
 
 
    /**
     * Constructor
     * @param mAct the reference to the calling activity
     */
    public MainView(MainActivity mAct) {
        super(mAct);
        this.mAct=mAct;
        sHolder = getHolder();
        sHolder.addCallback(this);
        deviceVibrator=(Vibrator)mAct.getSystemService(Context.VIBRATOR_SERVICE);
        if(!deviceVibrator.hasVibrator())
            deviceVibrator=null;
     
    }
 
 
    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width,int height)
    {}

 
    @Override
    public void surfaceCreated(SurfaceHolder sHolder) {
        screenWidth=getWidth();
        screenHeight=getHeight();
        surfaceReady=true;
        if(mThread==null)
        {
            mAct.loadSharedPrefs();
            setStatisticStrings();
            mThread=new MainThread(this);
            startMainThread();
        }
        mThread.setPause(false);
     
     
    }

 
    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        surfaceReady=false;
        mThread.setPause(true);
    }
 
 
    @Override
    public boolean onTouchEvent(MotionEvent e)
    {
        super.onTouchEvent(e);
     
        switch (mode)
        {
        case EXIT_MODE:
            exitModeTouch(e);
            break;
         
        case LEADERBOARD_MODE:
            leaderBoardModeTouch(e);
            break;
         
        case MAIN_MODE:
            mainModeTouch(e);
            break;
         
        case ME_MODE:
            meModeTouch(e);
            break;
         
        case SETTINGS_MODE:
            settingsModeTouch(e);
            break;
         
        case STATISTICS_MODE:
            statisticsModeTouch(e);
            break;
         
        default:
            break;
          
        }

          performClick();
        return true;
     }

 
    @Override
    public boolean performClick()
    {
        super.performClick();
        return true;
    }
 
 
    /**
     * method for handling touches while on mode mainMode
     * @param e the MotionEvent
     */
    public void mainModeTouch(MotionEvent e)
    {
        curTouchPosX=e.getX();
        curTouchPosY=e.getY();
     
        if(!playButtonDown)
          {
            BackgroundParticle.FORCE_SOURCE_X=curTouchPosX;
            BackgroundParticle.FORCE_SOURCE_Y=curTouchPosY;
          }
        else
        {
            BackgroundParticle.FORCE_SOURCE_X=-1000;
            BackgroundParticle.FORCE_SOURCE_Y=-1000;
          }
     
          switch(e.getAction())
          {
            case MotionEvent.ACTION_POINTER_DOWN:
              case MotionEvent.ACTION_DOWN:
               
                  if(pID!=-1)break;
               
                  pID=e.getPointerId(0);
                oldtouchPosY=touchPosY=curTouchPosY;
                oldTouchPosX=touchPosX=curTouchPosX;
               
                if(touchPosY<=screenHeight-0.05*screenWidth&&touchPosY>=screenHeight-0.35*screenWidth)
                  {
                      if(touchPosX>=screenWidth/3f&&touchPosX<=screenWidth*2f/3f)
                      {
                          MenuObject.MOVING=false;
                      }
                       
                   
                      for(MenuObject mO:mThread.mOList)
                      {
                          if(mO.menuButtonSelectable&&touchPosX<=screenWidth*0.6f&&touchPosX>=screenWidth*0.4f&&touchPosY<=screenHeight-0.1f*screenWidth&&touchPosY>=screenHeight-0.3f*screenWidth)
                          {
                           
                              if(mO==mThread.meButton)
                              {
                                  meButtonDown=true;
                              }
                           
                              if(mO==mThread.highscoreButton)
                              {
                                  highscoreButtonDown=true;
                              }
                           
                              if(mO==mThread.settingsButton)
                              {
                                  settingsButtonDown=true;
                              }
                           
                              if(mO==mThread.soundButton)
                              {
                                  soundButtonDown=true;
                              }
                           
                              if(mO==mThread.exitButton)
                              {
                                  exitButtonDown=true;
                              }
                           
                          }
                      }
                   
                      menuTouched=true;
                  }
                  else
                  {
                      float delPos=(curTouchPosX-mThread.playButton.posX)*(curTouchPosX-mThread.playButton.posX)+
                                    (curTouchPosY-mThread.playButton.posY)*(curTouchPosY-mThread.playButton.posY);
                      if(delPos<=mThread.playButton.width*mThread.playButton.width/4f)
                          playButtonDown=true;
               
                  }
               
                  break;
               
              case MotionEvent.ACTION_MOVE:
               
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
               
                  if(menuTouched&&(dragMode||Math.abs(curTouchPosX-touchPosX)>0.02f*screenWidth))
                  {
                      MenuObject.MOVING=false;
                      mThread.changePosX(0.4f*(curTouchPosX-touchPosX));
                      touchPosX=curTouchPosX;
                      dragMode=true;
                      meButtonDown=highscoreButtonDown=settingsButtonDown=soundButtonDown=exitButtonDown=false;
                  }
                  else if(curTouchPosY>=screenHeight-screenWidth*0.1f||curTouchPosY<=screenHeight-screenWidth*0.3f)
                      meButtonDown=highscoreButtonDown=settingsButtonDown=soundButtonDown=exitButtonDown=false;
               
               
               
                  if(playButtonDown)
                  {
                      float delPos=(curTouchPosX-mThread.playButton.posX)*(curTouchPosX-mThread.playButton.posX)+
                                    (curTouchPosY-mThread.playButton.posY)*(curTouchPosY-mThread.playButton.posY);
                      if(delPos>mThread.playButton.width*mThread.playButton.width/4f)
                          playButtonDown=false;
                  }
               
                  if(menuTouched&&curTouchPosY<screenHeight-0.35*screenWidth);
                  else break;
               
              case MotionEvent.ACTION_POINTER_UP:
              case MotionEvent.ACTION_UP:
                  BackgroundParticle.FORCE_SOURCE_X=-1000;
                  BackgroundParticle.FORCE_SOURCE_Y=-1000;
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
                  pID=-1;
                  if(menuTouched&&!dragMode)
                  {
                      if(curTouchPosX<=screenWidth/3f&&Math.abs(MenuObject.ANCHOR_POS_X-MenuObject.ANCHOR_X)<0.1f*screenWidth)
                      {
                          MenuObject.setAnchorX(MenuObject.ANCHOR_X-(float)(0.2f*screenWidth));
                      }
                      else if(curTouchPosX>=screenWidth*2f/3f&&Math.abs(MenuObject.ANCHOR_POS_X-MenuObject.ANCHOR_X)<0.1f*screenWidth)
                      {
                          MenuObject.setAnchorX(MenuObject.ANCHOR_X+(float)(0.2f*screenWidth));
                      }
                   
                      else if(MenuObject.ANCHOR_POS_X==MenuObject.ANCHOR_X)
                      {     
                          if(MenuObject.ANCHOR_POS_X!=MenuObject.ANCHOR_X)
                          for(float i=-0.3f*(float)screenWidth;i<=0.5f*screenWidth;i+=0.2f*screenWidth)
                          {
                              if(Math.abs(MenuObject.ANCHOR_POS_X-i)<=0.1f*screenWidth)
                              {
                                  MenuObject.ANCHOR_X=i;
                                  break;
                              }
                          }
                       
                       
                          else
                          {
                              if(meButtonDown&&curTouchPosY<=screenHeight-screenWidth*0.1f&&curTouchPosY>=screenHeight-screenWidth*0.3f)
                              {
                                  mode=Mode.ME_MODE;
                                  mThread.menuFrame.symbolBitmap=mThread.meSymbol;
                                  MenuFrame.symbolLabel=mThread.meButton.buttonLabel;
                                  mThread.menuFrame.anchorY=(float)screenHeight/2f;
                                  mThread.menuFrame.menuFrameMoving=true;
                                  playButtonClick();
                                  playMenuEnterSound();
                              }
                           
                              else if(highscoreButtonDown&&curTouchPosY<=screenHeight-screenWidth*0.1f&&curTouchPosY>=screenHeight-screenWidth*0.3f)
                              {
//                                  mode=Mode.LEADERBOARD_MODE;
//                                  mThread.menuFrame.symbolBitmap=mThread.highscoreSymbol;
//                                  MenuFrame.symbolLabel=mThread.highscoreButton.buttonLabel;
//                                  mThread.menuFrame.anchorY=(float)screenHeight/2f;
//                                  mThread.menuFrame.menuFrameMoving=true;
                                  playButtonClick();
//                                  playMenuEnterSound();
                                  Toast.makeText(mAct, "Not Available Yet", Toast.LENGTH_SHORT).show();
                              }
                           
                              else if(settingsButtonDown&&curTouchPosY<=screenHeight-screenWidth*0.1f&&curTouchPosY>=screenHeight-screenWidth*0.3f)
                              {
                                  mode=Mode.SETTINGS_MODE;
                                  mThread.menuFrame.symbolBitmap=mThread.settingsSymbol;
                                  MenuFrame.symbolLabel=mThread.settingsButton.buttonLabel;
                                  mThread.menuFrame.anchorY=(float)screenHeight/2f;
                                  mThread.menuFrame.menuFrameMoving=true;
                                  playButtonClick();
                                  playMenuEnterSound();
                              }
                           
                              else if(soundButtonDown&&curTouchPosY<=screenHeight-screenWidth*0.1f&&curTouchPosY>=screenHeight-screenWidth*0.3f)
                              {
                                  if(soundOn)
                                  {
                                      if(soundFXOn&&musicOn)
                                      {
                                          soundFXOn=false;
                                          musicOn=false;
                                          soundInt=0;
                                      }
                                      else if(soundFXOn)
                                      {
                                          soundFXOn=false;
                                          soundInt=1;
                                      }
                                      else if(musicOn)
                                      {
                                          musicOn=false;
                                          soundInt=2;
                                      }
                                  }
                                  else
                                  {
                                      switch (soundInt)
                                      {
                                          case 0:soundFXOn=true;musicOn=true;break;
                                          case 1:soundFXOn=true;break;
                                          case 2:musicOn=true;break;
                                          default:break;
                                      }
                                  }
                                  soundOn=!soundOn;
                                  mThread.changeSoundButton=true;

                                  if(!musicOn)
                                {
                                      if(mediaPlayer!=null)
                                    {
                                          if(stopMediaPlayer())
                                          releaseMediaPlayer();
                                    }
                                }
                                else
                                {
                                    createMediaPlayer();
                                }
                                  playButtonClick();
                              }
                           
                              else if(exitButtonDown&&curTouchPosY<=screenHeight-screenWidth*0.1f&&curTouchPosY>=screenHeight-screenWidth*0.3f)
                              {
                                  mode=Mode.EXIT_MODE;

                                  mThread.exitModeMenuFrame.anchorY=(float)screenHeight/2f;
                                  mThread.exitModeMenuFrame.moving=true;
                                  playButtonClick();
                                  playMenuEnterSound();
                              }
                           
                          }
                      }
                  }
                  else if(dragMode&&Math.abs(oldTouchPosX-curTouchPosX)>=0.01f*screenWidth&&Math.abs(oldTouchPosX-curTouchPosX)<=0.3f*screenWidth)//System.currentTimeMillis()-oldTime<300)
                      {
                          MenuObject.setAnchorX(MenuObject.ANCHOR_X+(oldTouchPosX-curTouchPosX<0?0.2f*screenWidth:-0.2f*screenWidth));
                      }
                  else if(dragMode)
                   
                      if(MenuObject.ANCHOR_POS_X!=MenuObject.ANCHOR_X)
                      {
                          for(float i=-0.3f*(float)screenWidth;i<=0.5f*screenWidth;i+=0.2f*screenWidth)
                          {
                              if(Math.abs(MenuObject.ANCHOR_POS_X-i)<=0.1f*screenWidth)
                              {
                                  MenuObject.ANCHOR_X=i;
                                  break;
                              }
                          }
                      }
               
                  if(playButtonDown)
                  {
                      playButtonClick();
                      mThread.startGame=true;
                  }
                   
                  dragMode=false;
               
                  menuTouched=false;
               
                  playButtonDown=false;
               
                  meButtonDown=highscoreButtonDown=settingsButtonDown=soundButtonDown=exitButtonDown=false;
               
                  MenuObject.MOVING=true;

                  break;
          }
    }
 
 
    /**
     * method for handling touches while on mode meMode
     * @param e the MotionEvent
     */
    public void meModeTouch(MotionEvent e)
    {
        curTouchPosX=e.getX();
        curTouchPosY=e.getY();
        switch(e.getAction())
        {
            case MotionEvent.ACTION_POINTER_DOWN:
            case MotionEvent.ACTION_DOWN:
                if(pID!=-1)break;
                  pID=e.getPointerId(0);
                touchPosY=curTouchPosY;
                touchPosX=curTouchPosX;
                if(Math.abs(touchPosX-mThread.meModeMenuContent.buttonPosX[0])<=(float)mThread.meModeMenuContent.buttonUpWidth[0]/2f
                          &&Math.abs(touchPosY-mThread.meModeMenuContent.buttonPosY[0])<=(float)mThread.meModeMenuContent.buttonUpHeight[0]/2f)
                {
                    mThread.meModeMenuContent.buttonDown[0]=true;
                }
             
                if(Math.abs(touchPosX-mThread.menuFrame.closeButtonPosX)<=(float)mThread.menuFrame.closeButtonWidth&&
                   Math.abs(touchPosY-mThread.menuFrame.closeButtonPosY)<=(float)mThread.menuFrame.closeButtonHeight)
                {
                    closeButtonDown=true;
                }
                break;
             
            case MotionEvent.ACTION_MOVE:
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
               

                if(mThread.meModeMenuContent.buttonDown[0]&&(Math.abs(curTouchPosX-mThread.meModeMenuContent.buttonPosX[0])>(float)mThread.meModeMenuContent.buttonUpWidth[0]/2f||
                                            Math.abs(curTouchPosY-mThread.meModeMenuContent.buttonPosY[0])>(float)mThread.meModeMenuContent.buttonUpHeight[0]/2f))
                {
                    mThread.meModeMenuContent.buttonDown[0]=false;
                }
             
                  if(closeButtonDown&&(Math.abs(curTouchPosX-mThread.menuFrame.closeButtonPosX)>mThread.menuFrame.closeButtonWidth||
                                       Math.abs(curTouchPosY-mThread.menuFrame.closeButtonPosY)>mThread.menuFrame.closeButtonHeight))
                  {
                      closeButtonDown=false;
                  }
                  break;
             
            case MotionEvent.ACTION_POINTER_UP:
              case MotionEvent.ACTION_UP:
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
                  pID=-1;
                  if(closeButtonDown&&Math.abs(curTouchPosX-mThread.menuFrame.closeButtonPosX)<=mThread.menuFrame.closeButtonWidth
                                    &&Math.abs(curTouchPosY-mThread.menuFrame.closeButtonPosY)<=mThread.menuFrame.closeButtonHeight)
                {
                    mThread.menuFrame.anchorY=(float)screenHeight+(float)mThread.menuFrame.height/2f;
                    mThread.menuFrame.menuFrameMoving=true;
                    playButtonClick();
                    playMenuExitSound();
                }
               

                if(mThread.meModeMenuContent.buttonDown[0]&&Math.abs(touchPosX-mThread.meModeMenuContent.buttonPosX[0])<=(float)mThread.meModeMenuContent.buttonUpWidth[0]/2f
                                         &&Math.abs(touchPosY-mThread.meModeMenuContent.buttonPosY[0])<=(float)mThread.meModeMenuContent.buttonUpHeight[0]/2f)
                {
                    mode=Mode.STATISTICS_MODE;
                    MenuFrame.symbolLabel="Statistics";
                    mThread.menuFrame.symbolBitmap=mThread.statisticsSymbol;
                    playButtonClick();
                }
               
                mThread.meModeMenuContent.buttonDown[0]=closeButtonDown=false;
                break;
        }
    }
 
 
    /**
     * method for handling touches while on mode statisticsMode
     * @param e the MotionEvent
     */
    public void statisticsModeTouch(MotionEvent e)
    {
        curTouchPosX=e.getX();
        curTouchPosY=e.getY();
        switch(e.getAction())
        {
            case MotionEvent.ACTION_POINTER_DOWN:
            case MotionEvent.ACTION_DOWN:
                if(pID!=-1)break;
                  pID=e.getPointerId(0);
                touchPosY=curTouchPosY;
                touchPosX=curTouchPosX;
                if(Math.abs(touchPosX-mThread.menuFrame.closeButtonPosX)<=(float)mThread.menuFrame.closeButtonWidth&&
                   Math.abs(touchPosY-mThread.menuFrame.closeButtonPosY)<=(float)mThread.menuFrame.closeButtonHeight)
                {
                    closeButtonDown=true;
                }
                break;
             
            case MotionEvent.ACTION_MOVE:
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
                  if(closeButtonDown&&(Math.abs(curTouchPosX-mThread.menuFrame.closeButtonPosX)>mThread.menuFrame.closeButtonWidth||
                                       Math.abs(curTouchPosY-mThread.menuFrame.closeButtonPosY)>mThread.menuFrame.closeButtonHeight))
                  {
                      closeButtonDown=false;
                  }
                  break;
             
            case MotionEvent.ACTION_UP:
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
                  pID=-1;
                  if(closeButtonDown&&Math.abs(curTouchPosX-mThread.menuFrame.closeButtonPosX)<=mThread.menuFrame.closeButtonWidth&&
                                      Math.abs(curTouchPosY-mThread.menuFrame.closeButtonPosY)<=mThread.menuFrame.closeButtonHeight)
                {
                    mode=Mode.ME_MODE;
                    MenuFrame.symbolLabel=mThread.meButton.buttonLabel;
                    mThread.menuFrame.symbolBitmap=mThread.meSymbol;
                    playButtonClick();
                }
                closeButtonDown=false;
                break;
        }
    }
 
 
    /**
     * method for handling touches while on mode leaderBoardMode
     * @param e the MotionEvent
     */
    public void leaderBoardModeTouch(MotionEvent e)
    {
        curTouchPosX=e.getX();
        curTouchPosY=e.getY();
        switch(e.getAction())
        {
            case MotionEvent.ACTION_POINTER_DOWN:
            case MotionEvent.ACTION_DOWN:
                if(pID!=-1)break;
                  pID=e.getPointerId(0);
                touchPosY=curTouchPosY;
                touchPosX=curTouchPosX;
                if(Math.abs(touchPosX-mThread.menuFrame.closeButtonPosX)<=(float)mThread.menuFrame.closeButtonWidth&&
                   Math.abs(touchPosY-mThread.menuFrame.closeButtonPosY)<=(float)mThread.menuFrame.closeButtonHeight)
                {
                    closeButtonDown=true;
                }
                break;
             
            case MotionEvent.ACTION_MOVE:
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
                  if(closeButtonDown&&(Math.abs(curTouchPosX-mThread.menuFrame.closeButtonPosX)>mThread.menuFrame.closeButtonWidth||
                                       Math.abs(curTouchPosY-mThread.menuFrame.closeButtonPosY)>mThread.menuFrame.closeButtonHeight))
                  {
                      closeButtonDown=false;
                  }
                  break;
             
            case MotionEvent.ACTION_UP:
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
                  pID=-1;
                  if(closeButtonDown&&Math.abs(curTouchPosX-mThread.menuFrame.closeButtonPosX)<=mThread.menuFrame.closeButtonWidth&&
                                      Math.abs(curTouchPosY-mThread.menuFrame.closeButtonPosY)<=mThread.menuFrame.closeButtonHeight)
                {
                    mThread.menuFrame.anchorY=(float)screenHeight+(float)mThread.menuFrame.height/2f;
                    mThread.menuFrame.menuFrameMoving=true;
                    playButtonClick();
                    playMenuExitSound();
                }
                closeButtonDown=false;
                break;
        }
    }
 
 
    /**
     * method for handling touches while on mode settingsMode
     * @param e the MotionEvent
     */
    public void settingsModeTouch(MotionEvent e)
    {
        curTouchPosX=e.getX();
        curTouchPosY=e.getY();
        switch(e.getAction())
        {
            case MotionEvent.ACTION_POINTER_DOWN:
            case MotionEvent.ACTION_DOWN:
                if(pID!=-1)break;
                  pID=e.getPointerId(0);
                touchPosY=curTouchPosY;
                touchPosX=curTouchPosX;
             
                for(int i=0;i<5;i++)
                {
                    if(Math.abs(touchPosX-mThread.settingsModeMenuContent.buttonPosX[i])<=mThread.settingsModeMenuContent.buttonUpWidth[i]/2f&&
                       Math.abs(touchPosY-mThread.settingsModeMenuContent.buttonPosY[i])<=mThread.settingsModeMenuContent.buttonUpHeight[i]/2f)
                    {
                        mThread.settingsModeMenuContent.buttonDown[i]=true;
                        break;
                    }
                }
                if(Math.abs(touchPosX-mThread.menuFrame.closeButtonPosX)<=(float)mThread.menuFrame.closeButtonWidth&&
                   Math.abs(touchPosY-mThread.menuFrame.closeButtonPosY)<=(float)mThread.menuFrame.closeButtonHeight)
                {
                    closeButtonDown=true;
                }
                break;
             
            case MotionEvent.ACTION_MOVE:
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
               
                  for(int i=0;i<mThread.settingsModeMenuContent.buttonCount;i++)
                {
                    if(mThread.settingsModeMenuContent.buttonDown[i]&&(Math.abs(curTouchPosX-mThread.settingsModeMenuContent.buttonPosX[i])>mThread.settingsModeMenuContent.buttonUpWidth[i]/2f||
                                        Math.abs(curTouchPosY-mThread.settingsModeMenuContent.buttonPosY[i])>mThread.settingsModeMenuContent.buttonUpHeight[i]/2f))
                    {
                        mThread.settingsModeMenuContent.buttonDown[i]=false;
                        break;
                    }
                }
               
                  if(closeButtonDown&&(Math.abs(curTouchPosX-mThread.menuFrame.closeButtonPosX)>mThread.menuFrame.closeButtonWidth||
                                       Math.abs(curTouchPosY-mThread.menuFrame.closeButtonPosY)>mThread.menuFrame.closeButtonHeight))
                  {
                      closeButtonDown=false;
                  }
                  break;
             
            case MotionEvent.ACTION_POINTER_UP:
            case MotionEvent.ACTION_UP:
                  if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
                  pID=-1;
               
                  /*
                   * 0-soundFX
                   * 1-Music
                   * 2-Notification
                   * 3-Vibration
                   * 4-No Ads
                   */
                  for(int i=0;i<5;i++)
                {
                    if(mThread.settingsModeMenuContent.buttonDown[i]&&Math.abs(curTouchPosX-mThread.settingsModeMenuContent.buttonPosX[i])<=mThread.settingsModeMenuContent.buttonUpWidth[i]/2f&&
                        Math.abs(curTouchPosY-mThread.settingsModeMenuContent.buttonPosY[i])<=mThread.settingsModeMenuContent.buttonUpHeight[i]/2f)
                    {
                        mThread.settingsModeMenuContent.buttonDown[i]=false;
                        if(i==0)
                        {
                            if(!soundFXOn&&!musicOn)
                            {
                                if(!soundOn)
                                {
                                    soundOn=!soundOn;
                                    mThread.changeSoundButton=true;
                                }
                            }
                            soundFXOn=!soundFXOn;
                         
                            if(!soundFXOn&&!musicOn)
                                soundInt=0;
                         
                            playButtonClick();
                        }

                        else if(i==1)
                        {
                            if(musicOn)
                            {
                                if(mediaPlayer!=null)
                                {
                                    if(stopMediaPlayer())
                                    releaseMediaPlayer();
                                }
                            }
                            else
                            {
                                createMediaPlayer();
                            }
                            if(!soundFXOn&&!musicOn)
                            {
                                if(!soundOn)
                                {
                                    soundOn=!soundOn;
                                    mThread.changeSoundButton=true;
                                }
                            }
                            musicOn=!musicOn;
                         
                         
                            if(!soundFXOn&&!musicOn)
                                soundInt=0;
                         
                            playButtonClick();
                        }
                        else if(i==2)
                        {
                            if(notificationOn)
                                mAct.cancelAlarmForNotification();
                            else
                                mAct.setAlarmForNotification();
                         
                            notificationOn=!notificationOn;
                            playButtonClick();
                        }
                        else if(i==3)
                        {
                            if(!vibrationOn)
                                if(deviceVibrator!=null)
                                    deviceVibrator.vibrate(500);
                            else if(deviceVibrator!=null)
                                    deviceVibrator.cancel();
                             
                            vibrationOn=!vibrationOn;
                            playButtonClick();
                        }
                        else if(i==4)
                        {
                            playButtonClick();
                        }
                     
                        if(!soundFXOn&&!musicOn)
                        {
                            if(soundOn)
                            {
                                soundOn=!soundOn;
                                mThread.changeSoundButton=true;
                            }
                        }

                        mAct.setSharedPrefs();
                        break;
                    }
                }
               
                  if(closeButtonDown&&Math.abs(curTouchPosX-mThread.menuFrame.closeButtonPosX)<=mThread.menuFrame.closeButtonWidth&&
                                      Math.abs(curTouchPosY-mThread.menuFrame.closeButtonPosY)<=mThread.menuFrame.closeButtonHeight)
                {
                    mThread.menuFrame.anchorY=(float)screenHeight+(float)mThread.menuFrame.height/2f;
                    mThread.menuFrame.menuFrameMoving=true;
                    playButtonClick();
                    playMenuExitSound();
                }
                closeButtonDown=false;
                break;
        }
    }
 
 
    /**
     * method for handling touches while on mode exitMode
     * @param e the MotionEvent
     */
    public void exitModeTouch(MotionEvent e)
    {
        curTouchPosX=e.getX();
        curTouchPosY=e.getY();
        switch(e.getAction())
        {
            case MotionEvent.ACTION_POINTER_DOWN:
            case MotionEvent.ACTION_DOWN:
             
                if(pID!=-1)break;
               
                pID=e.getPointerId(0);
             
                  touchPosY=curTouchPosY;
             
                touchPosX=curTouchPosX;
             
                if(Math.abs(touchPosX-mThread.exitModeMenuFrame.rightButtonPosX)<=(float)mThread.exitModeMenuFrame.rightButtonUpWidth/2f&&
                   Math.abs(touchPosY-mThread.exitModeMenuFrame.rightButtonPosY)<=(float)mThread.exitModeMenuFrame.rightButtonUpHeight/2f)
                {
                    mThread.exitModeMenuFrame.rightButtonDown=true;
                }
             

                if(Math.abs(touchPosX-mThread.exitModeMenuFrame.leftButtonPosX)<=(float)mThread.exitModeMenuFrame.leftButtonUpWidth/2f&&
                   Math.abs(touchPosY-mThread.exitModeMenuFrame.leftButtonPosY)<=(float)mThread.exitModeMenuFrame.leftButtonUpHeight/2f)
                {
                    mThread.exitModeMenuFrame.leftButtonDown=true;
                }
             
                break;
             
            case MotionEvent.ACTION_MOVE:
               
                if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
               
                  if(mThread.exitModeMenuFrame.rightButtonDown
                          &&(Math.abs(curTouchPosX-mThread.exitModeMenuFrame.rightButtonPosX)>(float)mThread.exitModeMenuFrame.rightButtonUpWidth/2f||
                             Math.abs(curTouchPosY-mThread.exitModeMenuFrame.rightButtonPosY)>(float)mThread.exitModeMenuFrame.rightButtonUpHeight/2f))
                  {
                      mThread.exitModeMenuFrame.rightButtonDown=false;
                  }
               

                  if(mThread.exitModeMenuFrame.leftButtonDown
                          &&(Math.abs(curTouchPosX-mThread.exitModeMenuFrame.leftButtonPosX)>(float)mThread.exitModeMenuFrame.leftButtonUpWidth/2f||
                             Math.abs(curTouchPosY-mThread.exitModeMenuFrame.leftButtonPosY)>(float)mThread.exitModeMenuFrame.leftButtonUpHeight/2f))
                  {
                      mThread.exitModeMenuFrame.leftButtonDown=false;
                  }
                  break;
             
            case MotionEvent.ACTION_POINTER_UP:
            case MotionEvent.ACTION_UP:
               
                if(pID==-1||e.getActionIndex()!=e.findPointerIndex(pID))break;
               
                pID=-1;
               
                  if(mThread.exitModeMenuFrame.rightButtonDown&&
                     Math.abs(curTouchPosX-mThread.exitModeMenuFrame.rightButtonPosX)<=(float)mThread.exitModeMenuFrame.rightButtonUpWidth/2f&&
                   Math.abs(curTouchPosY-mThread.exitModeMenuFrame.rightButtonPosY)<=(float)mThread.exitModeMenuFrame.rightButtonUpHeight/2f)
                {
                      mThread.exitModeMenuFrame.anchorY=(float)screenHeight+(float)mThread.menuFrame.height/2f;
                    mThread.exitModeMenuFrame.moving=true;
                    playButtonClick();
                    playMenuExitSound();
                }
               

                  if(mThread.exitModeMenuFrame.leftButtonDown&&
                     Math.abs(curTouchPosX-mThread.exitModeMenuFrame.leftButtonPosX)<=(float)mThread.exitModeMenuFrame.leftButtonUpWidth/2f&&
                   Math.abs(curTouchPosY-mThread.exitModeMenuFrame.leftButtonPosY)<=(float)mThread.exitModeMenuFrame.leftButtonUpHeight/2f)
                {
                      playButtonClick();
                      mAct.finishActivity();
                      mAct.overridePendingTransition(anim.fade_in, anim.fade_out);
                }

                  mThread.exitModeMenuFrame.rightButtonDown=false;
                  mThread.exitModeMenuFrame.leftButtonDown=false;
                break;
        }
    }
 
 
    /**
     * sets the strings for the statistics
     */
    public void setStatisticStrings()
    {
        highScoreString=""+(gamesPlayed==0?"-":highScore);
        starPointsString=""+(gamesPlayed==0?"-":starPoints);
        gamesPlayedString=""+(gamesPlayed==0?"-":gamesPlayed);
        dotsPoppedString=""+(dotsPopped==0?"-":dotsPopped);
     
        if(timePlayed!=0)
        {
            int hours=timePlayed/3600000;
            int minutes=(timePlayed-hours*3600000)/60000;
            int seconds=(timePlayed%60000)/1000;
         
            timePlayedString=""+(hours<10?"0":"")+hours+":"+(minutes<10?"0":"")+minutes+":"+(seconds<10?"0":"")+seconds;
        }
        else
            timePlayedString="-";
     
        int skala=400;
     
        if(dotsPopped==0)
            reactionString="-";
        else if(timePlayed/dotsPopped<skala)
            reactionString="S";
        else if(timePlayed/dotsPopped<skala+50)
            reactionString="A";
        else if(timePlayed/dotsPopped<skala+100)
            reactionString="B";
        else if(timePlayed/dotsPopped<skala+150)
            reactionString="C";
        else if(timePlayed/dotsPopped<skala+200)
            reactionString="D";
        else
            reactionString="X";
     
//        if(dotsPopped!=0)
//            reactionString+=" ("+timePlayed/dotsPopped+")";
     
        avgScoreString=""+(gamesPlayed>0?(int)((float)dotsPopped/(float)gamesPlayed+0.5f):"-");
     
        if(gamesPlayed!=0)
        {
            int hours=timePlayed/gamesPlayed/3600000;
            int minutes=(timePlayed/gamesPlayed-hours*3600000)/60000;
            int seconds=((timePlayed/gamesPlayed)%60000)/1000;
            avgRoundString=""+(hours<10?"0":"")+hours+":"+(minutes<10?"0":"")+minutes+":"+(seconds<10?"0":"")+seconds;
        }
        else
            avgRoundString="-";
    }
 
 
    /**
     * locks the surface's canvas and calls the drawing method of the thread
     */
    public void doDraw()
    {
        if(!surfaceReady)return;
     
        canvas=null;
        try
        {         
            canvas = sHolder.lockCanvas();
            try
            {
                mThread.drawOnCanvas(canvas);
            }
            catch(Throwable t)
            {
//                Log.e("haha","hier ist was passier beim zeichnen",t);
            }
        }
        catch(Throwable t)
        {
            canvas=null;
        }
        finally
        {
            if(canvas!= null)
            {
                sHolder.unlockCanvasAndPost(canvas);
            }
        }
     
    }
 
 
    /**
     * starts the game
     */
    public void startGame()
    {
        stopMediaPlayer();
        releaseMediaPlayer();
        mAct.startActivity(new Intent(mAct,PlayActivity.class));
        mAct.overridePendingTransition(anim.fade_in, anim.fade_out);
        mAct.finishActivity();
    }
 
 
    /**
     * starts the main thread
     */
    public void startMainThread()
    {
        mThread.setRunning(true);
        if(surfaceReady)
        {
            try
            {
                mThread.start();
            }
            catch(RuntimeException e)
            {
            }
        }
    }
 
 
    /**
     * kills the main thread
     */
    public void killMainThread()
    {
        mThread.setPause(true);
        mThread.setRunning(false);
    }


    /**
     * play the menu exit sound
     */
    public void playMenuExitSound()
    {
        if(soundFXOn&&mAct.menuExitSoundLoaded)
        {
            mAct.soundPool.play(mAct.menuExitSoundID, 0.5f, 0.5f, 0, 0, 1.0f);
        }
    }
 
 
    /**
     * play the menu entered sound
     */
    public void playMenuEnterSound()
    {
        if(soundFXOn&&mAct.menuEnterSoundLoaded)
        {
            mAct.soundPool.play(mAct.menuEnterSoundID, 0.5f, 0.5f, 0, 0, 1.0f);
        }
    }
 
 
    /**
     * plays the button click sound
     */
    public void playButtonClick()
    {
        if(soundFXOn&&mAct.buttonClickSoundLoaded)
        {
            mAct.soundPool.play(mAct.buttonClickSoundID, 1f, 1f, 0, 0, 1.0f);
        }
    }
 
 
    /**
     * creates and starts the mediaPlayer
     */
    public void createMediaPlayer()
    {
        new Thread()
        {
            public void run()
            {
                boolean created=true;
                try
                {
                    mediaPlayer=MediaPlayer.create(mAct, R.raw.mainmenumusic);
                }
                catch(Throwable t)
                {
                    created=false;
                }
                finally
                {
                    if(created)
                    {
                        mediaPlayer.setLooping(true);
                        mediaPlayer.setVolume(0.1f, 0.1f);
                        startMediaPlayer();
                    }
                }
            }
        }.start();
    }
 
 
    /**
     * releases the mediaPlayer
     * @return true if mediaPlayer was successfully released
     */
    public boolean releaseMediaPlayer()
    {
        try
        {
            mediaPlayer.release();
            return true;
        }
        catch(Throwable t)
        {
            return false;
        }
    }
 
 
    /**
     * pauses the mediaPlayer
     * @return true if the mediaPlayer was successfully stopped
     */
    public boolean pauseMediaPlayer()
    {
        try
        {
            mediaPlayer.pause();
            return true;
        }
        catch(Throwable t)
        {
            return false;
        }
     
    }
 
 
    /**
     * stops the mediaPlayer
     * @return true if the mediaPlayer was successfully stopped
     */
    public boolean stopMediaPlayer()
    {
        try
        {
            mediaPlayer.stop();
            return true;
        }
        catch(Throwable t)
        {
            return false;
        }
     
    }
 
 
    /**
     * starts the mediaPlayer
     */
    public void startMediaPlayer()
    {
        new Thread()
        {
            public void run()
            {
                boolean retry=true;
                while(retry)
                {
                    try
                    {
                        mediaPlayer.start();
                        retry=false;
                    }
                    catch(Throwable t)
                    {
                        retry=true;
                    }
                }
            }
        }.start();
     
     
     
    }
 
}
 
Zuletzt bearbeitet:
  • Danke
Reaktionen: Hoffimh
MainThread:

Code:
package de.jaielsoft.threads;

import java.util.ArrayList;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Typeface;
import de.jaielsoft.activities.R;
import de.jaielsoft.drawableobjects.BackgroundParticle;
import de.jaielsoft.drawableobjects.DrawableObject;
import de.jaielsoft.drawableobjects.ExitModeMenuFrame;
import de.jaielsoft.drawableobjects.MenuContent;
import de.jaielsoft.drawableobjects.MenuFrame;
import de.jaielsoft.drawableobjects.MenuObject;
import de.jaielsoft.surfaceviews.MainView;
import de.jaielsoft.surfaceviews.MainView.Mode;

public class MainThread extends Thread{
 
    public MainView mView;
 
    public Resources res;
 
    public Typeface typeFace;
 
    public DrawableObject dotLogo=new DrawableObject();
    public DrawableObject playButton=new DrawableObject();
 
    public MenuFrame menuFrame=new MenuFrame();
 
    public MenuObject meButton=new MenuObject();
    public MenuObject highscoreButton=new MenuObject();
    public MenuObject settingsButton=new MenuObject();
    public MenuObject soundButton=new MenuObject();
    public MenuObject exitButton=new MenuObject();
 
    public MenuContent meModeMenuContent=new MenuContent(0,4,0,1,false);
    public MenuContent statisticsModeMenuContent=new MenuContent(6,0,6,0,false);
    public MenuContent settingsModeMenuContent=new MenuContent(2,1,2,5,true);
 
    public ExitModeMenuFrame exitModeMenuFrame=new ExitModeMenuFrame();
 
    //neu
    public MenuContent leaderBordModeMenuContent;
    //neu
 
    public BackgroundParticle[] backgroundParticle;
 
    public ArrayList<MenuObject> mOList=new ArrayList<MenuObject>();
    public ArrayList<BackgroundParticle> backgroundParticleList=new ArrayList<BackgroundParticle>();
 
    public boolean isRunning=false;
    public boolean isPaused=false;
    public boolean changeSoundButton=false;
    public boolean startGame=false;

    public int screenWidth;
    public int screenHeight;
 
    public int starLevelBitmapSize;
    public int starLevel;
 
    public long delTime=0;
    public long oldTime=0;
 
    public float menuButtonDownSize;
    public float menuButtondownFactor;
    public float circleFactor=1f;
    public float leftBound;
    public float rightBound;
 
    public Paint meModeHighScoreTextPaint=new Paint();
    public Paint meModeStarPointsTextPaint=new Paint();
    public Paint meModeHighScoreCountPaint=new Paint();
    public Paint meModeStarPointsCountPaint=new Paint();
    public Paint menuFramePaint=new Paint();
    public Paint alphaPaint=new Paint();
 
    public Bitmap meButtonOrig;
    public Bitmap highscoreButtonOrig;
    public Bitmap settingsButtonOrig;
    public Bitmap soundButtonOnOrig;
    public Bitmap soundButtonOffOrig;
    public Bitmap exitButtonOrig;
    public Bitmap starLevelBitmap;
    public Bitmap meSymbol;
    public Bitmap highscoreSymbol;
    public Bitmap settingsSymbol;
    public Bitmap starShadow;
    public Bitmap backgroundParticleBitmap;
    public Bitmap starBackground;
    public Bitmap playButtonDown;
    public Bitmap statisticsSymbol;
 
 


    /**
     * the constructor
     * @param mView the Mainview's reference
     */
    public MainThread(MainView mView)
    {
        this.mView=mView;
        this.screenHeight=mView.screenHeight;
        this.screenWidth=mView.screenWidth;
        this.res=mView.getResources();
     
        backgroundParticle=new BackgroundParticle[400];
     
        initAll();
        setPaint();
        scaleBitmaps(true);
    }


    /**
     * set the thread in running mode
     * @param run the boolean for running
     */
    public void setRunning(boolean run)
    {
        this.isRunning=run;
    }
 
 
    /**
     * sets the thread in pause mode
     * @param pause the boolean for pause
     */
    public void setPause(boolean pause)
    {
        this.isPaused=pause;
    }
 
 
    /**
     * this is the run method of the main thread
     */
    @Override
    public void run()
    {
        if(mView.musicOn)
            mView.createMediaPlayer();
        float oldPosX=0;
        float alphaValue=255;
        int countDown=100;
        for(MenuObject mObj:mOList)
        {
            oldPosX=mObj.posX;
            mObj.updatePosition();
        }
        while(isRunning)
        {
            delTime=0;
            oldTime=System.currentTimeMillis();
         
         
            while(!isPaused)
            {
                if(alphaValue!=0)
                {
                    alphaValue-=delTime/5f;
                 
                    if(alphaValue<=0)
                        alphaValue=0;
                 
                    alphaPaint.setAlpha((int)alphaValue);
                }
             
                for(BackgroundParticle tBP:backgroundParticleList)
                {
                    tBP.renderParticle(delTime);
                }
             
             
             
                MenuObject.updateAnchorPos(delTime);
             
             
                for(MenuObject mObj:mOList)
                {
                    oldPosX=mObj.posX;
                    mObj.updatePosition(); 
                    if(mView.soundFXOn&&mView.mAct.beepSoundLoaded&&(oldPosX<screenWidth/2f&&mObj.posX>=screenWidth/2f||
                                         oldPosX>screenWidth/2f&&mObj.posX<=screenWidth/2f))
                    {
                        mView.mAct.soundPool.play(mView.mAct.beepSoundID, 0.2f, 0.2f, 0, 0, 1);
                    }
                }
             
             
                menuFrame.updatePosition(delTime);
             
                exitModeMenuFrame.updatePosition(delTime);
             
             
                if(MenuObject.SCALING)
                {
                    scaleBitmaps(false);
                    MenuObject.SCALING=false;
                }
             
                if(changeSoundButton)
                    changeSoundButton();
             
                if(mView.mode!=Mode.MAIN_MODE&&menuFrame.posY==-menuFrame.height/2f&&exitModeMenuFrame.posY==-exitModeMenuFrame.height/2f)
                    mView.mode=Mode.MAIN_MODE;
             
                mView.doDraw();
         
                setDeltaTime();
             
                if(startGame)
                {
                    countDown-=delTime;
                    if(countDown<=0)
                    {
                        countDown=0;
                        break;
                    }
                    if(mView.musicOn)
                    {
                        mView.mediaPlayer.setVolume(0.1f*countDown/100f,0.1f*countDown/100f);
                    }
                }
            }
            if(startGame&&countDown<=0)
                break;
            relax();
        }
     
        if(startGame&&countDown<=0)
            mView.startGame();
    }
 
 
    /**
     * sets the time between two frames
     */
    public void setDeltaTime()
    {
        if(oldTime!=0)
            delTime=System.currentTimeMillis()-oldTime;
        if(delTime<30)
        {
            try
            {
                sleep(30-delTime);
            }
            catch (InterruptedException e)
            {
                return;
            }
            delTime=System.currentTimeMillis()-oldTime;
        }
        if(delTime>50l)delTime=50l;
        oldTime=System.currentTimeMillis();
    }
 
 
    /**
     * send the thread to sleep
     */
    public void relax()
    {
        try
        {
            sleep(100);
        }
        catch (InterruptedException e)
        {
            return;
        }
     
    }
 
 
    /**
     * initializes all objects and variables
     */
    public void initAll()
    {
        leftBound=0.35f*screenWidth;
        rightBound=0.65f*screenWidth;
     
        mOList.add(meButton);
        mOList.add(highscoreButton);
        mOList.add(settingsButton);
        mOList.add(soundButton);
        mOList.add(exitButton);

        meButton.buttonLabel="Me";
        highscoreButton.buttonLabel="Leaderboard";
        settingsButton.buttonLabel="Settings";
        soundButton.buttonLabel="Sound";
        exitButton.buttonLabel="Exit";
     
        DrawableObject.setScreenDimensions(screenWidth, screenHeight);
        MenuObject.setScreenDimensions(screenWidth,screenHeight);
        MenuFrame.setScreenDimensions(screenWidth,screenHeight);
        ExitModeMenuFrame.setScreenDimensions(screenWidth, screenHeight);
        BackgroundParticle.setScreenDimensions(screenWidth, screenHeight);
     
        MenuObject.setBounds((float)(-0.3f*screenWidth),screenWidth/2f);
        MenuObject.setAnchorX(screenWidth/2f);
        MenuObject.setAnchorPosX(screenWidth/2f);
     
     
        //setting their values
     
        menuButtonDownSize=0.18f*(float)screenWidth;
        menuButtondownFactor=0.45f;
     
        starLevelBitmapSize=(int)((float)screenWidth/20f);
     
        exitModeMenuFrame.setBitmapDimensions((int)(screenWidth*0.8f),(int)(screenHeight*0.3f));
        exitModeMenuFrame.initAll();
     
        menuFrame.setBitmapDimensions((int)(screenWidth*0.8f), (int)(screenHeight*0.7f));
        menuFrame.initAll();
     
        dotLogo.setBitmapDimensions(screenWidth, (int)(screenWidth*0.481698f));
        dotLogo.setPos(screenWidth/2f, 4f*starLevelBitmapSize+dotLogo.height/2f);
     
        float spaceForPlayButton=(screenHeight-0.3f*screenWidth-4f*starLevelBitmapSize-dotLogo.height)/2f;
        float playButtonPosY=4f*starLevelBitmapSize+spaceForPlayButton+dotLogo.height;
     
        playButton.setPos(screenWidth/2f,playButtonPosY);
        playButton.setBitmapDimensions((int)(screenHeight*0.35f), (int)(screenHeight*0.35f));
     
     

        for (int i = 0; i < backgroundParticle.length; i++)
        {
            backgroundParticle[i]=new BackgroundParticle(backgroundParticleList);
        }
     
        float X=0;
        for(MenuObject mO:mOList)
        {
            mO.setBitmapDimensions((int)(screenWidth*0.2f),(int)(screenWidth*0.2f));
            mO.setPos(0,(float)(screenHeight-mO.height));
            mO.setDis2AnchorX(X);
            X+=screenWidth*0.2f;
        }
        if(mView.starPoints<250)
        {
            starLevel=0;
        }
        else if(mView.starPoints<1000)
        {
            starLevel=1;
        }
        else if(mView.starPoints<2500)
        {
            starLevel=2;
        }
        else if(mView.starPoints<10000)
        {
            starLevel=3;
        }
        else if(mView.starPoints<25000)
        {
            starLevel=4;
        }
        else if(mView.starPoints<100000)
        {
            starLevel=5;
        }
        else
        {
            starLevel=6;
        }
     
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        meModeMenuContent.centerText[0]="Highscore";
        meModeMenuContent.centerText[1]=mView.highScoreString;
        meModeMenuContent.centerText[2]="Starpoints";
        meModeMenuContent.centerText[3]=mView.starPointsString;

        meModeMenuContent.buttonUpWidth[0]=(int)(menuFrame.width*0.5f);
        meModeMenuContent.buttonUpHeight[0]=(int)(menuFrame.height*0.153f);
     
        meModeMenuContent.buttonDownWidth[0]=(int)(meModeMenuContent.buttonUpWidth[0]*0.9f);
        meModeMenuContent.buttonDownHeight[0]=(int)(meModeMenuContent.buttonUpHeight[0]*0.9f);
     
        meModeMenuContent.buttonDisPosX[0]=menuFrame.width/2f;
        meModeMenuContent.buttonDisPosY[0]=0.95f*menuFrame.height-meModeMenuContent.buttonUpHeight[0]/2f;
     
        for(int i=0;i<meModeMenuContent.centerTextCount;i++)
        {
            meModeMenuContent.centerTextDisPosX[i]=menuFrame.width*0.925f;
        }
     
     
        float space=(0.91f*menuFrame.height-meModeMenuContent.buttonUpHeight[0]-0.06f*menuFrame.width-menuFrame.symbolHeight);
     
        meModeMenuContent.centerTextDisPosY[0]=menuFrame.symbolPosYOffSet+space*0.28f;
        meModeMenuContent.centerTextDisPosY[1]=menuFrame.symbolPosYOffSet+space*0.44f;
        meModeMenuContent.centerTextDisPosY[2]=menuFrame.symbolPosYOffSet+space*0.68f;
        meModeMenuContent.centerTextDisPosY[3]=menuFrame.symbolPosYOffSet+space*0.84f;
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
     
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        statisticsModeMenuContent.leftText[0]="Games";
        statisticsModeMenuContent.leftText[1]="Dots popped";
        statisticsModeMenuContent.leftText[2]="Playtime";
        statisticsModeMenuContent.leftText[3]="Reaction";
        statisticsModeMenuContent.leftText[4]="Avg. Score";
        statisticsModeMenuContent.leftText[5]="Avg Round";
     
        statisticsModeMenuContent.rightText[0]=mView.gamesPlayedString;
        statisticsModeMenuContent.rightText[1]=mView.dotsPoppedString;
        statisticsModeMenuContent.rightText[2]=mView.timePlayedString;
        statisticsModeMenuContent.rightText[3]=mView.reactionString;
        statisticsModeMenuContent.rightText[4]=mView.avgScoreString;
        statisticsModeMenuContent.rightText[5]=mView.avgRoundString;
     
        space=menuFrame.height-menuFrame.symbolPosYOffSet;
     
        float anchorPosY=menuFrame.symbolPosYOffSet+space/12f+menuFrame.height/50f/1.4f;
        float stepPosY=space/6f;
     
        for(int i=0;i<statisticsModeMenuContent.leftTextCount;i++)
        {
            statisticsModeMenuContent.leftTextDisPosX[i]=0.075f*menuFrame.width;
            statisticsModeMenuContent.rightTextDisPosX[i]=0.925f*menuFrame.width;
            statisticsModeMenuContent.leftTextDisPosY[i]=statisticsModeMenuContent.rightTextDisPosY[i]=anchorPosY+stepPosY*i;
        }     
        ////////////////////////////////////////////////////////////////////////////////////////////////////////

        ////////////////////////////////////////////////////////////////////////////////////////////////////////
        anchorPosY=menuFrame.symbolPosYOffSet;
     
        settingsModeMenuContent.leftText[0]="Sound FX";
        settingsModeMenuContent.leftText[1]="Notification";
     
        settingsModeMenuContent.centerText[0]="No Ads";
     
        settingsModeMenuContent.rightText[0]="Music";
        settingsModeMenuContent.rightText[1]="Vibration";
     
        settingsModeMenuContent.buttonDisPosX[0]=settingsModeMenuContent.buttonDisPosX[2]=
        settingsModeMenuContent.leftTextDisPosX[0]=settingsModeMenuContent.leftTextDisPosX[1]=menuFrame.width*0.275f;
     
        settingsModeMenuContent.buttonDisPosX[1]=settingsModeMenuContent.buttonDisPosX[3]=
        settingsModeMenuContent.rightTextDisPosX[0]=settingsModeMenuContent.rightTextDisPosX[1]=menuFrame.width*0.725f;
     
        settingsModeMenuContent.buttonDisPosX[4]=settingsModeMenuContent.centerTextDisPosX[0]=menuFrame.width/2f;

        settingsModeMenuContent.buttonDisPosY[0]=settingsModeMenuContent.buttonDisPosY[1]=menuFrame.symbolPosYOffSet+0.18f*space;
     
        settingsModeMenuContent.buttonDisPosY[2]=settingsModeMenuContent.buttonDisPosY[3]=menuFrame.symbolPosYOffSet+0.48f*space;
     
        settingsModeMenuContent.buttonDisPosY[4]=menuFrame.symbolPosYOffSet+0.78f*space;
     
        for(int i=0;i<settingsModeMenuContent.buttonCount;i++)
        {
            settingsModeMenuContent.buttonUpHeight[i]=(int)(space*0.16f);
            settingsModeMenuContent.buttonDownHeight[i]=(int)(settingsModeMenuContent.buttonUpHeight[i]*0.9f);
        }
     
     
        for(int i=0;i<settingsModeMenuContent.buttonCount-1;i++)
        {
            settingsModeMenuContent.buttonUpWidth[i]=(int)(menuFrame.width*0.35f);
            settingsModeMenuContent.buttonDownWidth[i]=(int)(settingsModeMenuContent.buttonUpWidth[i]*0.9f);
        }
     
        settingsModeMenuContent.buttonUpWidth[4]=(int)(menuFrame.width*0.35f);
     
        settingsModeMenuContent.buttonDownWidth[4]=(int)(settingsModeMenuContent.buttonUpWidth[4]*0.9f);
     
        settingsModeMenuContent.leftTextDisPosY[0]=settingsModeMenuContent.rightTextDisPosY[0]=menuFrame.symbolPosYOffSet+0.3f*space;
     
        settingsModeMenuContent.leftTextDisPosY[1]=settingsModeMenuContent.rightTextDisPosY[1]=menuFrame.symbolPosYOffSet+0.6f*space;
     
        settingsModeMenuContent.centerTextDisPosY[0]=menuFrame.symbolPosYOffSet+0.9f*space;
        ////////////////////////////////////////////////////////////////////////////////////////////////////////
    }
 
 
    /**
     * initializes the Paint objects
     */
    public void setPaint()
    {     
        typeFace=Typeface.createFromAsset(mView.mAct.getAssets(), "fonts/font.ttf");
     

        for(MenuObject mO:mOList)
        {
            mO.menuLabelPaint.setTypeface(typeFace);
            mO.menuLabelPaint.setTextSize((float)screenWidth/24f);
            mO.menuLabelPaint.setColor(Color.WHITE);
            mO.menuLabelPaint.setTextAlign(Align.CENTER);
        }
     
        MenuFrame.symbolLabelPaint.setTypeface(typeFace);
        MenuFrame.symbolLabelPaint.setTextSize(1.2f*menuFrame.symbolHeight);
        MenuFrame.symbolLabelPaint.setColor(Color.BLACK);
        MenuFrame.symbolLabelPaint.setTextAlign(Align.CENTER);
     
        menuFramePaint.setAlpha(225);


        meModeHighScoreTextPaint.setTextAlign(Align.RIGHT);
        meModeHighScoreTextPaint.setTypeface(typeFace);
        meModeHighScoreTextPaint.setTextSize(menuFrame.height*0.09f);
        meModeHighScoreTextPaint.setColor(Color.rgb(100,0,0));
     
        meModeStarPointsTextPaint.setTextAlign(Align.RIGHT);
        meModeStarPointsTextPaint.setTypeface(typeFace);
        meModeStarPointsTextPaint.setTextSize(menuFrame.height*0.09f);
        meModeStarPointsTextPaint.setColor(Color.rgb(100,100,25));
     
        meModeHighScoreCountPaint.setTextAlign(Align.RIGHT);
        meModeHighScoreCountPaint.setTypeface(typeFace);
        meModeHighScoreCountPaint.setTextSize(menuFrame.height*0.14f);
        meModeHighScoreCountPaint.setColor(Color.rgb(145,0,0));
     
        meModeStarPointsCountPaint.setTextAlign(Align.RIGHT);
        meModeStarPointsCountPaint.setTypeface(typeFace);
        meModeStarPointsCountPaint.setTextSize(menuFrame.height*0.14f);
        meModeStarPointsCountPaint.setColor(Color.rgb(150,150,45));
     
        statisticsModeMenuContent.leftPaint.setTypeface(typeFace);
        statisticsModeMenuContent.leftPaint.setTextSize(menuFrame.height/20f);
     
        statisticsModeMenuContent.rightPaint.setTypeface(typeFace);
        statisticsModeMenuContent.rightPaint.setTextSize(menuFrame.height/20f);
        statisticsModeMenuContent.rightPaint.setTextAlign(Align.RIGHT);
     
        settingsModeMenuContent.leftPaint.setTypeface(typeFace);
        settingsModeMenuContent.leftPaint.setTextSize((menuFrame.height-menuFrame.symbolPosYOffSet)/25f);
        settingsModeMenuContent.leftPaint.setTextAlign(Align.CENTER);
     
        settingsModeMenuContent.centerPaint.setTypeface(typeFace);
        settingsModeMenuContent.centerPaint.setTextSize((menuFrame.height-menuFrame.symbolPosYOffSet)/25f);
        settingsModeMenuContent.centerPaint.setTextAlign(Align.CENTER);
     
        settingsModeMenuContent.rightPaint.setTypeface(typeFace);
        settingsModeMenuContent.rightPaint.setTextSize((menuFrame.height-menuFrame.symbolPosYOffSet)/25f);
        settingsModeMenuContent.rightPaint.setTextAlign(Align.CENTER);
     

        exitModeMenuFrame.textPaint.setTypeface(typeFace);
        exitModeMenuFrame.textPaint.setTextSize(exitModeMenuFrame.height*14f/40f);
        exitModeMenuFrame.textPaint.setTextAlign(Align.CENTER);
        exitModeMenuFrame.textPaint.setColor(Color.rgb(100,0,0));
    }
 
 
    /**
     * draws all bitmaps on the canvas of the surface
     * @param canvas the locked canvas to draw to
     */
    public void drawOnCanvas(Canvas canvas)
    {     
        if(canvas==null)return;
        canvas.drawColor(Color.BLACK);
     
        for(BackgroundParticle tBP:backgroundParticleList)
        {
            canvas.drawBitmap(backgroundParticleBitmap,
                              tBP.posX-BackgroundParticle.OBJECT_SIZE/2f,
                              tBP.posY-BackgroundParticle.OBJECT_SIZE/2f,
                              tBP.backgroundParticlePaint);
        }
     
        if(!mView.playButtonDown)
            canvas.drawBitmap(playButton.bmp,playButton.posX-playButton.width/2f,playButton.posY-playButton.height/2f,null);
        else
            canvas.drawBitmap(playButtonDown,playButton.posX-playButton.width*0.45f,playButton.posY-playButton.height*0.45f,null);
     
        canvas.drawBitmap(dotLogo.bmp,dotLogo.posX-dotLogo.width/2f,dotLogo.posY-dotLogo.height/2f,null);
     
        float starStep=((float)screenWidth*0.85f)/5f;
        float position=screenWidth*0.075f;
        for(int i=0;i<starLevel;i++,position+=starStep)
        {
            canvas.drawBitmap(starLevelBitmap,position-starLevelBitmapSize/2f,starLevelBitmapSize/2f,null);
            canvas.drawBitmap(starBackground,position-starLevelBitmapSize,0,null);
        }
     
     
        for(int i=0;i<6-starLevel;i++,position+=starStep)
        {
            canvas.drawBitmap(starShadow,position-starLevelBitmapSize/2f,starLevelBitmapSize/2f,null);
        }
     
         
        drawInOrder(canvas);
     
        for(MenuObject mO:mOList)
        {
            if(mO.menuLabelShowable)
            {
                canvas.drawText(mO.buttonLabel,
                                (float)screenWidth/2f,
                                mO.posY+0.1f*(float)screenWidth+(float)screenWidth/18f, mO.menuLabelPaint);
                break;
            }
        }
     
        if(menuFrame.posY>-menuFrame.height/2f&&menuFrame.posY<screenHeight+menuFrame.height/2f)
        {
            canvas.drawBitmap(menuFrame.bmp,menuFrame.posX-menuFrame.width/2f,menuFrame.posY-menuFrame.height/2f,menuFramePaint);
         
            canvas.drawBitmap(mView.closeButtonDown?menuFrame.closeButtonDownBitmap:menuFrame.closeButtonUpBitmap,
                              mView.closeButtonDown?menuFrame.closeButtonPosX-0.9f*menuFrame.closeButtonWidth/2f:menuFrame.closeButtonPosX-menuFrame.closeButtonWidth/2f,
                              mView.closeButtonDown?menuFrame.closeButtonPosY-0.9f*menuFrame.closeButtonHeight/2f:menuFrame.closeButtonPosY-menuFrame.closeButtonHeight/2f,
                              menuFramePaint);
         
            canvas.drawBitmap(menuFrame.symbolBitmap,menuFrame.symbolPosX-menuFrame.symbolWidth/2f,menuFrame.symbolPosY-menuFrame.symbolHeight/2f,menuFramePaint);

            canvas.drawText(MenuFrame.symbolLabel,screenWidth/2f+0.0035f*menuFrame.height,menuFrame.symbolPosY+menuFrame.symbolHeight*0.4f,MenuFrame.symbolLabelPaint);
         
     
     
     
            if(mView.mode==Mode.ME_MODE)
            {
                meModeMenuContent.updatePositions(menuFrame.posX-menuFrame.width/2f, menuFrame.posY-menuFrame.height/2f);
             
                canvas.drawText(meModeMenuContent.centerText[0],meModeMenuContent.centerTextPosX[0],meModeMenuContent.centerTextPosY[0],meModeHighScoreTextPaint);
                canvas.drawText(meModeMenuContent.centerText[1],meModeMenuContent.centerTextPosX[1],meModeMenuContent.centerTextPosY[1],meModeHighScoreCountPaint);
                canvas.drawText(meModeMenuContent.centerText[2],meModeMenuContent.centerTextPosX[2],meModeMenuContent.centerTextPosY[2],meModeStarPointsTextPaint);
                canvas.drawText(meModeMenuContent.centerText[3],meModeMenuContent.centerTextPosX[3],meModeMenuContent.centerTextPosY[3],meModeStarPointsCountPaint);
             
             
                canvas.drawBitmap(meModeMenuContent.buttonDown[0]?
                        meModeMenuContent.buttonDownBitmap[0]:meModeMenuContent.buttonUpBitmap[0],
                        meModeMenuContent.buttonDown[0]?
                        meModeMenuContent.buttonPosX[0]-meModeMenuContent.buttonDownWidth[0]/2f:meModeMenuContent.buttonPosX[0]-meModeMenuContent.buttonUpWidth[0]/2f,
                        meModeMenuContent.buttonDown[0]?
                        meModeMenuContent.buttonPosY[0]-meModeMenuContent.buttonDownHeight[0]/2f:meModeMenuContent.buttonPosY[0]-meModeMenuContent.buttonUpHeight[0]/2f,     
                        null);
             
            }
            else if(mView.mode==Mode.STATISTICS_MODE)
            {
                statisticsModeMenuContent.updatePositions(menuFrame.posX-menuFrame.width/2f, menuFrame.posY-menuFrame.height/2f);
                for(int i=0;i<statisticsModeMenuContent.leftTextCount;i++)
                {
                    if(i==3)
                    {
                        if(statisticsModeMenuContent.rightText[i].equals("A"))
                            statisticsModeMenuContent.rightPaint.setColor(Color.rgb(48, 192, 0));
                        else if(statisticsModeMenuContent.rightText[i].equals("B"))
                            statisticsModeMenuContent.rightPaint.setColor(Color.rgb(96, 144, 0));
                        else if(statisticsModeMenuContent.rightText[i].equals("C"))
                            statisticsModeMenuContent.rightPaint.setColor(Color.rgb(144, 96, 0));
                        else if(statisticsModeMenuContent.rightText[i].equals("D"))
                            statisticsModeMenuContent.rightPaint.setColor(Color.rgb(192, 48, 0));
                        else if(statisticsModeMenuContent.rightText[i].equals("X"))
                            statisticsModeMenuContent.rightPaint.setColor(Color.rgb(240, 0, 0));
                        else if(statisticsModeMenuContent.rightText[i].equals("S"))
                            statisticsModeMenuContent.rightPaint.setColor(Color.rgb(0, 240, 0));
                    }
                    canvas.drawText(statisticsModeMenuContent.leftText[i], statisticsModeMenuContent.leftTextPosX[i], statisticsModeMenuContent.leftTextPosY[i], statisticsModeMenuContent.leftPaint);
                    canvas.drawText(statisticsModeMenuContent.rightText[i], statisticsModeMenuContent.rightTextPosX[i], statisticsModeMenuContent.rightTextPosY[i], statisticsModeMenuContent.rightPaint);
                    if(i==3)
                    {
                        statisticsModeMenuContent.rightPaint.setColor(Color.BLACK);
                    }
                }
             
            }
            else if(mView.mode==Mode.SETTINGS_MODE)
            {
                settingsModeMenuContent.updatePositions(menuFrame.posX-menuFrame.width/2f, menuFrame.posY-menuFrame.height/2f);
                for(int i=0;i<settingsModeMenuContent.leftTextCount;i++)
                {
                    canvas.drawText(settingsModeMenuContent.leftText[i],settingsModeMenuContent.leftTextPosX[i],settingsModeMenuContent.leftTextPosY[i],settingsModeMenuContent.leftPaint);
                    canvas.drawText(settingsModeMenuContent.rightText[i],settingsModeMenuContent.rightTextPosX[i],settingsModeMenuContent.rightTextPosY[i],settingsModeMenuContent.rightPaint);
                 
                }
             
                canvas.drawText(settingsModeMenuContent.centerText[0],settingsModeMenuContent.centerTextPosX[0],settingsModeMenuContent.centerTextPosY[0],settingsModeMenuContent.centerPaint);
             
                boolean buttonChecked[]={false,false,false,false,false};
                if(mView.soundFXOn)
                {
                    buttonChecked[0]=true;
                }
                if(mView.musicOn)
                {
                    buttonChecked[1]=true;
                }
                if(mView.notificationOn)
                {
                    buttonChecked[2]=true;
                }
                if(mView.vibrationOn)
                {
                    buttonChecked[3]=true;
                }
             
                for(int i=0;i<settingsModeMenuContent.buttonCount;i++)
                {
                 
                    settingsModeMenuContent.drawButton(canvas,i,settingsModeMenuContent.buttonDown[i],buttonChecked[i]);
                 
                }
            } 
        }
     
        if(exitModeMenuFrame.posY>-exitModeMenuFrame.height/2f&&exitModeMenuFrame.posY<screenHeight+exitModeMenuFrame.height/2f)
        {
            canvas.drawBitmap(exitModeMenuFrame.bmp,exitModeMenuFrame.posX-exitModeMenuFrame.width/2f,
                              exitModeMenuFrame.posY-exitModeMenuFrame.height/2f,menuFramePaint);
         
            if(exitModeMenuFrame.leftButtonDown)
                canvas.drawBitmap(exitModeMenuFrame.leftButtonDownBitmap,
                                    exitModeMenuFrame.leftButtonPosX-exitModeMenuFrame.leftButtonDownWidth/2f,
                                    exitModeMenuFrame.leftButtonPosY-exitModeMenuFrame.leftButtonDownHeight/2f,null);
            else
                canvas.drawBitmap(exitModeMenuFrame.leftButtonUpBitmap,
                                      exitModeMenuFrame.leftButtonPosX-exitModeMenuFrame.leftButtonUpWidth/2f,
                                      exitModeMenuFrame.leftButtonPosY-exitModeMenuFrame.leftButtonUpHeight/2f,null);

            if(exitModeMenuFrame.rightButtonDown)
                canvas.drawBitmap(exitModeMenuFrame.rightButtonDownBitmap,
                                    exitModeMenuFrame.rightButtonPosX-exitModeMenuFrame.rightButtonDownWidth/2f,
                                    exitModeMenuFrame.rightButtonPosY-exitModeMenuFrame.rightButtonDownHeight/2f,null);
            else
                canvas.drawBitmap(exitModeMenuFrame.rightButtonUpBitmap,
                                      exitModeMenuFrame.rightButtonPosX-exitModeMenuFrame.rightButtonUpWidth/2f,
                                      exitModeMenuFrame.rightButtonPosY-exitModeMenuFrame.rightButtonUpHeight/2f,null);
             
         
            canvas.drawText("Exit?",exitModeMenuFrame.textPosX,exitModeMenuFrame.textPosY,exitModeMenuFrame.textPaint);         
        }
     
        if(alphaPaint.getAlpha()!=0)
            canvas.drawPaint(alphaPaint);
    }
 
     
    /**
     * draws the menu buttons in the right order
     * @param canvas the locked canvas to draw to
     */
    public void drawInOrder(Canvas canvas)
    {
     
        if(MenuObject.ANCHOR_POS_X>=-0.3f*screenWidth&&MenuObject.ANCHOR_POS_X<=-0.1f*screenWidth)
        {
            drawExitButton(canvas);     
            if((int)(MenuObject.ANCHOR_POS_X-0.5d)!=(int)(-0.3d*screenWidth))drawSettingsButton(canvas);
            drawSoundButton(canvas);
        }
        else if(MenuObject.ANCHOR_POS_X>-0.1f*screenWidth&&MenuObject.ANCHOR_POS_X<=0.1f*screenWidth)
        {         
            drawHighscoreButton(canvas);
            if((int)(MenuObject.ANCHOR_POS_X+0.5d)!=(int)(0.1d*screenWidth))drawExitButton(canvas);
            drawSoundButton(canvas);     
            drawSettingsButton(canvas);
        }
        else
        {         
            drawMeButton(canvas);
            if(MenuObject.ANCHOR_POS_X<0.3f*screenWidth)drawSoundButton(canvas);
            if(MenuObject.ANCHOR_POS_X!=0.5f*screenWidth)drawSettingsButton(canvas);
            drawHighscoreButton(canvas);
        }
    }
 
 
    /**
     * draws the me button
     * @param canvas the locked canvas to draw to
     */
    public void drawMeButton(Canvas canvas)
    {
        if(mView.meButtonDown)
            canvas.drawBitmap(meButtonOrig,meButton.posX<leftBound?
                            leftBound-meButton.width*menuButtondownFactor:meButton.posX-meButton.width*menuButtondownFactor,
                            meButton.posY-meButton.width*menuButtondownFactor,null);
        else
            canvas.drawBitmap(meButton.bmp,meButton.posX<leftBound?
                            leftBound-meButton.width/2f:meButton.posX-meButton.width/2f,
                            meButton.posY-meButton.width/2f,null);

        canvas.drawCircle(meButton.posX<leftBound?
                        leftBound:meButton.posX,meButton.posY,
                        circleFactor*meButton.width/2f,meButton.buttonShadowPaint);
    }
 
     
    /**
     * draws the highscore button
     * @param canvas the locked canvas to draw to
     */
    public void drawHighscoreButton(Canvas canvas)
    {
        if(mView.highscoreButtonDown)
            canvas.drawBitmap(highscoreButtonOrig,highscoreButton.posX<leftBound?
                            leftBound-highscoreButton.width*menuButtondownFactor:highscoreButton.posX>rightBound?
                            rightBound-highscoreButton.width*menuButtondownFactor:highscoreButton.posX-highscoreButton.width*menuButtondownFactor,
                            highscoreButton.posY-highscoreButton.width*menuButtondownFactor,null);
        else
            canvas.drawBitmap(highscoreButton.bmp,highscoreButton.posX<leftBound?
                            leftBound-highscoreButton.width/2f:highscoreButton.posX>rightBound?
                            rightBound-highscoreButton.width/2f:highscoreButton.posX-highscoreButton.width/2f,
                            highscoreButton.posY-highscoreButton.width/2f,null);

        canvas.drawCircle(highscoreButton.posX<leftBound?
                        leftBound:highscoreButton.posX>rightBound?
                        rightBound:highscoreButton.posX,
                        highscoreButton.posY,circleFactor*highscoreButton.width/2f,highscoreButton.buttonShadowPaint);
    }

 
    /**
     * draws the settings button
     * @param canvas the locked canvas to draw to
     */
    public void drawSettingsButton(Canvas canvas)
    {
        if(mView.settingsButtonDown)
            canvas.drawBitmap(settingsButtonOrig,settingsButton.posX<leftBound?
                            leftBound-settingsButton.width*menuButtondownFactor:settingsButton.posX>rightBound?
                            rightBound-settingsButton.width*menuButtondownFactor:settingsButton.posX-settingsButton.width*menuButtondownFactor,
                            settingsButton.posY-settingsButton.width*menuButtondownFactor,null);
        else
            canvas.drawBitmap(settingsButton.bmp,settingsButton.posX<leftBound?
                            leftBound-settingsButton.width/2f:settingsButton.posX>rightBound?
                            rightBound-settingsButton.width/2f:settingsButton.posX-settingsButton.width/2f,
                            settingsButton.posY-settingsButton.width/2f,null);

        canvas.drawCircle(settingsButton.posX<leftBound?
                        leftBound:settingsButton.posX>rightBound?
                        rightBound:settingsButton.posX,settingsButton.posY,
                        circleFactor*settingsButton.width/2f,settingsButton.buttonShadowPaint);
    }
 
 
    /**
     * draws the sound button
     * @param canvas the locked canvas to draw to
     */
    public void drawSoundButton(Canvas canvas)
    {
        if(mView.soundButtonDown)
            canvas.drawBitmap(mView.soundOn?soundButtonOnOrig:soundButtonOffOrig,soundButton.posX<leftBound?
                            leftBound-soundButton.width*menuButtondownFactor:soundButton.posX>rightBound?
                            rightBound-soundButton.width*menuButtondownFactor:soundButton.posX-soundButton.width*menuButtondownFactor,
                            soundButton.posY-soundButton.width*menuButtondownFactor,null);
        else
            canvas.drawBitmap(soundButton.bmp,soundButton.posX<leftBound?
                            leftBound-soundButton.width/2f:soundButton.posX>rightBound?
                            rightBound-soundButton.width/2f:soundButton.posX-soundButton.width/2f,
                            soundButton.posY-soundButton.width/2f,null);

        canvas.drawCircle(soundButton.posX<leftBound?
                        leftBound:soundButton.posX>rightBound?
                        rightBound:soundButton.posX,soundButton.posY,
                        circleFactor*soundButton.width/2f,soundButton.buttonShadowPaint);
    }
 
 
    /**
     * draws the exit button
     * @param canvas the locked canvas to draw to
     */
    public void drawExitButton(Canvas canvas)
    {
        if(mView.exitButtonDown)
            canvas.drawBitmap(exitButtonOrig,exitButton.posX>rightBound?
                            rightBound-exitButton.width*menuButtondownFactor:exitButton.posX-exitButton.width*menuButtondownFactor,
                            exitButton.posY-exitButton.width*menuButtondownFactor,null);
        else
            canvas.drawBitmap(exitButton.bmp,exitButton.posX>rightBound?
                            rightBound-exitButton.width/2f:exitButton.posX-exitButton.width/2f,
                            exitButton.posY-exitButton.width/2f,null);
     
        canvas.drawCircle(exitButton.posX>rightBound?
                        rightBound:exitButton.posX,exitButton.posY,
                        circleFactor*exitButton.width/2f,exitButton.buttonShadowPaint);
    }
 
 
    /**
     * changes the x position of the menu's anchor
     * @param delPosX the delta x to change
     */
    public void changePosX(float delPosX)
    {
        MenuObject.setAnchorPosX(MenuObject.ANCHOR_POS_X+delPosX);
    }
 
 
    /**
     * scales all bitmaps
     * @param firstTime if this is set to true it is the first time to scale them
     */
    public void scaleBitmaps(boolean firstTime)
    {
        if(firstTime)
        {         
            dotLogo.bmp=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.dotlogo),
                    dotLogo.width,dotLogo.height,true);
         
            playButton.bmp=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.playbutton),
                    playButton.width,playButton.height,true);
         
            playButtonDown=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.playbuttondown),
                    (int)(playButton.width*0.9f),(int)(playButton.height*0.9f),true);

            backgroundParticleBitmap=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.dotwhite),
                    BackgroundParticle.OBJECT_SIZE,BackgroundParticle.OBJECT_SIZE,true);
         
            starBackground=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.backgroundparticle),
                    2*starLevelBitmapSize,2*starLevelBitmapSize,true);
         

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            menuFrame.bmp=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.frame),
                    menuFrame.width,menuFrame.height,true);

            menuFrame.closeButtonDownBitmap=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.closebuttondown),
                    (int)(menuFrame.closeButtonWidth*0.9f),(int)(menuFrame.closeButtonHeight*0.9f),true);
         
            menuFrame.closeButtonUpBitmap=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.closebuttonup),
                    (int)(menuFrame.closeButtonWidth),(int)(menuFrame.closeButtonHeight),true);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////

            meSymbol=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.mesymbol),
                    (int)(menuFrame.symbolWidth),(int)(menuFrame.symbolHeight),true);
            highscoreSymbol=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.highscoresymbol),
                    (int)(menuFrame.symbolWidth),(int)(menuFrame.symbolHeight),true);
            settingsSymbol=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.settingssymbol),
                    (int)(menuFrame.symbolWidth),(int)(menuFrame.symbolHeight),true);
            statisticsSymbol=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.statisticssymbol),
                    (int)(menuFrame.symbolWidth),(int)(menuFrame.symbolHeight),true);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            meButtonOrig=meButton.bmp=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.mebutton),
                    (int)(menuButtonDownSize),(int)(menuButtonDownSize),true);
         
            highscoreButtonOrig=highscoreButton.bmp=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.highscorebutton),
                    (int)(menuButtonDownSize),(int)(menuButtonDownSize),true);
         
            settingsButtonOrig=settingsButton.bmp=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.settingsbutton),
                    (int)(menuButtonDownSize),(int)(menuButtonDownSize),true);
         
            soundButtonOnOrig=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.soundonbutton),
                    (int)(menuButtonDownSize),(int)(menuButtonDownSize),true);
         
            soundButtonOffOrig=Bitmap.createScaledBitmap(
                        BitmapFactory.decodeResource(res,R.drawable.soundoffbutton),
                        (int)(menuButtonDownSize),(int)(menuButtonDownSize),true);
         
            soundButton.bmp=mView.soundOn?soundButtonOnOrig:soundButtonOffOrig;
         
            exitButtonOrig=exitButton.bmp=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.exitbutton),
                    (int)(menuButtonDownSize),(int)(menuButtonDownSize),true);
         
            starLevelBitmap=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.star),
                    starLevelBitmapSize,starLevelBitmapSize,true);
         
            starShadow=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.starshadow),
                    starLevelBitmapSize,starLevelBitmapSize,true);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            meModeMenuContent.buttonUpBitmap[0]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.statisticsbutton),
                    meModeMenuContent.buttonUpWidth[0],meModeMenuContent.buttonUpHeight[0],true);
         
            meModeMenuContent.buttonDownBitmap[0]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.statisticsbutton),
                    meModeMenuContent.buttonDownWidth[0],meModeMenuContent.buttonDownHeight[0],true);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////

            ////////////////////////////////////////////////////////////////////////////////////////////////////////     
            settingsModeMenuContent.buttonUpBitmap[0]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.soundfxoff),
                    settingsModeMenuContent.buttonUpWidth[0],settingsModeMenuContent.buttonUpHeight[0],true);
         
            settingsModeMenuContent.buttonUpBitmap[1]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.musicoff),
                    settingsModeMenuContent.buttonUpWidth[1],settingsModeMenuContent.buttonUpHeight[1],true);
         
            settingsModeMenuContent.buttonUpBitmap[2]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.notificationoff),
                    settingsModeMenuContent.buttonUpWidth[2],settingsModeMenuContent.buttonUpHeight[2],true);
         
            settingsModeMenuContent.buttonUpBitmap[3]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.vibrationoff),
                    settingsModeMenuContent.buttonUpWidth[3],settingsModeMenuContent.buttonUpHeight[3],true);
         
            settingsModeMenuContent.buttonUpBitmap[4]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.noadsbutton),
                    settingsModeMenuContent.buttonUpWidth[4],settingsModeMenuContent.buttonUpHeight[4],true);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            settingsModeMenuContent.buttonDownBitmap[0]=Bitmap.createScaledBitmap(
                    settingsModeMenuContent.buttonUpBitmap[0],
                    settingsModeMenuContent.buttonDownWidth[0],settingsModeMenuContent.buttonDownHeight[0],true);
         
            settingsModeMenuContent.buttonDownBitmap[1]=Bitmap.createScaledBitmap(
                    settingsModeMenuContent.buttonUpBitmap[1],
                    settingsModeMenuContent.buttonDownWidth[1],settingsModeMenuContent.buttonDownHeight[1],true);
         
            settingsModeMenuContent.buttonDownBitmap[2]=Bitmap.createScaledBitmap(
                    settingsModeMenuContent.buttonUpBitmap[2],
                    settingsModeMenuContent.buttonDownWidth[2],settingsModeMenuContent.buttonDownHeight[2],true);
         
            settingsModeMenuContent.buttonDownBitmap[3]=Bitmap.createScaledBitmap(
                    settingsModeMenuContent.buttonUpBitmap[3],
                    settingsModeMenuContent.buttonDownWidth[3],settingsModeMenuContent.buttonDownHeight[3],true);
         
            settingsModeMenuContent.buttonDownBitmap[4]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.noadsbutton),
                    settingsModeMenuContent.buttonDownWidth[4],settingsModeMenuContent.buttonDownHeight[4],true);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////

            ////////////////////////////////////////////////////////////////////////////////////////////////////////     
            settingsModeMenuContent.buttonSelectedUpBitmap[0]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.soundfxon),
                    settingsModeMenuContent.buttonUpWidth[0],settingsModeMenuContent.buttonUpHeight[0],true);
         
            settingsModeMenuContent.buttonSelectedUpBitmap[1]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.musicon),
                    settingsModeMenuContent.buttonUpWidth[1],settingsModeMenuContent.buttonUpHeight[1],true);
         
            settingsModeMenuContent.buttonSelectedUpBitmap[2]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.notificationon),
                    settingsModeMenuContent.buttonUpWidth[2],settingsModeMenuContent.buttonUpHeight[2],true);
         
            settingsModeMenuContent.buttonSelectedUpBitmap[3]=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.vibrationon),
                    settingsModeMenuContent.buttonUpWidth[3],settingsModeMenuContent.buttonUpHeight[3],true);
         
            ////////////////////////////////////////////////////////////////////////////////////////////////////////

            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            settingsModeMenuContent.buttonSelectedDownBitmap[0]=Bitmap.createScaledBitmap(
                    settingsModeMenuContent.buttonSelectedUpBitmap[0],
                    settingsModeMenuContent.buttonDownWidth[0],settingsModeMenuContent.buttonDownHeight[0],true);
         
            settingsModeMenuContent.buttonSelectedDownBitmap[1]=Bitmap.createScaledBitmap(
                    settingsModeMenuContent.buttonSelectedUpBitmap[1],
                    settingsModeMenuContent.buttonDownWidth[1],settingsModeMenuContent.buttonDownHeight[1],true);
         
            settingsModeMenuContent.buttonSelectedDownBitmap[2]=Bitmap.createScaledBitmap(
                    settingsModeMenuContent.buttonSelectedUpBitmap[2],
                    settingsModeMenuContent.buttonDownWidth[2],settingsModeMenuContent.buttonDownHeight[2],true);
         
            settingsModeMenuContent.buttonSelectedDownBitmap[3]=Bitmap.createScaledBitmap(
                    settingsModeMenuContent.buttonSelectedUpBitmap[3],
                    settingsModeMenuContent.buttonDownWidth[3],settingsModeMenuContent.buttonDownHeight[3],true);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////


            ////////////////////////////////////////////////////////////////////////////////////////////////////////
            exitModeMenuFrame.bmp=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.exitframe),
                    exitModeMenuFrame.width,exitModeMenuFrame.height,true);
         
            exitModeMenuFrame.leftButtonDownBitmap=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.okbutton),
                    (int)exitModeMenuFrame.leftButtonDownWidth,(int)exitModeMenuFrame.leftButtonDownHeight,true);
         
            exitModeMenuFrame.leftButtonUpBitmap=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.okbutton),
                    (int)exitModeMenuFrame.leftButtonUpWidth,(int)exitModeMenuFrame.leftButtonUpHeight,true);
         
            exitModeMenuFrame.rightButtonDownBitmap=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.xbutton),
                    (int)exitModeMenuFrame.rightButtonDownWidth,(int)exitModeMenuFrame.rightButtonDownHeight,true);
         
            exitModeMenuFrame.rightButtonUpBitmap=Bitmap.createScaledBitmap(
                    BitmapFactory.decodeResource(res,R.drawable.xbutton),
                    (int)exitModeMenuFrame.rightButtonUpWidth,(int)exitModeMenuFrame.rightButtonUpHeight,true);
            ////////////////////////////////////////////////////////////////////////////////////////////////////////
         
        }
        else
        {
            if(meButton.delPosX<0.2f*(float)screenWidth)
            {
                meButton.bmp=null;
                meButton.bmp=Bitmap.createScaledBitmap(
                        meButtonOrig,
                        meButton.width,meButton.height,true);
            }
            else if(meButton.bmp.getWidth()>(int)(0.1f*screenWidth))
            {
                meButton.bmp=null;
                meButton.bmp=Bitmap.createScaledBitmap(
                        meButtonOrig,
                        (int)(0.1f*screenWidth),(int)(0.1f*screenWidth),true);
            }
         
         
            if(highscoreButton.delPosX<0.2f*(float)screenWidth)
            {
                highscoreButton.bmp=null;
                highscoreButton.bmp=Bitmap.createScaledBitmap(
                        highscoreButtonOrig,
                        highscoreButton.width,highscoreButton.height,true);
            }
            else if(highscoreButton.bmp.getWidth()>(int)(0.1f*screenWidth))
            {
                highscoreButton.bmp=null;
                highscoreButton.bmp=Bitmap.createScaledBitmap(
                        highscoreButtonOrig,
                        (int)(0.1f*screenWidth),(int)(0.1f*screenWidth),true);
            }
         
         
            if(settingsButton.delPosX<0.2f*(float)screenWidth)
            {
                settingsButton.bmp=null;
                settingsButton.bmp=Bitmap.createScaledBitmap(
                        settingsButtonOrig,
                        settingsButton.width,settingsButton.height,true);
            }
            else if(settingsButton.bmp.getWidth()>(int)(0.1f*screenWidth))
            {
                settingsButton.bmp=null;
                settingsButton.bmp=Bitmap.createScaledBitmap(
                        settingsButtonOrig,
                        (int)(0.1f*screenWidth),(int)(0.1f*screenWidth),true);
            }
         
         
            if(soundButton.delPosX<0.2f*(float)screenWidth)
            {
                soundButton.bmp=null;
                soundButton.bmp=mView.soundOn?
                                Bitmap.createScaledBitmap(
                                soundButtonOnOrig,
                                soundButton.width,soundButton.height,true):
                                Bitmap.createScaledBitmap(
                                soundButtonOffOrig,
                                soundButton.width,soundButton.height,true);
            }
            else if(soundButton.bmp.getWidth()>(int)(0.1f*screenWidth))
            {
                soundButton.bmp=null;
                soundButton.bmp=mView.soundOn?
                                Bitmap.createScaledBitmap(
                                soundButtonOnOrig,
                                (int)(0.1f*screenWidth),(int)(0.1f*screenWidth),true):
                                Bitmap.createScaledBitmap(
                                soundButtonOffOrig,
                                (int)(0.1f*screenWidth),(int)(0.1f*screenWidth),true);
            }
         
         
            if(exitButton.delPosX<0.2f*(float)screenWidth)
            {
                exitButton.bmp=null;
                exitButton.bmp=Bitmap.createScaledBitmap(
                        exitButtonOrig,
                        exitButton.width,exitButton.height,true);
            }
            else if(exitButton.bmp.getWidth()>(int)(0.1f*screenWidth))
            {
                exitButton.bmp=null;
                exitButton.bmp=Bitmap.createScaledBitmap(
                        exitButtonOrig,
                        (int)(0.1f*screenWidth),(int)(0.1f*screenWidth),true);
            }
        }
        System.gc();
    }
 
 
    /**
     * changes the no ad button when premium
     */
    public void changeNoAdButton()
    {
        settingsModeMenuContent.buttonUpBitmap[4]=Bitmap.createScaledBitmap(
                BitmapFactory.decodeResource(res,R.drawable.noadsbutton),
                settingsModeMenuContent.buttonUpWidth[4],settingsModeMenuContent.buttonUpHeight[4],true);
     
        settingsModeMenuContent.buttonDownBitmap[4]=Bitmap.createScaledBitmap(
                BitmapFactory.decodeResource(res,R.drawable.noadsbutton),
                settingsModeMenuContent.buttonDownWidth[4],settingsModeMenuContent.buttonDownHeight[4],true);
    }
 
    /**
     * changes the sound button
     */
    public void changeSoundButton()
    {
        if(soundButton.delPosX<0.2f*(float)screenWidth)
        {
            soundButton.bmp=null;
            soundButton.bmp=mView.soundOn?
                            Bitmap.createScaledBitmap(
                            soundButtonOnOrig,
                            soundButton.width,soundButton.height,true):
                            Bitmap.createScaledBitmap(
                            soundButtonOffOrig,
                            soundButton.width,soundButton.height,true);
        }
     
        else if(soundButton.bmp.getWidth()>=(int)(0.1f*screenWidth))
        {
            soundButton.bmp=null;
            soundButton.bmp=mView.soundOn?
                            Bitmap.createScaledBitmap(
                            soundButtonOnOrig,
                            (int)(0.1f*screenWidth),(int)(0.1f*screenWidth),true):
                            Bitmap.createScaledBitmap(
                            soundButtonOffOrig,
                            (int)(0.1f*screenWidth),(int)(0.1f*screenWidth),true);
        }
        changeSoundButton=false;
    }

}

Das Alles ist das was die MainActivity meiner App zum Laufen bringt. Ich kann dir gerne einen Link zu dem Store Eintrag per PM schicken falls du es live sehen willst wie der Code arbeitet :)
Es stellt lediglich mein HauptMenü dar der zum eigentlichen Spiel führt.

Lass dich nicht von der Größe des Codes irritieren das ist normal dass da 1000-2000 Zeilen zusammenkommen wenn du viele Objekte und viel Logik drin haben möchtest.

Es läuft ungefähr so ab:

Ich setze den ContentView der Activity einfach in onCreate.
Wenn das Surface sich aufgebaut habe instanziere ich den MainThread.
Dieser initialisiert alle notwendigen Objekte und Variablen eben dieser im Konstruktor.
Bitmaps werden geladen und skaliert.
Und dann wird der Thread gestartet.
Dieser aktualisiert alle 30 ms die SurfaceView an Hand der Logik.

Wie gesagt bei Wunsch kann ich dir auch eine Schablone bereitstellen wo du dein Code einfach nur einfügen musst.
 
Zuletzt bearbeitet:
  • Danke
Reaktionen: Hoffimh
Hallo Jaiel;

vielen dank für deine Antwort.
Da ich Anfänger bin kann ich deinen Worten nur schwer folgen,aber ich werde versuchen deine Tipps umzusetzen.
Gerne würde ich mehr über Vorteilhaften Aufbau von Spielen erfahren.
Ich werde berichten ob ich es hinbekommen hab ;D

Vielen Dank

MfG Hoffimh
 
Zu deiner Frage nochmal...
Du setzt deine View ja als Content.

Der Name Spielactivity ist dabei sehr ungünstig gewählt nebenbei bemerkt.

So wie dein System bisher aussieht verstehe ich nicht wieso du nicht einfach weiter gemacht und eine GameOverView oder ein GameOver layout erstellt hast.

Da ist auf jeden Fall noch vieles an Verbesserungsbedarf z.B. System.exit (1). Besser : finish (). Und setContentview mehrmals ist eben auch nicht gut.

Wie gesagt fährst du mit Activity, SurfaceView und Thread eben besser.

Im Thread die gesamte Logik.
In der View die Touchabfragen und das Zeichnen.

Ich würde dir raten auch deine Objekte die gezeichnet werden sollen von einer Basis Klasse erben zu lassen und in einer ArrayList anzulegen.
Die Basisklasse sollte abstrakt sein und auch 2 abstrakte Methoden update (long) und draw (Canvas) besitzen so kannst du diese dann ganz leicht dazu veranlassen etwas zu tun und hast dann weniger Code in dem Thread drin.
Was bei meinem Code da nicht der Fall ist;).
 
  • Danke
Reaktionen: Hoffimh
Hallo Jaiel,

entschuldige das ich mich so doof anstelle, aber ich kann dir leider nicht Folgen...
Könntest du es bitte auf "Anfänger-Niveu" erklären ?
Das wäre nett.Vielen Dank für deine bisherige Hilfe.

MfG Hoffimh
 
Hast du es denn jetzt gelöst mit dem game over screen?

Für die SurafceView Lösung die ich dir ans Herz lege falls du wirklich Spieleentwicklung betreiben willst ist das schonmal ein guter Einstieg:

To OpenGL or to SurfaceView | Infinut

Und dann ein Tutorial hier:
Using Surface View for Android

oder hier:
Android Game App Tutorial 04 - Erste App - GameActivity, SurfaceView - Panjutorials

libGDX würde ich auch empfehlen aber komm erstmal mit SurfaceView zurecht. Direkt auf openGL würde ich persönlich nciht programmieren sondern frameworks wie libGDX dazu nehmen.

Ich habe am Anfang zu viele Referenzen der Activity verteilt zum Beispiel so war alles irgendwie ineinander verwoben. Dadurch wird der Code schwer wartbar und so aber man lernt mit der Zeit es besser zu machen.


Wenn du etwas nciht verstanden hast von dem vorherigen dann frag doch einfach, dann kann ich dir das genau erklären. Ich brauche schon eine Angabe was du genau nicht verstanden hast :)
 
Zuletzt bearbeitet:
  • Danke
Reaktionen: Hoffimh
Hallo Jaiel,

nein, leider konnte ich mein Problem nicht beheben.

LG Hoffimh
 

Ähnliche Themen

E
Antworten
0
Aufrufe
955
ey6799
E
M
  • merlin1234x
Antworten
1
Aufrufe
1.032
wilco
W
Temucin
Antworten
1
Aufrufe
537
jogimuc
J
Zurück
Oben Unten