Math.random()
指定范围内乱数。
import java.util.*;
class random {
public static void main(String[] args) {
double temp = Math.random();
System.out.println(temp);
System.out.println(temp * (500 - 600));
System.out.println((int)(temp * (500 - 600) + 600));
System.out.println(Math.random() * (5 - 10) + 10);
}
}
2019年3月28日木曜日
2019年3月27日水曜日
Android游戏编程之从零开始、p190
Android游戏编程之从零开始、p190
4.14.1 矩形碰撞
public boolean isCollsion(Rect rectA, Rect rectB) {
// left
// A B
if (rectA.left < rectB.left && rectA.right < rectB.left) {
return false;
}
// top
// A
// B
if (rectA.bottom < rectB.top && rectA.bottom < rectB.bottom) {
return false;
}
// right
// B A
if (rectA.left > rectB.left && rectA.left > rectB.right) {
return false;
}
// bottom
// B
// A
if (rectA.top > rectB.bottom && rectA.bottom > rectB.bottom) {
return false;
}
return true;
}
4.14.1 矩形碰撞
public boolean isCollsion(Rect rectA, Rect rectB) {
// left
// A B
if (rectA.left < rectB.left && rectA.right < rectB.left) {
return false;
}
// top
// A
// B
if (rectA.bottom < rectB.top && rectA.bottom < rectB.bottom) {
return false;
}
// right
// B A
if (rectA.left > rectB.left && rectA.left > rectB.right) {
return false;
}
// bottom
// B
// A
if (rectA.top > rectB.bottom && rectA.bottom > rectB.bottom) {
return false;
}
return true;
}
ラベル:
Android游戏编程之从零开始
2019年3月24日日曜日
Android游戏编程之从零开始、p173
Android游戏编程之从零开始、p173
自定义动画
动态位图
private void T1set() {
btax = bitmapB.getWidth() - this.getWidth();
btay = -bitmapB.getHeight() + this.getHeight();
}
private void T1(Canvas canvas) {
btax -= 10;
canvas.drawColor(Color.RED);
canvas.drawBitmap(bitmapB, -btax, btay, paint);
}
private void mDraw() {
try {
canvas = surfaceHolder.lockCanvas();
if (canvas != null) {
T1(canvas);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
@Override
public void run() {
while (thflag) {
long s = System.currentTimeMillis();
mDraw();
long e = System.currentTimeMillis();
if (e - s < 50) {
try {
Thread.sleep(50 - (e - s));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
自定义动画
动态位图
private void T1set() {
btax = bitmapB.getWidth() - this.getWidth();
btay = -bitmapB.getHeight() + this.getHeight();
}
private void T1(Canvas canvas) {
btax -= 10;
canvas.drawColor(Color.RED);
canvas.drawBitmap(bitmapB, -btax, btay, paint);
}
private void mDraw() {
try {
canvas = surfaceHolder.lockCanvas();
if (canvas != null) {
T1(canvas);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
@Override
public void run() {
while (thflag) {
long s = System.currentTimeMillis();
mDraw();
long e = System.currentTimeMillis();
if (e - s < 50) {
try {
Thread.sleep(50 - (e - s));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
ラベル:
Android游戏编程之从零开始
Android游戏编程之从零开始 P166
Android游戏编程之从零开始
②第二种是利用Regin来对画布设置可视区域。
canvas.clipRegion(region) 过时。
canvas.clipPath(region.getBoundaryPath()) 利用
private void T3(Canvas canvas) {
canvas.save();
canvas.drawColor(Color.WHITE);
Region region = new Region();
region.op(new Rect(200, 200, 1000, 1000), Region.Op.UNION);
region.op(new Rect(400, 300, 900, 900), Region.Op.REVERSE_DIFFERENCE);
region.op(new Rect(500, 200, 800, 800), Region.Op.XOR);
canvas.clipPath(region.getBoundaryPath());
canvas.drawBitmap(bitmapC, 0, 0, paint);
canvas.restore();
}
②第二种是利用Regin来对画布设置可视区域。
canvas.clipRegion(region) 过时。
canvas.clipPath(region.getBoundaryPath()) 利用
private void T3(Canvas canvas) {
canvas.save();
canvas.drawColor(Color.WHITE);
Region region = new Region();
region.op(new Rect(200, 200, 1000, 1000), Region.Op.UNION);
region.op(new Rect(400, 300, 900, 900), Region.Op.REVERSE_DIFFERENCE);
region.op(new Rect(500, 200, 800, 800), Region.Op.XOR);
canvas.clipPath(region.getBoundaryPath());
canvas.drawBitmap(bitmapC, 0, 0, paint);
canvas.restore();
}
adb devices 查询设备
查询设备
$ adb devices
将文件复制到设备/从设备复制文件
$ adb pull remote local
$ adb push local remote
进行屏幕截图
$ adb shell screencap /sdcard/screen.png
录制视频
$ adb shell screenrecord /sdcard/demo.mp4
$ adb devices
将文件复制到设备/从设备复制文件
$ adb pull remote local
$ adb push local remote
进行屏幕截图
$ adb shell screencap /sdcard/screen.png
录制视频
$ adb shell screenrecord /sdcard/demo.mp4
2019年3月21日木曜日
ldpi,mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi
ldpi,mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi
float xdpi = getResources().getDisplayMetrics().xdpi;
float ydpi = getResources().getDisplayMetrics().ydpi;
https://blog.csdn.net/guolin_blog/article/details/50727753
https://developer.android.com/reference/android/util/DisplayMetrics.html
float xdpi = getResources().getDisplayMetrics().xdpi;
float ydpi = getResources().getDisplayMetrics().ydpi;
https://blog.csdn.net/guolin_blog/article/details/50727753
https://developer.android.com/reference/android/util/DisplayMetrics.html
ラベル:
Android_Layout
2018年11月12日月曜日
AboutDialog の追加
AboutDialog の追加
public class AboutDialog extends AlertDialog {
private Context context;
public AboutDialog(Context context) {
super(context);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout li = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.about_layout, null);
TextView textView = li.findViewById(R.id.textView3);
textView.setText(Html.fromHtml("<u>" + getString(R.string.GooglePlayStore) + "<u>"));
Pattern pattern = Pattern.compile("");
String url = getString(R.string.PlayURL);
Linkify.addLinks(textView, pattern, url, null, null);
setContentView(li);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="30dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@mipmap/ic_launcher_foreground" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/app_name"
android:textSize="30dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/kankanla"
android:textSize="20dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/GooglePlayStore"
android:textSize="20dp" />
</LinearLayout>
public class AboutDialog extends AlertDialog {
private Context context;
public AboutDialog(Context context) {
super(context);
this.context = context;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout li = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.about_layout, null);
TextView textView = li.findViewById(R.id.textView3);
textView.setText(Html.fromHtml("<u>" + getString(R.string.GooglePlayStore) + "<u>"));
Pattern pattern = Pattern.compile("");
String url = getString(R.string.PlayURL);
Linkify.addLinks(textView, pattern, url, null, null);
setContentView(li);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="30dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
app:srcCompat="@mipmap/ic_launcher_foreground" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/app_name"
android:textSize="30dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/kankanla"
android:textSize="20dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1"
android:text="@string/GooglePlayStore"
android:textSize="20dp" />
</LinearLayout>
ラベル:
Android_Layout
登録:
投稿 (Atom)