i have a sprite sheet called "words sprites.png" and it has the images of all numbers (0-9) next to each other. In my program i have a int called score which holds my current score, it begins at 0. I have a class called Others which i am trying to use to display the score by using the images on the sprite sheet. This needs to work even if the score is bigger than 1 digit, so if the score = 1290 the Others class's image will display 1290 using the images in my sprite sheet. how do i do this? pls provide an example code :)
the sheet displays 0-9 in a row with each digit being the size of 7x7 pixels. Each digit in the sprite sheet has a 1 pixel spacing in between (included in the 7x7 box).
this is the closest iv got.
its supposed to convert the int to a String, then using the for loop it goes through each char in the String and for each of those it will check which number it is using another for loop and depending on what it comes out with it will change the image to the required picture and draw it on top of the fullWord image, and then continue on checking the next number in the string. But i have done something wrong and i cant find it.
private GreenfootImage sprite=new GreenfootImage("words sprites.png"); private GreenfootImage image; SpaceInvadersWorld world = (SpaceInvadersWorld) getWorld(); String score = world.score+""; GreenfootImage fullWord = new GreenfootImage(score.length()*7,7); for(int i=0; i<score.length(); i++) { for(int a=0; a<10; a++) { int num = score.charAt(i); if(num==a) { image.clear(); image.scale(image.getWidth()/3,image.getHeight()/3); imageX=a*-7-1; image.drawImage(sprite,imageX,imageY); image.drawImage(fullWord,i*-7,-1); } }