对于运行代码的实例,此函数将使用指定的参数在指定的事件中执行代码。这里有许多选项,允许完全模拟所有可能的事件,但请注意,这实际上只是执行事件中的所有代码;游戏不会修改任何内容以使其手动触发。
例如,如果您选择执行键盘按下事件 ev_keypress,该事件将被触发,但相关键不会被识别为已被按下。或者,如果您执行计时器事件 ev_alarm,则计时器计数不会设置为 -1,而是继续倒计时。
注意 可以使用event_perform_async调用异步事件。
下表概述了 GameMaker 中包含的用于引用事件 类型 的所有常量及其 编号 值。事件本身以 粗体文本 标记,并且与 event_type 变量的返回值相同 (将传递到此函数的第一个参数中),而它们的数值则标记为 斜体文本 ,并且与 event_number 变量的返回值 (将传递到此函数的第二个参数中) 相同:
事件类型常量 & 事件数字常量 | |
---|---|
常量 | 描述 |
ev_create | Create event |
ev_destroy | Destroy event |
ev_cleanup | Clean Up Event |
ev_step | Step event |
---- ev_step_normal | Step |
---- ev_step_begin | Begin Step |
---- ev_step_end | End Step |
ev_alarm | Alarm event |
---- 0 ... 11 | The number relevant to which of the 12 alarms you wish to trigger the event of |
ev_keyboard, ev_keypress, ev_keyrelease | Keyboard/Keyboard Pressed/Keyboard Released |
---- any key code | vk_space or ord("W") for example. |
ev_mouse | Mouse event |
---- ev_left_button | Left button held down on object |
---- ev_right_button | Right button held down on object |
---- ev_middle_button | Middle button (or clickable wheel) held down on object |
---- ev_no_button | No buttons held down |
---- ev_left_press | Left button just pressed on object |
---- ev_right_press | Right button just pressed on object |
---- ev_middle_press | Middle button (or clickable wheel) just pressed on object |
---- ev_left_release | Left button just released on object |
---- ev_right_release | Right button just released on object |
---- ev_middle_release | Middle button just released on object |
---- ev_mouse_enter | Mouse just entered object's bounding box |
---- ev_mouse_leave | Mouse just left object's bounding box |
---- ev_mouse_wheel_up | Mouse wheel scrolled upwards |
---- ev_mouse_wheel_down | Mouse wheel scrolled downwards |
---- ev_global_left_button | Left button held down anywhere |
---- ev_global_right_button | Right button held down anywhere |
---- ev_global_middle_button | Middle button (or clickable wheel) held down anywhere |
---- ev_global_left_press | Left button just pressed anywhere |
---- ev_global_right_press | Right button just pressed anywhere |
---- ev_global_middle_press | Middle button (or clickable wheel) just pressed anywhere |
---- ev_global_left_release | Left button just released anywhere |
---- ev_global_right_release | Right button just released anywhere |
---- ev_global_middle_release | Middle button just released anywhere |
ev_gesture | A gesture event (Tap, Drag, Flick, Pinch or Rotate) |
---- ev_gesture_tap | A single click/touch and release has been detected for an instance |
---- ev_gesture_double_tap | Two quick touches/clicks and releases have been detected for an instance |
---- ev_gesture_drag_start | The beginning of a drag gesture has been detected for an instance |
---- ev_gesture_dragging | A touch/click has been held and moved for an instance |
---- ev_gesture_drag_end | The release of the touch/click from a drag has been detected for an instance |
---- ev_gesture_flick | The release of a touch/click from a drag had enough movement for a flick event to be detected for the instance |
---- ev_gesture_pinch_start | Two touches and a straight movement have been detected for an instance |
---- ev_gesture_pinch_in | The movement between two touches for an instance has been detected as inwards |
---- ev_gesture_pinch_out | The movement between two touches for an instance has been detected as outwards |
---- ev_gesture_pinch_end | The release of one (or both) touches for a pinch has been detected for an instance |
---- ev_gesture_rotate_start | The movement between two touches for an instance has been detected as a rotation |
---- ev_gesture_rotating | The movement between two touches for an instance has been detected as rotating |
---- ev_gesture_rotate_end | The release of one (or both) touches for a rotation has been detected for an instance |
---- ev_global_gesture_tap | A single click/touch and release has been detected anywhere in the room |
---- ev_global_gesture_double_tap | Two quick touches/clicks and releases have been detected anywhere in the room |
---- ev_global_gesture_drag_start | The beginning of a drag gesture has been detected anywhere in the room |
---- ev_global_gesture_dragging | A touch/click has been held and moved anywhere in the room |
---- ev_global_gesture_drag_end | The release of the touch/click from a drag has been detected anywhere in the room |
---- ev_global_gesture_flick | The release of a touch/click from a drag had enough movement for a flick event to be detected anywhere in the room |
---- ev_global_gesture_pinch_start | Two touches and a straight movement have been detected anywhere in the room |
---- ev_global_gesture_pinch_in | The movement between two touches anywhere in the room has been detected as inwards |
---- ev_global_gesture_pinch_out | The movement between two touches anywhere in the room has been detected as outwards |
---- ev_global_gesture_pinch_end | The release of one (or both) touches for a pinch has been detected anywhere in the room |
---- ev_global_gesture_rotate_start | The movement between two touches anywhere in the room has been detected as a rotation |
---- ev_global_gesture_rotating | The movement between two touches anywhere in the room has been detected as rotating |
---- ev_global_gesture_rotate_end | The release of one (or both) touches for a rotation has been detected anywhere in the room |
ev_collision | Collision with an object |
---- The index of the object to check. | obj_enemy for example. |
ev_other | One of the actions listed under 'Other' |
---- ev_outside | Whether the instance is outside of the room |
---- ev_boundary | Whether the instance is intersecting the boundary |
---- ev_outside_view0...7 | Whether the instance is outside the given view (0 to 7) |
---- ev_boundary_view0...7 | Whether the instance is interesecting with the boundary of the given view (0 to 7) |
---- ev_game_start | Only triggered at the start of the game |
---- ev_game_end | Only triggered at the end of the game |
---- ev_room_start | Only triggered at the start of a room |
---- ev_room_end | Only triggered at the end of a room |
---- ev_animation_end | If the object's sprite has reached the end of its animation |
---- ev_animation_update | Animation event that runs every step for objects that use skeletal animations |
---- ev_animation_event | Animation event that runs for skeletal animations as assigned in the skeletal animation tool |
---- ev_end_of_path | If the object has reached the end of a path it is following |
---- ev_user0... ev_user15 | One of the 16 available user events. |
---- ev_broadcast_message | Broadcast Message event used for sprites and sequences |
ev_draw | Draw event. NOTE This event cannot be forced outside of a draw event and the constants are only for identifying the event when performed in these cases. |
---- ev_draw_normal | The normal draw event. |
---- ev_draw_begin | The draw begin event. |
---- ev_draw_end | The draw end event. |
---- ev_draw_pre | The pre draw event. |
---- ev_draw_post | The post draw event. |
---- ev_gui | The draw gui event. |
---- ev_gui_begin | The draw gui begin event. |
---- ev_gui_end | The draw gui end event. |
event_perform(type, numb);
参数 | 类型 | 描述 |
---|---|---|
type | 事件类型常量 | 要执行的事件类型(请参见上表)。 |
numb | Real or 事件数字常量 | 特定的事件常量或值。无论事件是否有子事件,其默认事件总是由事件编号 0 引用 (例如,创建事件只有一个事件编号为 0 的子事件,正常的步骤和绘制事件可以通过其常量 (分别为 ev_step_normal 和 ev_draw_normal) 或 事件编号 0 引用) |
N/A
event_perform(ev_keypress, ord("W"));
这将执行与按下 "W" 键的键盘检查相关联的事件 (而不实际生成键盘按下)。
event_perform(ev_step, ev_step_begin);
这将执行步开始事件(如果从任何步骤事件调用,它将导致步开始事件代码运行两次)。
event_perform(ev_create, 0);
这将执行该实例的创建事件。