fixed sprites falling off top of screen
This commit is contained in:
parent
02bc2df0e8
commit
d90b773c7f
|
@ -237,9 +237,12 @@ impl Gpu {
|
||||||
|
|
||||||
fn parse_oam(&mut self, scanline: u8) -> Vec<Object> {
|
fn parse_oam(&mut self, scanline: u8) -> Vec<Object> {
|
||||||
let mut objs = vec![];
|
let mut objs = vec![];
|
||||||
|
let effective_scanline = scanline + 16;
|
||||||
for i in (0xFE00..0xFE9F).step_by(4) {
|
for i in (0xFE00..0xFE9F).step_by(4) {
|
||||||
let y_pos = self.oam.get(i).wrapping_sub(16);
|
let y_pos = self.oam.get(i);
|
||||||
if y_pos <= scanline && (y_pos + self.lcdc.obj_size.get_height()) > scanline {
|
if y_pos <= effective_scanline
|
||||||
|
&& (y_pos + self.lcdc.obj_size.get_height()) > effective_scanline
|
||||||
|
{
|
||||||
// sprite is on line
|
// sprite is on line
|
||||||
let x_pos = self.oam.get(i + 1);
|
let x_pos = self.oam.get(i + 1);
|
||||||
let mut tile_index = self.oam.get(i + 2);
|
let mut tile_index = self.oam.get(i + 2);
|
||||||
|
@ -277,7 +280,7 @@ impl Gpu {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_object(&mut self, scanline: u8, object: Object) {
|
fn render_object(&mut self, scanline: u8, object: Object) {
|
||||||
let mut object_row = scanline - object.y;
|
let mut object_row = scanline - (object.y.wrapping_sub(16));
|
||||||
if object.flags.y_flip {
|
if object.flags.y_flip {
|
||||||
object_row = self.lcdc.obj_size.get_height() - (object_row + 1);
|
object_row = self.lcdc.obj_size.get_height() - (object_row + 1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue