Loading...
Logo
Processing Forum
darkgisba's Profile
7 Posts
16 Responses
0 Followers

Activity Trend

Last 30 days
Show:
Private Message
    What tips can you give me on code optimization for android.

    I have been checking the memory usage of many games that are built with eclipse and they usually use from 15 to 30 mb of ram.

    My game witch doesn't seems as complex as most uses 45mb and can ramp up to 80 and you can make it crash by repetitively jumping from level to level.

    Im gonna give you some examples of code, that I think are giving me some performance issues.

    1. void loadCoordinates() {
    2.   println("loaded"+""+millis());
    3.   try {
    4.     String[]strokesdone = loadStrings("\\turtle\\ownStrokes.txt");
    5.     for (n=0; n<nlvl;n++) {
    6.       ownstrokes[n] = int(strokesdone[n]);
    7.       if (ownstrokes[n]==0) {
    8.         ownstrokes[n]=int(10);
    9.       }
    10.     }
    11.   }
    12.   catch (NullPointerException e) {
    13.     String[] strokesdone = new String[nlvl];
    14.     for (n=0; n<nlvl;n++) {
    15.       strokesdone[n] = 10+"";
    16.     }
    17.     saveStrings("\\turtle\\ownStrokes.txt", strokesdone);
    18.   }
    19.   nMax=cX.length;
    20.   for (n=0; n<nMax;n++) { 
    21.     hitX[n] = width/float(cX[n]);    
    22.     if (float(cX[n])==0) {
    23.       hitX[n]=0;
    24.     }  
    25.     hitY[n] = height/float(cY[n]);  
    26.     if (float(cY[n])==0) {
    27.       hitY[n]=0;
    28.     }
    29.   }
    30. }


    that function is played at the start of most levels to reset coordinates for hitbox's and my memory usage ramps up at every new level.

    1. void level26() {
    2.   if (load==0) {
    3.     nulify();
    4.     loadCoordinates();
    5.     die=0;
    6.     drag=0.98;
    7.     tinting=255;
    8.     H=height/24;
    9.     W=width/16;
    10.     posX=width/1.4;
    11.     posY=height/1.4;
    12.     dX=0;
    13.     dY=0;
    14.     glue=0;
    15.     bounce=0;
    16.     movement=2;
    17.   }
    18.   load=1;
    19.   image(level[lvl], 0, 0, width, height);
    20.   whirlCount=(whirlCount+0.2)%4;
    21.   image(whirl[int(whirlCount)], hitX[710], hitY[710], width/10, height/15);

    22.   //game maker stuff
    23.   if (nMax>0) {
    24.     hitX[nMax]=abs(hitX[nMax-1]-mouseX);
    25.     hitY[nMax]=abs(hitY[nMax-1]-mouseY);
    26.   }
    27.   character();
    28.   image(levelForeground[lvl], 0, 0, width, height);
    29.   ui();
    30.   //stuff to delete later
    31.   if (edit==1) {
    32.     for (n=682;n<711;n+=2) {
    33.       stroke(100);
    34.       fill(255, 80);
    35.       rect(hitX[n], hitY[n], hitX[n+1], hitY[n+1]);
    36.       fill(0);
    37.       text("square "+(n/2+1), hitX[n]+hitX[n+1]/2, hitY[n]+hitY[n+1]/2);
    38.       text("n "+n, hitX[n]+hitX[n+1]/2, hitY[n]+hitY[n+1]/2+10);
    39.     }
    40.   }
    41.   //stuff to delete later**
    42.   if (posX<W) {
    43.     posX=W;
    44.     dX*=-stone;
    45.   }
    46.   if (posY<H) {
    47.     posY=H;
    48.     dY*=-stone;
    49.   }
    50.   for (n=682; n<712;n+=2) {
    51.     if (colision2(posX, posY, H, W, hitX[n], hitY[n], hitX[n+1], hitY[n+1])==true) {
    52.       fill(255);
    53.       ////////////////////bumpers//////////////////////
    54.       if (n==696||n==698||n==700||n==702||n==704||n==706||n==708) {
    55.         if (bump==0) {
    56.           dX=(width/32)*random(-1, 1);
    57.           dY=(height/48)*random(-1, 1);
    58.           bump=n;
    59.           break;
    60.         }
    61.       }
    62.       //speeed!!!!!!!!!!!!
    63.       if (n==690||n==692||n==694) {
    64.         dY++;
    65.         break;
    66.       }
    67.       ////////////// PIT
    68.       if (n==684) {
    69.         dX=(hitX[n]+(hitX[n+1]/2)-posX)/50;
    70.         dY=(hitY[n]+(hitY[n+1]/2)-posY)/50;
    71.         die();
    72.         glue=0;
    73.         break;
    74.       } 
    75.       //      //glue tiles
    76.       if (n==634||n==632) {
    77.         glue=n;
    78.         stone=1;
    79.       }
    80.       if (dY>0&&posY<hitY[n]) {
    81.         posY-=dY;
    82.         dY*=-stone;
    83.       }
    84.       if (dY<0&&posY>hitY[n]+hitY[n+1]) {
    85.         posY-=dY;
    86.         dY*=-stone;
    87.       }
    88.       if (dX>0&&posX<hitX[n]) {
    89.         posX-=dX;
    90.         dX*=-stone;
    91.       }
    92.       if (dX<0&&posX>hitX[n]+hitX[n+1] ) {
    93.         posX-=dX;
    94.         dX*=-stone;
    95.       }

    96.       //      // bouncy tile
    97.       //      if(n==38){
    98.       //       dX*=bounce;
    99.       //       dY*=bounce;
    100.       //      }
    101.       // win tile
    102.       if (n==710) {
    103.         //////////////
    104.         if (nstroke<ownstrokes[lvl]&&ownstrokes[lvl]!=0) {
    105.           ownstrokes[lvl]=nstroke;
    106.           String[] strokesdone = new String[nlvl];
    107.           for (n=0; n<nlvl;n++) {
    108.             strokesdone[n] = ownstrokes[n]+"";
    109.           }
    110.           saveStrings("\\turtle\\ownStrokes.txt", strokesdone);
    111.         }
    112.         nstroke=0;
    113.         /////////////
    114.         lvlcomplete[lvl]=1;
    115.         lvl++;
    116.         if (lvlcomplete[lvl]!=1) {
    117.           lvlcomplete[lvl]=2;
    118.         }

    119.         for (n=0; n<nlvl;n++) {
    120.           leveldone[n] = lvlcomplete[n]+"";
    121.         }
    122.         saveStrings("\\turtle\\setup.txt", leveldone);
    123.         load=0;
    124.       }
    125.     }
    126.     stone=0.8;
    127.   }
    128.   //bumper sistem
    129.   for (n=682; n<710;n+=2) {
    130.     if (colision2(posX, posY, H, W, hitX[n], hitY[n], hitX[n+1], hitY[n+1])==false&&bump==n) {
    131.       bump=0;
    132.     }
    133.   }
    134.   //glue system
    135.   for (n=614; n<640;n+=2) {
    136.     if (colision2(posX, posY, H, W, hitX[n], hitY[n], hitX[n+1], hitY[n+1])==false&&glue==n) {
    137.       dX=0;
    138.       dY=0;
    139.     }
    140.   }
    141. }
    Thats a example of how I do my levels and colision detection.

    1. void imagetool() {
    2.   if (lvl==-2) {
    3.     if (menuloaded==false) {
    4.       menuloaded=true;
    5.       for (n=0;n<9;n++) {
    6.         menu[n]=loadImage("menu"+(n)+".png");
    7.       }
    8.     }
    9.   }
    10.   else {
    11.     for (n=0;n<9;n++) {
    12.       menuloaded=false;
    13.       menu[n].delete();
    14.     }
    15.   }
    16.   if (lastlvl!=lvl&&lvl!=-2&&lvl!=-1) {
    17.     level[lvl]=loadImage("lvl"+(lvl+1)+".png");
    18.   }
    19.   if (lastlvl!=lvl&&lvl!=-2&&lvl!=-1&&lvl!=48) {
    20.     levelForeground[lvl]=loadImage("lvl"+(lvl+1)+"Foreground.png");
    21.   }
    22.   if (lvl!=lastlvl) {
    23.     for (n=0;n<level.length;n++) {
    24.       if (n!=lvl&&level[n]!=null) {
    25.         level[n].delete();
    26.       }
    27.     }
    28.     for (n=0;n<levelForeground.length;n++) {
    29.       if (n!=lvl&&levelForeground[n]!=null) {
    30.         levelForeground[n].delete();
    31.       }
    32.     }
    33.   }
    34. }
    Thats how I handle images and image deletion to free up ram.

    Please have a look at this samples and hopefully someone with a more experienced eye  than I will find some obvious flaw with a piece of the code.

    Thank you in advance.

    PS , all my images are PNG, do you think thats the best file type ?
    I need to know how to hide an ad on user interaction using processing friendly code.

    1. @Override
    2. public void onCreate(Bundle savedInstanceState) {

    3.   super.onCreate(savedInstanceState);
    4.   Window window = getWindow();
    5.   RelativeLayout adsLayout = new RelativeLayout(this);
    6.   RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.FILL_PARENT);
    7.   // Displays Ads at the bottom of your sketch, use Gravity.TOP to display them at the top

    8.   adsLayout.setGravity(Gravity.TOP);
    9.   AdView adView = new AdView(this, AdSize.BANNER, "a14e545fe4eb06c");  // add your app-id


    10.   adsLayout.addView(adView);
    11.   AdRequest newAdReq = new AdRequest();
    12.   // Remark: uncomment next line for testing your Ads (fake ads)
    13.   //newAdReq.setTesting(true);
    14.   adView.loadAd(newAdReq);

    15.   window.addContentView(adsLayout, lp2);
    16. }
    Thats what I have after my void draw to show the ad but i have no clue on how to hide it on user action , can anyone help me??

    1.  adView.setVisibility(View.GONE);
    That code is supposed to hide it but I don't know how to use it in my code without having compiler errors.

    Hello everyone , I have a working game in the market, and I only tested it on my phone wich is a samsung galaxy android 2.2

    the thing is, some of the users are saying that their phones do not save the levels, and that means that my save system is not working on their phones.

    Problem is, I do not know what phone they have or what version of android they are using , i know for a fact that the xpria x10 mini does not save the file, but I have no idea why.

    the code I use to save the files I need is the following 

    1.   String[] cX = new String[nMax];
    2.     for (n=0; n<nMax;n++) {
    3.       if (hitX[n]!=0) {
    4.         hitX[n]=width/hitX[n];
    5.       }
    6.       cX[n] = hitX[n]+"";
    7.     }
    8.     saveStrings("x.txt", cX);
    9.     String[] cY = new String[nMax];
    10.     for (n=0; n<nMax;n++) {
    11.       if (hitY[n]!=0) {
    12.         hitY[n]=height/hitY[n];
    13.       }
    14.       cY[n] = hitY[n]+"";
    15.     }
    16.     saveStrings("y.txt", cY);
    17.   }
    But loading from the files i initially give them its all fine:

    1.  try {
    2.     String[] strokesdone = loadStrings("\\turtle\\ownStrokes.txt");
    3.     for (n=0; n<35;n++) {
    4.       ownstrokes[n] = int(strokesdone[n]);
    5.     }
    6.   }
    7.   catch (NullPointerException e) {
    8.     String[] strokesdone = new String[nlvl];
    9.     for (n=0; n<nlvl;n++) {
    10.       strokesdone[n] = 10+"";
    11.     }
    12.     saveStrings("\\turtle\\ownStrokes.txt", strokesdone);
    13.   }
    Basicly loadStrings and saveStrings work fine on my phone samsung galaxy S,v 2.2.0, but i do not know why it doesnt work on some phones, and i actually do not know if it has to do with android version or not.

    Anyone ever had a similar problem?

    thats the link to the free demo of my game , please download,play it and tell me if your phone saves, if it does not, please tell me the make of your phone and the android version, I really need to get this sorted!
    Hello everyone , i need some feedback and testing of 2 games im developing at the moment.


    You can play them at that location and you can either leave feedback there , or here.

    Im the coder of those games  while the art is done by a colegue of myne , everything was done in processing and both games are ready to be put and played on the android phone.

    Please help me and test the games for bugs, playability issues or suggestions.

    Any feedback is welcome.

    Thank you!
    Hello everyone , long time reader, first time poster.

    Im developing a game for the android.

    Theres a highscore and for now thats the only string i want to be able to save for obvius reasons.

    I can do the loadString function and it grabs whatever i had when i turned my skecth into an app, but the saveString function does not work on the phone , and it does work on the desktop.

    Althou on the desktop when it saves it , it saves on the skecth folder and not on the data folder, but if I add a path to the saveString function , the phone gives me an error.

    Anyone knows a clean and short way of doing what I need there?

    Or a long and dirty if it has to be... :)

    Cheers and happy coding everyone!