Re: Set pixel in the world, not on the screen.
Posted: Wed Nov 25, 2015 5:58 pm
Ok. My game is almost done. But I wanted to talk about my method a little bit. Basically you have your pixel's coordinates, lets call them PixelX and PixelY, and you use setPixel to set it. But the coordinates need to keep updating based on the ScreenXOffset & ScreenYOffset. So we do this:
Now, the screen offset variables are negative because of how the screen moves. If I were to leave them positive they would automatically move in the same direction as the player. (See below. Player=red Pixel=white)
But the world isn't supposed to move with the player. It should scroll left when we walk right, and up when we go down, etcetera. (See below. Player=red Pixel=white)
So in this case we want the variables to be negative. But there's a couple of glitches that happen using this method.
1st, when I move off the screen to the left, right, or down, the pixel moves off the screen as expected. But when I move the player up the pixel sticks to the bottom of the screen. (See below. Player=red Pixel=white)
2nd, on the left it creates a string of pixels. Each with seven (7) spaces between them. Because of this, only one of the pixels in the string can be seen at a time. (See below. Player not present. Pixel specified.)
This is what I used to test the player's Y position so that it will only set the pixel when the player is in that area, hence stopping the sticking.
To remove the string of pixels I use the same concept, but for the X axis. Like this:
Because only one pixel in the string can be seen at a time none of the other pixels will be visable once setPixel is activated, hence killing the string. The number eight is used because the screen is eight pixels wide. The reason for this is... well I don't remember exactly. But it works! ;D I hope I explained myself in an understandable way. If you know what causes these glitches I would love to know!
Code: Select all
digiPixel.setPixel(-ScreenXOffset+PixelX,-ScreenYOffset+PixelY,PixelColor);
But the world isn't supposed to move with the player. It should scroll left when we walk right, and up when we go down, etcetera. (See below. Player=red Pixel=white)
So in this case we want the variables to be negative. But there's a couple of glitches that happen using this method.
1st, when I move off the screen to the left, right, or down, the pixel moves off the screen as expected. But when I move the player up the pixel sticks to the bottom of the screen. (See below. Player=red Pixel=white)
2nd, on the left it creates a string of pixels. Each with seven (7) spaces between them. Because of this, only one of the pixels in the string can be seen at a time. (See below. Player not present. Pixel specified.)
This is what I used to test the player's Y position so that it will only set the pixel when the player is in that area, hence stopping the sticking.
Code: Select all
if (ScreenYOffset-PixelY < 1)
Code: Select all
if (ScreenXOffset > PixelX-8)