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

2011/7/11

Problem with the Drawstring method

w1llis w1llis

2011/7/11

#
I wrote the following code:
public void drawVitals(){
drawString(health, 1, 1); 
}
But when i run it, it gives the following error: Cannot find symbol - method drawString(int, int, int) Are there any imports i need? Is there a special Greenfoot only method i can use to do this? Thanks!
GameCode GameCode

2011/7/11

#
You drawString is a method of GreenfootImage! This will work: getImage().drawString(...);
w1llis w1llis

2011/7/11

#
Did that, got a new error:
drawString(java.lang.String, int, int) in greenfoot.GreenFootImage cannot be applied to (int, int, int)
I think i know the problem, health is an int, not a string :O How do i transfer an int to a string? Nevermind figured it out
GameCode GameCode

2011/7/11

#
Well, thats very easy, just write getImage(""+health, ...); The ""+int transfers it into a String
GameCode GameCode

2011/7/11

#
Upps, I meant getImage().drawString(""+health, ...);
w1llis w1llis

2011/7/11

#
I see... Thanks
GameCode GameCode

2011/7/11

#
No problem =)
DonaldDuck DonaldDuck

2011/7/12

#
health_string = Integer.toString(health); //make an integer copy of health
getImage().clear(); //erase current image
getImage().drawString(health_string, 0, 1); //update image
You need to login to post a reply.