When you draw in Java it automatically draws from Left to Right. How can I invert this so the sprites are drawn from Right to Left ?
Just draw at a specified offset. For example:
g.drawImage(x - image.getWidth(), y); // x - imageWidth should be cached
I think he means “mirroring” it.
Just use g.drawImage:
You just need to swap the source rectangle and the destination rectangle coordinates on the X axis and it will be flipped horizontally. Swap the Y to flip vertically, and swap both to rotate 180º.
This is the problem I’m having…
The character in my game can dash. When he dashes to the left, and stops he stops where he is in the screen.
http://img62.imageshack.us/img62/6333/dashleft.png
Now when I dash to the right, and he stops he appears in the last position of the smoke (The Yellow Part). He even flashes as he dashes to the right.
http://img94.imageshack.us/img94/3323/dashright.png
Watch the streaming Video to see it in action
VIDEO = http://www.screentoaster.com/watch/stUE9dQ0RIR19bQF5YWl5QUVBW/glitch
This is why I think the problem is coming from Javas default way of drawing which is from Left to Right. So making it draw from Right to Left when the character is looking to the right might fix the problem, I’m just not sure how to switch it and where to implement this.
My draw statement looks like this…
g.drawImage(MasterGX.getImage(), (int)MasterGX.getX() , (int)MasterGX.getY(), MasterGX.getWidth(),MasterGX.getHeight(), null);
NOTE : “MasterGX” is the characters Name.
The dash probably shouldn’t be part of the same sprite. The solution would be to either separate them and draw the dash manually behind the sprite, or draw at an offset.
That’s a good Idea. I’ll try that.
Thanks.