# How much do pixels move when you change a sprite's x position by 1?

I noticed that there was a problem in my tower defense game. I use a stretched costume that acts as the range of the towers and if an enemy enters their range (it switches to the range costume and checks if any enemies are touching) then it shoots the first enemy.

Sometimes it doesn't turn back into the regular costume and other times it just lags the game. I thought of other things, and one thing that I concluded might work is checking if the distance between the tower and the enemy is a certain amount. Though, I am still keeping the costume so I can let the user visually understand how much range a tower has.

I see no reason not to do this, but I can't seem to get the proportion right when I try to multiply pixels as big as distances, it's always too big or too small. I obviously can't guess. I can't just see the costume height or width because that goes by pixels, not differences. I can't make a ruler sprite and check the difference because I don't know how far apart each line will be.

So that is what I need to know. How much do pixels move when you change x by 1? I really need to know the ratio of pixels to 1 X position. Here is the project. Everything else in the project works, I did the distance detection good, but it goes too far, and the towers are shooting enemies outside their range because I did not determine the distance yet.

I figured it out, so sorry if I wasted your time. The ratio is two pixels for every X position.

To answer the question asked in the title, the position on the stage is not done by pixels, because the stage can be zoomed in and out. Instead it uses coordinates, much like in math class (in fact, it's exactly like math class). A costume size is indeed in pixels, but visually it's scaled up or down to match the stage coordinates (so the size can be used as stage coordinates). The term you should be using is units.

So, I need to say, "X units"? Thank you for clarifying that, I will say that instead next time. I already knew very well what the X and Y coordinates are representing, I just didn't know what to call it in this context.

This is true only if you are using a 4K (Retina) display. On less dense displays, one turtle step is one pixel. The idea is that a square of side length 100 should neither be tiny nor fill the stage. It should be about an inch on a side, roughly.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.