event_perform

对于运行代码的实例,此函数将使用指定的参数在指定的事件中执行代码。这里有许多选项,允许完全模拟所有可能的事件,但请注意,这实际上只是执行事件中的所有代码;游戏不会修改任何内容以使其手动触发。

例如,如果您选择执行键盘按下事件 ev_keypress,该事件将被触发,但相关键不会被识别为已被按下。或者,如果您执行计时器事件 ev_alarm,则计时器计数不会设置为 -1,而是继续倒计时。

注意 可以使用event_perform_async调用异步事件。

下表概述了 GameMaker 中包含的用于引用事件 类型 的所有常量及其 编号 值。事件本身以 粗体文本 标记,并且与 event_type 变量的返回值相同 (将传递到此函数的第一个参数中),而它们的数值则标记为 斜体文本 ,并且与 event_number 变量的返回值 (将传递到此函数的第二个参数中) 相同:

事件类型常量 & 事件数字常量
常量描述
ev_createCreate event
ev_destroyDestroy event
ev_cleanupClean Up Event
ev_stepStep event
   ---- ev_step_normalStep
   ---- ev_step_beginBegin Step
   ---- ev_step_endEnd Step
ev_alarmAlarm event
   ---- 0 ... 11The number relevant to which of the 12 alarms you wish to trigger the event of
ev_keyboard, ev_keypress, ev_keyreleaseKeyboard/Keyboard Pressed/Keyboard Released
   ---- any key codevk_space or ord("W") for example.
ev_mouseMouse event
   ---- ev_left_buttonLeft button held down on object
   ---- ev_right_buttonRight button held down on object
   ---- ev_middle_buttonMiddle button (or clickable wheel) held down on object
   ---- ev_no_buttonNo buttons held down
   ---- ev_left_pressLeft button just pressed on object
   ---- ev_right_pressRight button just pressed on object
   ---- ev_middle_pressMiddle button (or clickable wheel) just pressed on object
   ---- ev_left_releaseLeft button just released on object
   ---- ev_right_releaseRight button just released on object
   ---- ev_middle_releaseMiddle button just released on object
   ---- ev_mouse_enterMouse just entered object's bounding box
   ---- ev_mouse_leaveMouse just left object's bounding box
   ---- ev_mouse_wheel_upMouse wheel scrolled upwards
   ---- ev_mouse_wheel_downMouse wheel scrolled downwards
   ---- ev_global_left_buttonLeft button held down anywhere
   ---- ev_global_right_buttonRight button held down anywhere
   ---- ev_global_middle_buttonMiddle button (or clickable wheel) held down anywhere
   ---- ev_global_left_pressLeft button just pressed anywhere
   ---- ev_global_right_pressRight button just pressed anywhere
   ---- ev_global_middle_pressMiddle button (or clickable wheel) just pressed anywhere
   ---- ev_global_left_releaseLeft button just released anywhere
   ---- ev_global_right_releaseRight button just released anywhere
   ---- ev_global_middle_releaseMiddle button just released anywhere
