@@ -215,27 +215,29 @@ def __init__(self, bank, width=8, height=8, palette=None, buffer=None):
215215 self .x = 0
216216 self .y = 0
217217 self .z = 0
218+ self .stride = (width + 1 ) & 0xfe
218219 self .width = width
219220 self .height = height
220221 self .bank = bank
221222 self .palette = palette or bank .palette
222- self .buffer = buffer or bytearray (( width * height ) >> 1 )
223- self .layer = _stage .Layer (width , height , self .bank .buffer ,
223+ self .buffer = buffer or bytearray (self . stride * height )
224+ self .layer = _stage .Layer (self . stride , self . height , self .bank .buffer ,
224225 self .palette , self .buffer )
225226
226227 def tile (self , x , y , tile = None ):
227228 """Get or set what tile is displayed in the given place."""
228229
229230 if not 0 <= x < self .width or not 0 <= y < self .height :
230231 return 0
231- b = self .buffer [(x * self .width + y ) >> 1 ]
232+ index = (y * self .stride + x ) >> 1
233+ b = self .buffer [index ]
232234 if tile is None :
233- return b & 0x0f if y & 0x01 else b >> 4
234- if y & 0x01 :
235+ return b & 0x0f if x & 0x01 else b >> 4
236+ if x & 0x01 :
235237 b = b & 0xf0 | tile
236238 else :
237239 b = b & 0x0f | (tile << 4 )
238- self .buffer [( x * self . width + y ) >> 1 ] = b
240+ self .buffer [index ] = b
239241
240242 def move (self , x , y , z = None ):
241243 """Shift the whole layer respective to the screen."""
@@ -270,8 +272,6 @@ def __init__(self, bank, frame, x, y, z=0, rotation=0, palette=None):
270272 def move (self , x , y , z = None ):
271273 """Move the sprite to the given place."""
272274
273- self .px = self .x
274- self .py = self .y
275275 self .x = x
276276 self .y = y
277277 if z is not None :
0 commit comments