Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -

Post new topic Reply to topic  [ 1 post ] 
  Fri Mar 09, 2012 8:39 pm
User avatar

Omnipresent Merchant
This is a really basic thing, but it's just took me hours to work out how to do, and Google said nothing useful at all on the matter. So, I'm posting this just so that next time someone googles it, they have a quick response.

How to draw an image in Android

1. Save an image, such as a .png, in the folder myGame/res/drawable-mdpi
2. Eclipse will load this and assign a variable to it that you can use


import android.graphics.BitmapFactory;

In your draw method of your class:

g.drawBitmap(BitmapFactory.decodeResource(activity.getResources(), R.drawable.background1), 0, 0, null);

Where g is your canvas.

Here, "background1" is the name of your image.

You'll need a Context. Everyone will throw around the word Context without giving you a clue in hell as to what it means.

Well, Activity is a Context. So, you'll need to pass "this" in when initializing your class in your activity.

For example:

Background background = new Background(width, height, this);

// in your class

public Background(int width, int height, Activity a)
activity = a;

Anyway I hope it's useful.

And I can guarantee that magically as soon as I've posted this somebody will reply and say "that's simple! You actually only need to x, y, z"

Such is the way of bloody java programming.

I'm on a horse.

Top Top
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

Who is online

Users browsing this forum: No users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

We are an independent, not-for-profit game making community.
Board Index
About Us
Downloadable Games
Free Browser Games
Games in Development
RPG Maker Support
Game Maker Support
Construct 2 Support
HBGames the eZine
Advanced RPG Maker
Site Announcements
Powered by phpBB © phpBB Group