擅长:python、mysql、java
<p>我以前做过的创建滚动环境的方法是给每个对象在世界上的坐标,然后给你的相机一个位置。绘图时,根据对象的实际坐标和相机的坐标计算每个对象在屏幕上的位置。在</p>
<pre><code>class Tile:
def __init__(self, x, y, other_variables):
self.x = x
self.y = y
# relative vars for later
self.relX = None
self.relY = None
# then your camera should have a position as well as its width and height:
class Camera:
def __init__(self, x, y, width, height):
# assign those variables here
# your drawing function:
for tile in tiles:
tile.relX = tile.x - camera.x
tile.relY = tile.y - camera.y
# blit your tiles to the screen at the relative coordinates
</code></pre>
<p>此外,还可以执行检查,以查看平铺是否完全位于摄影机空间之外,并且不绘制这些平铺。在</p>