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

2020/1/17

image scaling is awful! need help!

LightningFast LightningFast

2020/1/17

#
here is the code... import greenfoot.*; public class Textboxes extends Actor { int c;//counter public void act() { ranOrder(); } public Textboxes() { getImage().scale(15,10); } public void ranOrder() { if (c%300 == 0) { int ord = Greenfoot.getRandomNumber(2); GreenfootImage textArrays = {new GreenfootImage("RekaText1.png"),new GreenfootImage("RekaText2.png"),new GreenfootImage("RekaText3.png")}; setImage(textArrays); } c++; //counter increments (60 times per second, meaning 300 times = 5 sec) } }
danpost danpost

2020/1/17

#
The only scaled image is the initial one. I do not know if you wanted to scale it so small, but, for a text box, it would only be good for about one character of text. Also, your third image in the array will never show as you limit your random choice to only 2 possibilities.
MrCohen MrCohen

2020/1/17

#
danpost, you are too patient. I humbly bow down to you... But this ... code ... what? 1. Don't scale images. Make them the size you want in a graphic editor. Scaling should really only be used for effect (I.e. making an Enemy image shrink to nothing after the player hits it with a spell). If you're importing and then immediately scaling an image, you're doing it wrong. 2. You haven't told us anything. What are you trying to do? What's wrong? I mean ... I can see the errors, but your title is irrelevant because your code is miles from compiling and the errors have little to do with the scaling. Why is scaling awful? 3. I'm curious why you're putting 3 images into an array. You can't just setImage to an array like that. You have to specify a specific image. You also can't declare an array without square brackets. Your errors have nothing to do with scaling. 4. You put getImage().scale(15,10) into the constructor, but you don't actually set an image until the ranOrder() method which is called by act(). Act will not run before the constructor is called, so the image will be empty.
danpost danpost

2020/1/17

#
MrCohen: 1. True -- but I would not call it wrong -- just not the optimal way. 2. Truthfully: no errors and will compile (see 3). 3. Actually, the square brackets were there. They just do not show outside code tags (Quote the post to see actual text). 4. The default image set to the class, which may not be empty, is being scaled -- albeit, to quite a small size.
MrCohen MrCohen

2020/1/17

#
Interesting. I did not now that the code blocks messed up ... code. Good to know for the future. Yes, I guess if the image was set in the menu with it would scale that image. But I figured he was trying to scale the images he was drawing out of text. And I do agree - I sometimes get "wrong" and "not optimal" confused. I'm just a picky teacher I guess.
LightningFast LightningFast

2020/1/18

#
Sorry for a late reply... I took into consideration what you guys have said and fixed the code! Thank you! Here's the fixed code... import greenfoot.*; import java.util.*; public class Textboxes extends Actor { int t = 0;//counter GreenfootImage textArrays = {new GreenfootImage("RekaText1.png"),new GreenfootImage("RekaText2.png"),new GreenfootImage("RekaText3.png"), new GreenfootImage("RekaText4.png"),new GreenfootImage("RekaText5.png"),new GreenfootImage("RekaText6.png")}; //GreenfootImage array to store images public void act() { picTimer(); } public void pic(int ord) { GreenfootImage image = (textArrays); //initialize image to an image from GreenfootImage array image.scale(150, 100); setImage(image); } public void picTimer() { if (t%180 == 0) //counter increments (60 times per second, meaning 180 times = 3 sec) { int order = Greenfoot.getRandomNumber(6); //generates a random number from 0-6 pic(order); //passes random num which will be index num for GreenfootImage array } t++;//counter } }
You need to login to post a reply.