0

This is what my vegitables.java looks like

 public class Vegitable extends Context {
    String type;
    int side, position;

 public Vegitable(int side, int position) {
    if(side < 3 && side > 0 && position < 3 && position > 0) {
        this.side = side;
        this.position = position;
        this.setRand();
    }
  }
  public String getType() {
    return this.type;
  }

   public  boolean setRand() {
      Random rr = new Random();
      switch(rr.nextInt(3 - 1) + 1) {

        case 1:
            this.type = "Onion";
            break;
        case 2:
            this.type = "Pepperoni";

            break;
        default:
            return false;
    }
    return true;
} 

In my Main.Activity i want to randomly generate eighter an onion or a pepperoni. (Like this:)

public void spawn() {

    if(this.vegi.length > 30)
        return;

    Random r = new Random();

    if(r.nextInt(this.spawnRotationMax - 1) + 1 != 1)
        return;

    this.vegi[vegiNum] = new Vegitable(r.nextInt(3 - 1) + 1,r.nextInt(3 - 1) + 1);
    //this.vegi[1].getResources().getDrawable(R.drawable.charab);


    if (vegi[vegiNum].type.equals("Pepperoni")){}

    Toast.makeText(GameAcvitiy.this, this.vegi[vegiNum].getType(), Toast.LENGTH_LONG).show();
    vegiNum++; 

My question is : Where and how can i give my vegi objects an image so i can see and use them in my Main.Activity ? (I want to let em collide later on)

Thank you !

1 Answers1

0

If you want to put this into a game (sounds like it from what you mentioned about them colliding), then you should look in to using Bitmaps to render the graphics. In that case, this should be helpful. Any generic Android game tutorial will help with this. You could load the images normally, or from a sprite sheet.

If you just want to display the images inside a layout (such as a LinearLayout or a ListView), look in to using ImageViews.

Community
  • 1
  • 1
Danny Buonocore
  • 3,731
  • 3
  • 24
  • 46
  • Could you make an example (with the given code) or give me a link to a good tutorial ? Would appreciate – Dennis Oßwald May 12 '15 at 15:00
  • If you're looking for the first approach, you can check out http://gamedevelopment.tutsplus.com/tutorials/an-introduction-to-spritesheet-animation--gamedev-13099. Upvote/mark as best answer if it helps – Danny Buonocore May 12 '15 at 15:03
  • I think we are talkin in different directions. I want my vegi objects to have a bitmap. So you can see the objects on the screen after i called them . – Dennis Oßwald May 12 '15 at 16:06