###前提・実現したいこと
Androidstudio(Java)を使って、銃の早撃ちアプリを作成しています。
ゲーム画面の画像をかえてから、重くなりました。
ゲーム画面だけ動作がすべて重くなります。
###発生している問題・エラーメッセージ
I/OMXClient: Using client-side OMX mux.
E/OMXMaster: A component of name 'OMX.qcom.audio.decoder.aac' already exists, ignoring this one.
W/art: Suspending all threads took: 10.955ms
I/Choreographer: Skipped 33 frames! The application may be doing too much work on its main thread.
W/AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 4, track 44100 Hz, output 48000 Hz
I/Choreographer: Skipped 38 frames! The application may be doing too much work on its main thread.
###該当のソースコード
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Build;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.Random;
public class game_page extends AppCompatActivity {
int wait_time, attack_time;//撃つまでの待ち時間|撃たれる時間 Boolean wait_flag = false , attack_flag = true, start_flag = false, victory_flag = false;//待ち時間かの判断|撃たれたかの判断 int level; //難易度設定 Long startTime; SoundPool soundPool; //効果音用 int gun_sound; //////////////////////////////////////////// TextView score; ImageView action_view, mokumoku_view; Button shotButton; RelativeLayout layout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.game_page); mokumoku_view = (ImageView) findViewById(R.id.imageView); shotButton = (Button) findViewById(R.id.shoot_button); score = (TextView) findViewById(R.id.score_view); layout = (RelativeLayout)findViewById(R.id.layout); soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); gun_sound = soundPool.load(this, R.raw.gun_sound, 1); Random rnd = new Random(); wait_time = rnd.nextInt(12)+3; /*データ取得(難易度確認)--------------------------------------------------------------*/ SharedPreferences data = getSharedPreferences("game_data", Context.MODE_PRIVATE); level = data.getInt("level",3); /*------------------------------------------------------------------------------------*/ switch (level){ case 1://簡単 attack_time = rnd.nextInt(5)+8;//0.8-1.3秒 break; case 2://普通 attack_time = rnd.nextInt(3)+5;//0.5-0.8秒 break; case 3://難しい attack_time = rnd.nextInt(2)+3;//0.3-0.5秒 break; } Log.d("Game","WatiTime : "+wait_time); Log.d("Game","AttackTime : "+attack_time*100); if (Build.VERSION.SDK_INT >= 19){ Window window = getWindow(); View view = window.getDecorView(); view.setSystemUiVisibility( View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN ); } } public void Start(View v){ if (start_flag == false){ //スタートボタンを押したら Log.d("Game","Start"); shotButton.setText("SHOOT"); start_flag = true; layout.setBackgroundResource(R.drawable.afterstart); new Handler().postDelayed(new Runnable() { @Override public void run() { //撃つタイミングになたっら Log.d("Game","NOW!"); wait_flag = true; layout.setBackgroundResource(R.drawable.bunnow); startTime = System.currentTimeMillis(); //TODO:音の再生 } }, 1000 * wait_time);//1000 * (撃つタイミング秒数) new Handler().postDelayed(new Runnable() { @Override public void run() { Log.d("Game","BUN!!!"); attack_flag = false; //TODO:負けの処理 } }, 1000 * wait_time + 100 * attack_time);//100 * (撃たれる秒数) }else{ //撃つボタンを押したら Log.d("Game","attack_flag"+attack_flag+"/ wait_flag"+wait_flag); mokumoku_view.setBackgroundResource(R.drawable.mokumoku); Animation animation= AnimationUtils.loadAnimation(this,R.anim.alpha_fadeout); mokumoku_view.startAnimation(animation); shotButton.setEnabled(false); if (wait_flag == true) { Long stopTime = System.currentTimeMillis(); Long time = stopTime - startTime; score.setText("Time : " + time + "ms"); }else{ score.setText("Time : --- ms"); } soundPool.play(gun_sound, 0.2f, 0.2f, 0, 0, 1); SharedPreferences preferences = getSharedPreferences("game_data", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); int win = preferences.getInt("win",0); int lose = preferences.getInt("lose",0); if (attack_flag == true && wait_flag == true){ //撃たれていなければ(勝ち) victory_flag = true; layout.setBackgroundResource(R.drawable.math_win); win += 1; editor.putInt("win", win); Log.d("Game","WIN"); }else{ //負け layout.setBackgroundResource(R.drawable.math_lose); lose += 1; editor.putInt("lose", lose); Log.d("Game","LOSE"); } editor.apply(); } } public void Return(View v){ Intent intent = new Intent(this,Menu_Activity.class); startActivity(intent); finish(); }
}
###試したこと
画像の変え方などをかえました。
###補足情報(言語/FW/ツール等のバージョンなど)
Androidstudio 2.1.1
あなたの回答
tips
プレビュー