背景の上にレベルを描画しようとしていますが、その方法がわかりません。それぞれのピースを別々に描くことはできますが、画面上で両方を描く方法が完全にわかりません。背景を別の方法で描画する必要があると思いますが、そのような方法は知りません。
これまでの私のコードは次のとおりです。
public class DisplayMap extends Activity {
ImageView mapView;
String FILENAME = "World.tmx";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
setContentView(new TileBackground(this));
}
public void loadWorld(String path) {
ImageView mapView;
// Start the parser, get back TMX data object
TileMapData t = TMXLoader.readTMX(FILENAME, this);
mapView = (ImageView) findViewById(R.id.MapImage);
// Create a Bitmap from the tilemap data
Bitmap mapImage = TMXLoader.createBitmap(t, this, 0, t.layers.size());
// Set the imageview to show the map, if we have one
if (mapImage != null) {
mapView.setImageBitmap(mapImage);
}
// Map loading problem, inform the user.
else {
Toast errorMessage = Toast.makeText(getApplicationContext(),
"Map could not be loaded", Toast.LENGTH_LONG);
errorMessage.show();
}
}
class TileBackground extends View {
Bitmap bg;
public TileBackground(Context context) {
super(context);
try {
AssetManager assetManager = context.getAssets();
InputStream inputStream;
inputStream = assetManager.open("Background.png");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_4444;
bg = BitmapFactory.decodeStream(inputStream, null, options);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void onDraw(Canvas canvas) {
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
int iWidth = bg.getWidth();
int iHeight = bg.getHeight();
for (int x = 0; x < width; x += iWidth) {
for (int y = 0; y < height; y += iHeight)
canvas.drawBitmap(bg, x, y, null);
}
loadWorld(FILENAME);
invalidate();
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.seanheiss.shovelshovel.DisplayMap.TileBackground
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/TileBackground" />
<ImageView
android:id="@+id/MapImage"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
1 つの setContentView にコメントし、もう 1 つにはコメントしないことで、1 つの部分を描画できますが、両方を描画する方法がわかりません。ViewFlipper と呼ばれるものについて聞いたことがありますが、それを使用する必要があるかどうかはわかりません。仕組みがわかりません。
私を助けることができる人に感謝します!