• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Help with a Level Format

Hi, Gravity Games here, and I'm working on a simple platform game for android. Unfortunately however, I'm having trouble implementing a level format that spawns objects. I'm trying to read a .txt file, then write integers into an arraylist, and finally using the appropriate line in the array for a variable in the object (x and y position, and later on which graphic file it uses)

Here's what I've got:

gameView:

Code:
package com.gravitygamesinteractive.mysticmaze;

import android.view.*;
import android.content.*;
import android.graphics.*;
import javax.security.auth.callback.*;
import android.view.SurfaceHolder.Callback;
import java.util.*;
import java.io.File;

public class gameView extends SurfaceView
{

private Bitmap bmp;
private Bitmap tilebmp;
private SurfaceHolder holder; 
private GameLoopThread gameLoopThread;
private Sprite sprite;
private List<Tile> tiles=new ArrayList<Tile>();
private ArrayList<String> tilexarray=new ArrayList<String>();
private ArrayList<String> tileyarray=new ArrayList<String>();
private ArrayList<String> tileidarray=new ArrayList<String>();
private Scanner tilescan;
private int tileobjid;
private int tilex;
private int tiley;
private String tileobjidstr;
private String tilexstr;
private String tileystr;
private int b=0;
private int ta=0;

public gameView(Context context){
super(context);
gameLoopThread=new GameLoopThread(this);
holder=getHolder();
holder.addCallback(new Callback() {

@Override
public void surfaceDestroyed(SurfaceHolder holder){
gameLoopThread.setRunning(false);
gameLoopThread.stop();
}
@Override
public void surfaceCreated(SurfaceHolder holder){
gameLoopThread.setRunning(true);
gameLoopThread.start();

}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height){

}
});
bmp=BitmapFactory.decodeResource(getResources(), R.drawable.kyle);
sprite=new Sprite(this,bmp);
levelFile();
tilebmp=BitmapFactory.decodeResource(getResources(), R.drawable.ttile);
for(ta=0; ta<tilexarray.size(); ta++){
tiles.add(createTile(R.drawable.ttile));
}
}

private Tile createTile(int resource){
	Bitmap tilebmp=BitmapFactory.decodeResource(getResources(),resource);
return new Tile(this,tilebmp,Integer.parseInt(tilexarray.get(ta)),Integer.parseInt(tileyarray.get(ta)));
}

@Override
protected void onDraw(Canvas canvas){
canvas.drawColor(Color.BLACK);
sprite.onDraw(canvas);
for (int tac=0;tac<tilexarray.size();tac++){
Tile tile=new Tile(tilebmp,10,40);
	tile.onDraw(canvas);
}
	}

public void levelFile(){
try{
tilescan=new Scanner(new File("assets//levels//w1-1.txt"));
b=0;
while(tilescan.hasNextLine()){
tilex=tilescan.nextInt();
tilexstr=Integer.toString(tilex);
tilexarray.add(b,tilexstr);
tiley=tilescan.nextInt();
tileystr=Integer.toString(tiley);
tileyarray.add(b,tileystr);
	b++;
}
}catch(Exception e){}
}
	public ArrayList getTarrx(){
		return tilexarray;
	}
	public ArrayList getTarry(){
		return tileyarray;
	}
}

Tile:
Code:
package com.gravitygamesinteractive.mysticmaze;

import android.graphics.*;

public class Tile
{
private int x;
private int y;
private gameView gameview;
private Bitmap bmp;
private int altx;
private int alty;

public Tile(gameView gameview, Bitmap bmp, int x, int y){
this.gameview=gameview;
this.bmp=bmp;
this.x=x;
this.y=y;
altx=x;
alty=y;
}

private void update(){

}
public void onDraw(Canvas canvas){
update();
canvas.drawBitmap(bmp,x,y,null);
}
}

and here's the error I keep getting:
Constructor 'com.gravitygamesinteractive.mysticmaze.Tile.Tile(com.gravitygamesinteractive.mysticmaze.gameView,android.graphics.Bitmap,int,int)' can not be applied to '(android.graphics.Bitmap,int,int)'
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones