diff --git a/app/src/main/java/com/erz/joystick/MainActivity.java b/app/src/main/java/com/erz/joystick/MainActivity.java index 609cb1e..ac57d30 100644 --- a/app/src/main/java/com/erz/joystick/MainActivity.java +++ b/app/src/main/java/com/erz/joystick/MainActivity.java @@ -15,13 +15,16 @@ public class MainActivity extends AppCompatActivity implements JoyStick.JoyStick super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gameView = (GameView) findViewById(R.id.game); - ((JoyStick)findViewById(R.id.joy1)).setListener(this); - ((JoyStick)findViewById(R.id.joy1)).setPadColor(Color.parseColor("#55ffffff")); - ((JoyStick)findViewById(R.id.joy1)).setButtonColor(Color.parseColor("#55ff0000")); - ((JoyStick)findViewById(R.id.joy2)).setListener(this); - ((JoyStick)findViewById(R.id.joy2)).enableStayPut(true); - ((JoyStick)findViewById(R.id.joy2)).setButtonSize(50); - ((JoyStick)findViewById(R.id.joy2)).setButtonDrawable(R.drawable.droid); + JoyStick joy1 = (JoyStick) findViewById(R.id.joy1); + joy1.setListener(this); + joy1.setPadColor(Color.parseColor("#55ffffff")); + joy1.setButtonColor(Color.parseColor("#55ff0000")); + + JoyStick joy2 = (JoyStick) findViewById(R.id.joy2); + joy2.setListener(this); + joy2.enableStayPut(true); + joy2.setPadBackground(R.drawable.pad); + joy2.setButtonDrawable(R.drawable.button); } @Override diff --git a/app/src/main/res/drawable-hdpi/button.png b/app/src/main/res/drawable-hdpi/button.png new file mode 100755 index 0000000..5655d10 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/button.png differ diff --git a/app/src/main/res/drawable-hdpi/pad.png b/app/src/main/res/drawable-hdpi/pad.png new file mode 100755 index 0000000..dcdfa07 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/pad.png differ diff --git a/app/src/main/res/drawable-mdpi/button.png b/app/src/main/res/drawable-mdpi/button.png new file mode 100755 index 0000000..f11f4a8 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/button.png differ diff --git a/app/src/main/res/drawable-mdpi/pad.png b/app/src/main/res/drawable-mdpi/pad.png new file mode 100755 index 0000000..540b6c8 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/pad.png differ diff --git a/app/src/main/res/drawable-xhdpi/button.png b/app/src/main/res/drawable-xhdpi/button.png new file mode 100755 index 0000000..b543ee2 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/button.png differ diff --git a/app/src/main/res/drawable-xhdpi/pad.png b/app/src/main/res/drawable-xhdpi/pad.png new file mode 100755 index 0000000..bba5a0d Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/pad.png differ diff --git a/app/src/main/res/drawable-xxhdpi/button.png b/app/src/main/res/drawable-xxhdpi/button.png new file mode 100755 index 0000000..cc97fed Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/button.png differ diff --git a/app/src/main/res/drawable-xxhdpi/pad.png b/app/src/main/res/drawable-xxhdpi/pad.png new file mode 100755 index 0000000..bddfe7c Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/pad.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/button.png b/app/src/main/res/drawable-xxxhdpi/button.png new file mode 100755 index 0000000..9f412f5 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/button.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/pad.png b/app/src/main/res/drawable-xxxhdpi/pad.png new file mode 100755 index 0000000..b223de6 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/pad.png differ diff --git a/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java b/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java index 710fe98..e451625 100644 --- a/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java +++ b/joysticklibrary/src/main/java/com/erz/joysticklibrary/JoyStick.java @@ -137,7 +137,7 @@ public class JoyStick extends View { paint.setColor(padColor); canvas.drawCircle(centerX, centerY, radius, paint); } else { - temp.set(posX - radius, posY - radius, posX + radius, posY + radius); + temp.set(centerX - radius, centerY - radius, centerX + radius, centerY + radius); canvas.drawBitmap(padBGBitmap, null, temp, paint); } if (buttonBitmap == null) { @@ -219,8 +219,8 @@ public class JoyStick extends View { //size of button is a percentage of the minimum(width, height) //percentage must be between 25 - 50 - public void setButtonSize(int p) { - percentage = p; + public void setButtonRadiusScale(int scale) { + percentage = scale; if (percentage > 50) percentage = 50; if (percentage < 25) percentage = 25; }