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

2013/4/15

Graphics selection

JetLennit JetLennit

2013/4/15

#
Is there a way to select a small portion of a image to set as the actor sprite? Aside from the obvious move only a part of the image to a different image that would result in like 20 images for each character
danpost danpost

2013/4/15

#
You do not have to move a small portion only. You can draw the big image on the small image wherever (even using negative starting coordinates). So, let us say you had an image that was 200 x 200 and you wanted to create 4 images, 50 x 50 in size, one for each quadrant of the big image.
GreenfootImage bigImage;
bigImage = new GreenfootImage("bigImage.png");
GreenfootImage[] quads = new GreenfootImage[4];
for (int i=0; i<4; i++)
{
    int x = i % 2;
    int y = i / 2;
    quads[i].drawImage(bigImage, -50*x, -50*y);
}
should do it.
JetLennit JetLennit

2013/4/15

#
what about a 130 x 180 picture with 12?
danpost danpost

2013/4/15

#
Wow. I guess I forgot to create the smaller images in the last code post (I added it in the one below).
GreenfootImage bigImage;
bigImage = new GreenfootImage("bigImage.png");
bigImage.resize(135, 180);
GreenfootImage[] quads = new GreenfootImage[4];
for (int i=0; i<12; i++)
{
    int x = i % 3;
    int y = i / 3;
    quads[i]=new GreenfootImage(45, 45);
    quads[i].drawImage(bigImage, -45*x, -45*y);
}
I do not think the small amount of resize will distort the picture enough to make a difference; and the pieces can be square with this.
JetLennit JetLennit

2013/4/15

#
I am sorry that i have changed it again... but could you show me how to do it regardless of size (or almost)? (This is the last time i change it) And how do i use this as a actor's sprite and easily change it from one to the other
danpost danpost

2013/4/15

#
Will it always be 3 parts across and 4 parts down to make up the 12 portions? and why are you wanting to change the image of the actors from one to another? Maybe you should explain what you are trying to do (it would make it easier for me to determine how to respond). Like, why do you split the image to begin with? what functionaility are you placing on the actors that get these images? what triggers changing of the images? etc.
JetLennit JetLennit

2013/4/15

#
Sorry about that.. forgot to give the information. 1.Yes 2.
  • For walking animation
  • Switching direction
3.A Pokemon Game 4.I don't want to create a different sprite for each position (however I can if i have to) 5.Go to 2 6.Keys
danpost danpost

2013/4/15

#
Once the images are created, it is just a matter of changing the image of the actor to the appropriate image at the appropriate time. I will try to redo the method for any size image that is generally about 30 percent taller than it is wide. Wait, the code above will do any image of a fair size and shape already. I did notice I forgot to change the number of elements in the array on line 00. (line 4). Corrected line follows:
GreenfootImage[] quads = new GreenfootImage[12];
However, the name of the image array should probably be changed from 'quads' to something more appropriate, 'duodecas' maybe.
You need to login to post a reply.