
- Forum posts: 10
Sep 26, 2018, 8:06:22 PM via Website
Sep 26, 2018 8:06:22 PM via Website
Good morning,
new question that have been struck by a couple of days,
always for the splash screen talk with mini game to entertain the user.
Since positioning in a static way for an undefined number of combinations would be a long work and I think also useless since I hope that the splash screen is loaded for the shortest possible time, I opted for a pseudo-random positioning of the imageView but often they are positioned outside of the screen but unfortunately I can not identify the best code to avoid it, does anyone have a conscience?
This is the code used by me that creates the problem.
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay()
.getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
/*Random Number01*/
Random rand01 = new Random();
int numb01 = rand01.nextInt(10)+1; // Gives n such that 0 <= n < 10
Random randomX01 = new Random();
int X01 = randomX01.nextInt(width)+1;
Random randomY01 = new Random();
int Y01 = randomY01.nextInt(height)+1;
if (X01 > metrics.widthPixels /2 ) {
X01 = X01 - ((ImageView)findViewById(R.id.coin01)).getMeasuredWidth ();
}
if (Y01 > metrics.heightPixels /2 ) {
Y01 = Y01 - ((ImageView)findViewById(R.id.coin01)).getMeasuredHeight ();
}
((ImageView)findViewById(R.id.coin01)).setX ( X01 );
((ImageView)findViewById(R.id.coin01)).setY ( Y01 );
if (numb01 == 1) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon001souls);
accumulator01 = 1;
} else if (numb01 == 2) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon002souls);
accumulator01 = 2;
} else if (numb01 == 3) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon005souls);
accumulator01 = 5;
} else if (numb01 == 4) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon010souls);
accumulator01 = 10;
} else if (numb01 == 5) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon020souls);
accumulator01 = 20;
} else if (numb01 == 6) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon050souls);
accumulator01 = 50;
} else if (numb01 == 7) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon100souls);
accumulator01 = 100;
} else if (numb01 == 8) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon200souls);
accumulator01 = 200;
} else if (numb01 == 9) {
((ImageView)findViewById(R.id.coin01)).setImageResource(R.drawable.mon500souls);
accumulator01 = 500;
}
Waiting for your kind help,
Thank you