Skip to main content

action_pressed

Function action_pressed 

Source
pub fn action_pressed(action: Action) -> bool
Expand description

Returns true when the action’s bound button goes from “not pressed” to “pressed”. Otherwise returns false.

Returns false if the action is not bound to any button.

Examples found in repository?
examples/space_game.rs (line 254)
232    fn update_input(&mut self) {
233        if action_held(UP) {
234            self.speed += PLAYER_ACCEL;
235            self.emit_movement_particles();
236
237            if once_per_n_seconds(0.1) {
238                play_sound_ex(get_sounds().engine).volume(0.1).start();
239            }
240        }
241
242        if action_held(DOWN) {
243            self.speed -= PLAYER_ACCEL;
244        }
245
246        if action_held(RIGHT) {
247            self.angvel -= PLAYER_TURN_SPEED;
248        }
249
250        if action_held(LEFT) {
251            self.angvel += PLAYER_TURN_SPEED;
252        }
253
254        if action_pressed(SHOOT) {
255            play_sound(get_sounds().shoot);
256            let tip = self.pos + vec2(0.0, PLAYER_SIZE).rotated_around_origin(-self.rotation);
257            self.bullets
258                .push(Bullet::new(tip, self.rotation, self.vel()));
259        }
260    }