ev_gestureA gesture event (Tap, Drag, Flick, Pinch or Rotate)
   ---- ev_gesture_tapA single click/touch and release has been detected for an instance
   ---- ev_gesture_double_tapTwo quick touches/clicks and releases have been detected for an instance
   ---- ev_gesture_drag_startThe beginning of a drag gesture has been detected for an instance
   ---- ev_gesture_draggingA touch/click has been held and moved for an instance
   ---- ev_gesture_drag_endThe release of the touch/click from a drag has been detected for an instance
   ---- ev_gesture_flickThe release of a touch/click from a drag had enough movement for a flick event to be detected for the instance
   ---- ev_gesture_pinch_startTwo touches and a straight movement have been detected for an instance
   ---- ev_gesture_pinch_inThe movement between two touches for an instance has been detected as inwards
   ---- ev_gesture_pinch_outThe movement between two touches for an instance has been detected as outwards
   ---- ev_gesture_pinch_endThe release of one (or both) touches for a pinch has been detected for an instance
   ---- ev_gesture_rotate_startThe movement between two touches for an instance has been detected as a rotation
   ---- ev_gesture_rotatingThe movement between two touches for an instance has been detected as rotating
   ---- ev_gesture_rotate_endThe release of one (or both) touches for a rotation has been detected for an instance
   ---- ev_global_gesture_tapA single click/touch and release has been detected anywhere in the room
   ---- ev_global_gesture_double_tapTwo quick touches/clicks and releases have been detected anywhere in the room
   ---- ev_global_gesture_drag_startThe beginning of a drag gesture has been detected anywhere in the room
   ---- ev_global_gesture_draggingA touch/click has been held and moved anywhere in the room
   ---- ev_global_gesture_drag_endThe release of the touch/click from a drag has been detected anywhere in the room
   ---- ev_global_gesture_flickThe 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_startTwo touches and a straight movement have been detected anywhere in the room
   ---- ev_global_gesture_pinch_inThe movement between two touches anywhere in the room has been detected as inwards
   ---- ev_global_gesture_pinch_outThe movement between two touches anywhere in the room has been detected as outwards
   ---- ev_global_gesture_pinch_endThe release of one (or both) touches for a pinch has been detected anywhere in the room
   ---- ev_global_gesture_rotate_startThe movement between two touches anywhere in the room has been detected as a rotation
   ---- ev_global_gesture_rotatingThe movement between two touches anywhere in the room has been detected as rotating
   ---- ev_global_gesture_rotate_endThe release of one (or both) touches for a rotation has been detected anywhere in the room
ev_collisionCollision with an object
   ---- The index of the object to check.obj_enemy for example.
ev_otherOne of the actions listed under 'Other'
   ---- ev_outsideWhether the instance is outside of the room
   ---- ev_boundaryWhether the instance is intersecting the boundary
   ---- ev_outside_view0...7Whether the instance is outside the given view (0 to 7)
   ---- ev_boundary_view0...7Whether the instance is interesecting with the boundary of the given view (0 to 7)
   ---- ev_game_startOnly triggered at the start of the game
   ---- ev_game_endOnly triggered at the end of the game
   ---- ev_room_startOnly triggered at the start of a room
   ---- ev_room_endOnly triggered at the end of a room
   ---- ev_animation_endIf the object's sprite has reached the end of its animation
   ---- ev_animation_updateAnimation event that runs every step for objects that use skeletal animations
   ---- ev_animation_eventAnimation event that runs for skeletal animations as assigned in the skeletal animation tool
   ---- ev_end_of_pathIf the object has reached the end of a path it is following
   ---- ev_user0... ev_user15One of the 16 available user events.
   ---- ev_broadcast_messageBroadcast Message event used for sprites and sequences
ev_drawDraw 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_normalThe normal draw event.
   ---- ev_draw_beginThe draw begin event.
   ---- ev_draw_endThe draw end event.
   ---- ev_draw_preThe pre draw event.
   ---- ev_draw_postThe post draw event.
   ---- ev_guiThe draw gui event.
   ---- ev_gui_beginThe draw gui begin event.
   ---- ev_gui_endThe draw gui end event.

 

语法:

event_perform(type, numb);

参数类型描述
type事件类型常量要执行的事件类型(请参见上表)。
numbReal or 事件数字常量特定的事件常量或值。无论事件是否有子事件,其默认事件总是由事件编号 0 引用 (例如,创建事件只有一个事件编号为 0 的子事件,正常的步骤和绘制事件可以通过其常量 (分别为 ev_step_normalev_draw_normal) 事件编号 0 引用)

 

返回:

N/A

 

拓展示例

event_perform(ev_keypress, ord("W"));

这将执行与按下 "W" 键的键盘检查相关联的事件 (而不实际生成键盘按下)。

event_perform(ev_step, ev_step_begin);

这将执行步开始事件(如果从任何步骤事件调用,它将导致步开始事件代码运行两次)。

event_perform(ev_create, 0);

这将执行该实例的创建事件。