pub struct PlaydateSystem { /* private fields */ }Implementations§
Source§impl PlaydateSystem
impl PlaydateSystem
Sourcepub fn log_to_console(&self, msg: impl AsRef<str>)
pub fn log_to_console(&self, msg: impl AsRef<str>)
Calls the log function.
Sourcepub fn error(&self, msg: impl AsRef<str>)
pub fn error(&self, msg: impl AsRef<str>)
Calls the log function, outputting an error in red to the console, then pauses execution.
Sourcepub fn get_language(&self) -> Language
pub fn get_language(&self) -> Language
Returns the current language of the system.
Sourcepub fn get_current_time_milliseconds(&self) -> usize
pub fn get_current_time_milliseconds(&self) -> usize
Returns the number of milliseconds since…some arbitrary point in time. This should present a consistent timebase while a game is running, but the counter will be disabled when the device is sleeping.
Sourcepub fn get_seconds_since_epoch(&self) -> (usize, usize)
pub fn get_seconds_since_epoch(&self) -> (usize, usize)
Returns the number of seconds (and sets milliseconds if not NULL) elapsed since midnight (hour 0), January 1, 2000.
Sourcepub fn draw_fps(&self, pos: Vec2<i32>)
pub fn draw_fps(&self, pos: Vec2<i32>)
Calculates the current frames per second and draws that value at x, y.
Examples found in repository?
24 fn update(&mut self, delta: f32) {
25 // Clear screen
26 PLAYDATE.graphics.clear(Color::White);
27 // Draw image
28 PLAYDATE.graphics.draw_rotated_bitmap(
29 &self.image,
30 vec2![130, 120],
31 self.rotation,
32 vec2![0.5, 0.5],
33 vec2![1.0, 1.0],
34 );
35 // Rotate image
36 self.rotation += delta * 90.0;
37 // Draw text
38 PLAYDATE
39 .graphics
40 .draw_text("Hello, World!", vec2![230, 112]);
41 // Draw FPS
42 PLAYDATE.system.draw_fps(vec2![0, 0]);
43 }More examples
174 fn update(&mut self, _delta: f32) {
175 let button_state = PLAYDATE.system.get_button_state();
176 let prev_scale = self.scale;
177 let prev_center = self.center;
178 // Scale
179 if button_state.current.contains(Buttons::A) {
180 self.scale /= 1.1;
181 } else if button_state.current.contains(Buttons::B) {
182 self.scale *= 1.1
183 }
184 if !PLAYDATE.system.is_crank_docked() {
185 let crank = PLAYDATE.system.get_crank_change();
186 if crank > 0.0 {
187 self.scale /= 1.05;
188 } else if crank < 0.0 {
189 self.scale *= 1.05;
190 }
191 }
192 // Move
193 if button_state.current.contains(Buttons::Up) {
194 self.center.im += 10.0 * self.scale
195 } else if button_state.current.contains(Buttons::Down) {
196 self.center.im -= 10.0 * self.scale
197 }
198 if button_state.current.contains(Buttons::Left) {
199 self.center.re -= 10.0 * self.scale
200 } else if button_state.current.contains(Buttons::Right) {
201 self.center.re += 10.0 * self.scale
202 }
203 if prev_center != self.center || prev_scale != self.scale {
204 self.draw_frame();
205 }
206 // Draw metadata
207 self.draw_meta();
208 // Draw FPS
209 PLAYDATE.system.draw_fps(vec2![0, 0]);
210 }Returns bitmasks indicating which buttons are currently down. pushed and released reflect which buttons were pushed or released over the previous update cycle—at the nominal frame rate of 50 ms, fast button presses can be missed if you just poll the instantaneous state.
Examples found in repository?
174 fn update(&mut self, _delta: f32) {
175 let button_state = PLAYDATE.system.get_button_state();
176 let prev_scale = self.scale;
177 let prev_center = self.center;
178 // Scale
179 if button_state.current.contains(Buttons::A) {
180 self.scale /= 1.1;
181 } else if button_state.current.contains(Buttons::B) {
182 self.scale *= 1.1
183 }
184 if !PLAYDATE.system.is_crank_docked() {
185 let crank = PLAYDATE.system.get_crank_change();
186 if crank > 0.0 {
187 self.scale /= 1.05;
188 } else if crank < 0.0 {
189 self.scale *= 1.05;
190 }
191 }
192 // Move
193 if button_state.current.contains(Buttons::Up) {
194 self.center.im += 10.0 * self.scale
195 } else if button_state.current.contains(Buttons::Down) {
196 self.center.im -= 10.0 * self.scale
197 }
198 if button_state.current.contains(Buttons::Left) {
199 self.center.re -= 10.0 * self.scale
200 } else if button_state.current.contains(Buttons::Right) {
201 self.center.re += 10.0 * self.scale
202 }
203 if prev_center != self.center || prev_scale != self.scale {
204 self.draw_frame();
205 }
206 // Draw metadata
207 self.draw_meta();
208 // Draw FPS
209 PLAYDATE.system.draw_fps(vec2![0, 0]);
210 }Sourcepub fn set_peripherals_enabled(&self, mask: Peripherals)
pub fn set_peripherals_enabled(&self, mask: Peripherals)
By default, the accelerometer is disabled to save (a small amount of) power. To use a peripheral, it must first be enabled via this function. Accelerometer data is not available until the next update cycle after it’s enabled.
Sourcepub fn get_accelerometer(&self) -> (f32, f32, f32)
pub fn get_accelerometer(&self) -> (f32, f32, f32)
Returns the last-read accelerometer data.
Sourcepub fn get_crank_angle(&self) -> f32
pub fn get_crank_angle(&self) -> f32
Returns the current position of the crank, in the range 0-360. Zero is pointing up, and the value increases as the crank moves clockwise, as viewed from the right side of the device.
Sourcepub fn get_crank_change(&self) -> f32
pub fn get_crank_change(&self) -> f32
Returns the angle change of the crank since the last time this function was called. Negative values are anti-clockwise.
Examples found in repository?
174 fn update(&mut self, _delta: f32) {
175 let button_state = PLAYDATE.system.get_button_state();
176 let prev_scale = self.scale;
177 let prev_center = self.center;
178 // Scale
179 if button_state.current.contains(Buttons::A) {
180 self.scale /= 1.1;
181 } else if button_state.current.contains(Buttons::B) {
182 self.scale *= 1.1
183 }
184 if !PLAYDATE.system.is_crank_docked() {
185 let crank = PLAYDATE.system.get_crank_change();
186 if crank > 0.0 {
187 self.scale /= 1.05;
188 } else if crank < 0.0 {
189 self.scale *= 1.05;
190 }
191 }
192 // Move
193 if button_state.current.contains(Buttons::Up) {
194 self.center.im += 10.0 * self.scale
195 } else if button_state.current.contains(Buttons::Down) {
196 self.center.im -= 10.0 * self.scale
197 }
198 if button_state.current.contains(Buttons::Left) {
199 self.center.re -= 10.0 * self.scale
200 } else if button_state.current.contains(Buttons::Right) {
201 self.center.re += 10.0 * self.scale
202 }
203 if prev_center != self.center || prev_scale != self.scale {
204 self.draw_frame();
205 }
206 // Draw metadata
207 self.draw_meta();
208 // Draw FPS
209 PLAYDATE.system.draw_fps(vec2![0, 0]);
210 }Sourcepub fn is_crank_docked(&self) -> bool
pub fn is_crank_docked(&self) -> bool
Returns 1 or 0 indicating whether or not the crank is folded into the unit.
Examples found in repository?
174 fn update(&mut self, _delta: f32) {
175 let button_state = PLAYDATE.system.get_button_state();
176 let prev_scale = self.scale;
177 let prev_center = self.center;
178 // Scale
179 if button_state.current.contains(Buttons::A) {
180 self.scale /= 1.1;
181 } else if button_state.current.contains(Buttons::B) {
182 self.scale *= 1.1
183 }
184 if !PLAYDATE.system.is_crank_docked() {
185 let crank = PLAYDATE.system.get_crank_change();
186 if crank > 0.0 {
187 self.scale /= 1.05;
188 } else if crank < 0.0 {
189 self.scale *= 1.05;
190 }
191 }
192 // Move
193 if button_state.current.contains(Buttons::Up) {
194 self.center.im += 10.0 * self.scale
195 } else if button_state.current.contains(Buttons::Down) {
196 self.center.im -= 10.0 * self.scale
197 }
198 if button_state.current.contains(Buttons::Left) {
199 self.center.re -= 10.0 * self.scale
200 } else if button_state.current.contains(Buttons::Right) {
201 self.center.re += 10.0 * self.scale
202 }
203 if prev_center != self.center || prev_scale != self.scale {
204 self.draw_frame();
205 }
206 // Draw metadata
207 self.draw_meta();
208 // Draw FPS
209 PLAYDATE.system.draw_fps(vec2![0, 0]);
210 }Sourcepub fn set_crank_sounds_disabled(&self, flag: bool) -> bool
pub fn set_crank_sounds_disabled(&self, flag: bool) -> bool
The function returns the previous value for this setting.
Sourcepub fn get_flipped(&self) -> bool
pub fn get_flipped(&self) -> bool
Returns 1 if the global “flipped” system setting is set, otherwise 0.
Sourcepub fn set_auto_lock_disabled(&self, disable: bool)
pub fn set_auto_lock_disabled(&self, disable: bool)
Disables or enables the 60 second auto lock feature. When called, the timer is reset to 60 seconds.
A game can optionally provide an image to be displayed alongside the system menu. bitmap must be a 400x240 LCDBitmap. All important content should be in the left half of the image in an area 200 pixels wide, as the menu will obscure the rest. The right side of the image will be visible briefly as the menu animates in and out.
Optionally, a non-zero xoffset, can be provided. This must be a number between 0 and 200 and will cause the menu image to animate to a position offset left by xoffset pixels as the menu is animated in.
This function could be called in response to the kEventPause event in your implementation of eventHandler().
title will be the title displayed by the menu item.
Adds a new menu item to the System Menu. When invoked by the user, this menu item will:
- Invoke your callback function.
- Hide the System Menu.
- Unpause your game and call eventHandler() with the kEventResume event.
Your game can then present an options interface to the player, or take other action, in whatever manner you choose.
Adds a new menu item that can be checked or unchecked by the player.
title will be the title displayed by the menu item.
value should be false for unchecked, true for checked.
If this menu item is interacted with while the system menu is open, callback will be called when the menu is closed.
Adds a new menu item that allows the player to cycle through a set of options.
title will be the title displayed by the menu item.
options should be an array of strings representing the states this menu item can cycle through. Due to limited horizontal space, the option strings and title should be kept short for this type of menu item.
optionsCount should be the number of items contained in options.
If this menu item is interacted with while the system menu is open, callback will be called when the menu is closed.
Sourcepub fn get_reduce_flashing(&self) -> bool
pub fn get_reduce_flashing(&self) -> bool
Returns 1 if the global “reduce flashing” system setting is set, otherwise 0.
Sourcepub fn get_elapsed_time(&self) -> f32
pub fn get_elapsed_time(&self) -> f32
Returns the number of seconds since playdate.resetElapsedTime() was called. The value is a floating-point number with microsecond accuracy.
Sourcepub fn reset_elapsed_time(&self)
pub fn reset_elapsed_time(&self)
Resets the high-resolution timer.
Sourcepub fn get_battery_percentage(&self) -> f32
pub fn get_battery_percentage(&self) -> f32
Returns a value from 0-100 denoting the current level of battery charge. 0 = empty; 100 = full.
Sourcepub fn get_battery_voltage(&self) -> f32
pub fn get_battery_voltage(&self) -> f32
Returns the battery’s current voltage level.
Sourcepub fn get_timezone_offset(&self) -> i32
pub fn get_timezone_offset(&self) -> i32
Returns the system timezone offset from GMT, in seconds.
Sourcepub fn should_display_24_hour_time(&self) -> bool
pub fn should_display_24_hour_time(&self) -> bool
Returns 1 if the user has set the 24-Hour Time preference in the Settings program.
Sourcepub fn convert_epoch_to_date_time(&self, epoch: u32) -> DateTime
pub fn convert_epoch_to_date_time(&self, epoch: u32) -> DateTime
Converts the given epoch time to a PDDateTime.
Sourcepub fn convert_date_time_to_epoch(&self, datetime: DateTime) -> u32
pub fn convert_date_time_to_epoch(&self, datetime: DateTime) -> u32
Converts the given PDDateTime to an epoch time.
Sourcepub fn clear_icache(&self)
pub fn clear_icache(&self)
Flush the CPU instruction cache, on the very unlikely chance you’re modifying instruction code on the fly. (If you don’t know what I’m talking about, you don’t need this. :smile:)