This site requires JavaScript, please enable it in your browser!
Greenfoot back
kartikitrak
kartikitrak wrote ...

2012/5/26

Importing an Image

kartikitrak kartikitrak

2012/5/26

#
In my program, I have a whole bunch of classes that have to deal with objects and I really hate to create my classes for something as simple as what I'm trying to do. Currently I have an inventory image. In the inventory I want to have icons of the weapons that I will allow the user to choose from. How does one draw an icon(that I have a picture of in my image folder) on the inventory without replacing the inventory background image and without creating an object for the icon that I can later use to reduce the transparency when needed.
danpost danpost

2012/5/26

#
What does that have to do with 'Importing an Image' (your title)? Are you wanting to know how to draw the icon images on the inventory image? If so, look in the GreenfootImage API for a method that you could use to accomplish the task. Note, however, that if you are going to have the user click on an icon to select it, you will need to get the MouseInfo of the click and calculate the location of the click to determine which icon was clicked on.
kartikitrak kartikitrak

2012/5/26

#
I'm trying to get the icon images to be drawn onto the inventory image. Not interaction with the user will be needed. for the drawImage command is it: .drawImage(,xcoord,ycoord) for example: blueIcon.drawImage(inventorySlots,425,10)
danpost danpost

2012/5/26

#
No, it would be .drawImage(, imageX, imageY) for example: inventorySlots.drawImage(blueIcon, 425, 10); The imageX and imageY are where on the you want the top-left corner of .
kartikitrak kartikitrak

2012/5/27

#
I got a cannot find symbol - method drawImage(blueStarIcon,int,int) This was world class. inventorySlots is an object that has an image of the inventory and blueIcon is just an image.
danpost danpost

2012/5/27

#
Check your calling statement; make sure you are drawing on a GreenfootImage object. If inventorySlots is an object, not the image itself, you need to use:
inventorySlots.getImage().drawImage(blueIcon, 425, 10);
You need to login to post a reply.