我呼吁这些类出现在 onCreate() 方法中,并且它们在类的底部都有布尔值,一旦它们完成,它们将设置为 true。只有这样我的 SurfaceView 才会绘制它需要的东西。为什么这三门课要花这么长时间才能完成?
敌人、云和子弹都是我在调用他们的类之前加载的位图
public class handleBullets extends AsyncTask<String, Integer, String>
{
@Override
protected String doInBackground(String... arg0) {
Random r = new Random();
Log.d(null, "Spawn E-Bulles");
for(int i = 0; i < enemies.size(); i++)
{
Enemy tempE = enemies.get(i);
if(System.currentTimeMillis() - tempE.lastBulletSpawn >= 800 && tempE.x <= SCREEN_WIDTH)
{
EnemyBullet eb = new EnemyBullet(tempE.x, tempE.y, enemyBullet.getWidth(), enemyBullet.getHeight(), enemy.getWidth(), enemy.getHeight());
enemyBullets.add(eb);
tempE.lastBulletSpawn = System.currentTimeMillis();
}
}
Log.d(null, "Spawn Bullets");
if(System.currentTimeMillis() - lastPBSpawn >= 400)
{
Bullet b = new Bullet(x, y, player.getWidth(), player.getHeight());
bullets.add(b);
lastPBSpawn = System.currentTimeMillis();
}
Log.d(null, "Remove Bullets");
for(int i = bullets.size() - 1; i > -1; i--)
{
Bullet tempB = bullets.get(i);
if(tempB.x >= SCREEN_WIDTH)
bullets.remove(i);
}
Log.d(null, "removeEnemy Bullets");
for(int i = enemyBullets.size() - 1; i > -1; i--)
{
EnemyBullet tempEB = enemyBullets.get(i);
if(tempEB.x <= 0 - enemyBullet.getWidth())
enemyBullets.remove(i);
}
Log.d(null, "Explosion Renders");
for(int i = explosions.size() - 1; i > -1; i--)
{
Explosion tempEx = explosions.get(i);
tempEx.update();
if(tempEx.duration <= 0)
explosions.remove(i);
}
initial_bullets = true;
return null;
}
}
public class handleEnemy extends AsyncTask<String, Integer, String>
{
@Override
protected String doInBackground(String... arg0) {
Log.d(null, "Spawning Enemies...");
if(System.currentTimeMillis() - lastESpawn >= 750 && enemy != null)
{
Enemy x = new Enemy(SCREEN_WIDTH, SCREEN_HEIGHT, enemy.getWidth(), enemy.getHeight());
enemies.add(x);
lastESpawn = System.currentTimeMillis();
}
Log.d(null, "Enemies Spawned");
//
Log.d(null, "Removing Enemies...");
for(int i = enemies.size() - 1; i > -1; i--)
{
Enemy tempE = enemies.get(i);
if(tempE.x <= 0 - enemy.getWidth())
enemies.remove(tempE);
}
Log.d(null, "Enemies Removed");
//
initial_enemies = true;
return null;
}
}
public class handleClouds extends AsyncTask<String, Integer, String>
{
@Override
protected String doInBackground(String... arg0) {
Log.d(null, "Generating Clouds...");
Random r = new Random();
if(r.nextInt(200) == 0 && clouds.size() <= 6 && cloudBM1 != null && cloudBM2 != null)
{
Cloud c = new Cloud(SCREEN_WIDTH, SCREEN_HEIGHT, cloudBM1.getWidth(), cloudBM2.getHeight());
clouds.add(c);
}
Log.d(null, "Clouds Generated");
//
Log.d(null, "Removing Clouds...");
for(int i = clouds.size() - 1; i > -1; i--)
{
Cloud tempC = clouds.get(i);
if(tempC.x <= 0 - cloudBM1.getWidth() && tempC.dir == 0)
clouds.remove(i);
if(tempC.x >= SCREEN_WIDTH && tempC.dir == 1)
clouds.remove(i);
}
Log.d(null, "Clouds Removed");
//
initial_clouds = true;
return null;
}
}