Python+Pygame开发CHIP-8模拟器无渲染输出问题求助
CHIP-8模拟器渲染IBM Logo无输出问题
用Python结合Pygame开发CHIP-8模拟器,完成所有指令添加后尝试渲染IBM logo时,完全没有任何输出。排查后发现负责渲染的render方法甚至未被调用。
相关代码片段
渲染指令实现代码
def drw_vx_vy(self): width = 8 height = self.opcode & 0xF print("drw") self.v[0xF] = 0 for row in range(height): sprite = self.memory[self.i + row] for col in range(width): if (sprite & 0x80) > 0: self.display.draw_pixel(self.v[self.x] + col, self.v[self.y] + row) self.v[0xF] = 1 sprite = sprite << 1
Display类渲染相关代码
def draw_pixel(self, x, y): if x > self.width: x -= self.width elif x < 0: x += self.width if y > self.height: x -= self.height elif x < 0: x += self.height pixelLoc = x + (y * self.height) self.pixels[pixelLoc] = self.pixels[pixelLoc] ^ 1 print(self.pixels[pixelLoc]) return not self.pixels[pixelLoc] # pygame.draw.rect(self.surface, (255,255,255), ( # x * self.scale, y * self.scale, self.scale, self.scale) # ) def clear_display(self): self.screen.fill((0,0,0)) def render(self): self.clear_display() for i in range(self.width * self.height): x = (i % self.width) * self.scale y = i / self.width * self.scale if self.pixels[i]: pygame.draw.rect(self.surface, (255,255,255), ( x, y, self.scale, self.scale) ) pygame.display.update()
已检查过drw_vx_vy函数是否放在错误的case语句中,确认没问题。开发时参考了FreeCodeCamp的CHIP-8模拟器开发指南(原指南为JavaScript实现,已适配为Python版本)。
内容的提问来源于stack exchange,提问作者TechStudent10
相关产品推荐
相关产品推荐

