I need to initialize View and Canvas for the project I'm working on, but after an hour or so or searching, I can't figure out what to make them equal to.
Here is the code I have so far:
public class DisplayMap extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
displayMap();
} catch (IOException e) {
e.printStackTrace();
} catch (SlickException e) {
e.printStackTrace();
}
}
public void displayMap() throws IOException, SlickException {
loadWorld("assets/World.tmx");
}
public void loadWorld(String path) throws IOException {
View view = ?????;
Canvas canvas = ?????;
//World loading goes here
}
}
So, can anybody please suggest me how to initialize View and Canvas? Or am I going about this in the completely wrong way?
You need to write a custom view that loads the map, and then use the custom view in your activity.
In TMXView.java
:
public class TMXView extends View {
public TMXView(Context context) {
super(context);
// Load map
}
public void onDraw(Canvas canvas) {
// Draw the map on the canvas
}
}
In onCreate
of your activity:
View view = new TMXView(this);
setContentView(view);
For more information, refer to my talk on custom components: http://www.sqisland.com/talks/android-custom-components/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With