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

2017/1/7

How do you make an image smaller and make the "hit box" transparent

new113 new113

2017/1/7

#
I wanted to know how do you get an actor image smaller (if possible using code) and make the background/ hit box transparent.
danpost danpost

2017/1/7

#
new113 wrote...
I wanted to know how do you get an actor image smaller (if possible using code) and make the background/ hit box transparent.
Are you asking how to reduce the size of the image of an actor without reducing the size of the hit box?
Nosson1459 Nosson1459

2017/1/8

#
To change the size of an image you can do:
1
2
3
GreenfootImage image = new GreenfootImage("text", 28, null, null);
// to change the dimensions of the image you then do (to make it half the size)
image.scale(image.getWidth() / 2, image.getHeight() / 2);
to make an image transparent you can do:
1
2
3
GreenfootImage image = new GreenfootImage("text", 28, null, null);
// to make an image transparent you then do
image.setTransparency(0);
Edit: Now after I posted my post do I understand danpost's question.
new113 new113

2017/1/8

#
I want the "hit box" reduced or made transparent..
Nosson1459 Nosson1459

2017/1/8

#
new113 wrote...
I want the "hit box" to be smaller too.
An actor on the screen is it's image. If you have an image that's 100 x 100 pixels then that's the size of the Actor. You can have an image that's 100 x 100 pixels but with a border of 25 pixels on each side that's transparent so there is only 50 square pixels visible but the Actor is actually 100 x 100 pixels, so by changing the image size that is changing the actor size. (If that's not true, then where do you choose a size for the Actor itself?)
Nosson1459 Nosson1459

2017/1/8

#
(You edited your post.) Reducing the size of an image/actor is different than making the image entirely transparent but keeping the same size. Transparent pixels are still part of the actor so if you use isTouching it will detect transparent pixels, but if you reduce the size it will only detect the pixels of the newly reduced image.
danpost danpost

2017/1/8

#
danpost wrote...
Are you asking how to reduce the size of the image of an actor without reducing the size of the hit box?
The following does not answer my question:
new113 wrote...
I want the "hit box" reduced or made transparent..
Maybe you should be more specific. Give the sizes of the current image and its hit box and then give what you want them to be. Or, if there is an issue that requires the change, give an explanation of the issue -- how it is not what you want and want you actually want. I guess you can start by using the first code-post that Nosson1459 gave to size your image correctly; then, you can explain about the hit box using the new set of circumstances (breaking the problem down into individual steps).
Nosson1459 Nosson1459

2017/1/9

#

Side point:

The post was originally:
new113 wrote...
I want the "hit box" to be smaller too.
then it was edited to be:
new113 wrote...
I want the "hit box" reduced or made transparent..
but that doesn't necessarily help you (danpost) with your questions.
danpost danpost

2017/1/9

#
Nosson1459 wrote...
The post was originally: < Quote Omitted > then it was edited to be: <Quote Omitted>
The final original post says nothing about reducing the size of the hit box -- just making it transparent. Hence, my original question.
new113 new113

2017/1/9

#
The size of my image is 400x400 pixels. Also when I used that code (Nosson1459)were do you put the size of the actor?
Nosson1459 Nosson1459

2017/1/9

#
new113 wrote...
Also when I used that code (Nosson1459)were do you put the size of the actor?
That's what I'm asking you. I never knew there was a thing of setting actor sizes. What I was saying was that the actor size is it's image, so your actor is 400 x 400 pixels big "The size of my image is 400x400 pixels.". My code should be put in the place that you want to change the size or transparency of the image. If you want to do this in the beginning then put the code in the class constructor. You can put anywhere in the middle of your code to change the size of the image/actor in the middle of execution but if you would just put it in the act method, since my code halves the image size (instead setting int sizes) you probably won't much of a glance at your image.
You need to login to post a reply.