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

2019/2/3

Image

Adi18 Adi18

2019/2/3

#
I want to get the limits of an image and I don't know if I did well. up=this.getY()-this.getImage().getHeight()/2; down=this.getY()+this.getImage().getHeight()/2; left=this.getX()-this.getImage().getWidth()/2; right=this.getX()+this.getImage().getWidth()/2;
danpost danpost

2019/2/3

#
Adi18 wrote...
I want to get the limits of an image and I don't know if I did well. << Code Omitted >>
Yes, that would give you the bounds of the actor's image in world coordinates.
Adi18 Adi18

2019/2/3

#
Thank you
danpost danpost

2019/2/3

#
Adi18 wrote...
Thank you
Note, however, when dividing the image width and height by 2, there may be a loss of 1 pixel (when a dimension is odd). Also, keep in mind that subtracting from location will end on an edge pixel of the image, but adding will end 1 pixel off the edge (when dimension is even). So, if you need to be precise, the combination of these needs to be considered.
Adi18 Adi18

2019/2/3

#
Thanks. That could be a problem because I want to do something like a character can only jump to the top of the image, but if it touches the left, right or down side is put aside
danpost danpost

2019/2/3

#
Adi18 wrote...
Thanks. That could be a problem because I want to do something like a character can only jump to the top of the image, but if it touches the left, right or down side is put aside
For that, all you really need to know is the direction that the character moved. For example, if moved right and touches the object, then the object is to the right. Same goes for the other directions. As long as you adjust the position of the character such that it no longer touches the object (moving opposite the initial direction moved), you should not have any issues.
You need to login to post a reply.