diff --git a/agb/src/display/object.rs b/agb/src/display/object.rs index f8f9a0c..bad3571 100644 --- a/agb/src/display/object.rs +++ b/agb/src/display/object.rs @@ -3,6 +3,7 @@ use core::cell::RefCell; use super::DISPLAY_CONTROL; use crate::bitarray::Bitarray; use crate::memory_mapped::MemoryMapped1DArray; +use crate::number::Vector2D; const OBJECT_ATTRIBUTE_MEMORY: MemoryMapped1DArray = unsafe { MemoryMapped1DArray::new(0x0700_0000) }; @@ -114,6 +115,15 @@ impl ObjectStandard<'_> { pub fn hide(&mut self) { self.attributes.set_mode(Mode::Hidden) } + + /// Sets the x and y position of the object, performing casts as nessesary + /// to fit within the bits allocated for this purpose. + pub fn set_position(&mut self, position: Vector2D) { + let x = position.x as u16; + let y = position.y as u16; + self.attributes.set_x(x); + self.attributes.set_y(y); + } } impl<'a> ObjectAffine<'a> { @@ -157,6 +167,15 @@ impl<'a> ObjectAffine<'a> { self.attributes.set_affine(aff.loan.index); self.aff_id = Some(aff.loan.index); } + + /// Sets the x and y position of the object, performing casts as nessesary + /// to fit within the bits allocated for this purpose. + pub fn set_position(&mut self, position: Vector2D) { + let x = position.x as u16; + let y = position.y as u16; + self.attributes.set_x(x); + self.attributes.set_y(y); + } } fn set_bits(current: u16, value: u16, length: u16, shift: u16) -> u16 {