Why does flipping on y axis (using y scaling) cause a shift up in location?
Posted: Tue Dec 17, 2019 11:16 am
Hello, I'm currently on Week 1 of an online course called GD50 where you recreate some simple games in Love2D.
This week we're recreating 'Flappy Bird', which involves flying through pairs of pipes: one hanging down from the sky, and one coming up from the ground.
The original pipe image is of one coming up out of the ground. To get our pipes to come down from the sky, we set y-scaling to '-1', but we also, apparently, need to shift the pipe down by its own height. I don't understand why this is necessary.
function Pipe:render()
love.graphics.draw(PIPE_IMAGE, self.x,
(self.orientation == 'top' and self.y + PIPE_HEIGHT or self.y),
0, 1, self.orientation == 'top' and -1 or 1)
end
So, to be clear, all I want to do is to flip a pipe, while not moving it: I want it to be drawn up from the point it was previously drawn down from, so that if you first drew the pipe as normal and then inverted it and drew it again, the two would meet in the middle.
Does anyone know why this shift occurs?
Thank you!
This week we're recreating 'Flappy Bird', which involves flying through pairs of pipes: one hanging down from the sky, and one coming up from the ground.
The original pipe image is of one coming up out of the ground. To get our pipes to come down from the sky, we set y-scaling to '-1', but we also, apparently, need to shift the pipe down by its own height. I don't understand why this is necessary.
function Pipe:render()
love.graphics.draw(PIPE_IMAGE, self.x,
(self.orientation == 'top' and self.y + PIPE_HEIGHT or self.y),
0, 1, self.orientation == 'top' and -1 or 1)
end
So, to be clear, all I want to do is to flip a pipe, while not moving it: I want it to be drawn up from the point it was previously drawn down from, so that if you first drew the pipe as normal and then inverted it and drew it again, the two would meet in the middle.
Does anyone know why this shift occurs?
Thank you!