使用此函数,您可以创建一个自定义的、可点击的图标,作为游戏画布之外但在浏览器窗口内的“按钮”。 该函数将返回一个 ID 值,该值必须存储在一个变量中,以便在引用新可点击对象的所有其他按钮函数中使用。 此函数对于防止浏览器在点击按钮时创建弹出窗口非常有用,因为这一切都是通过 GameMaker 本身完成的。
您必须首先设置相对于浏览器窗口(左上角)的 (0,0) 的位置,然后为您希望按钮图标具有的精灵提供纹理页面条目(请参阅: sprite_get_tpe())。 然后,您可以指定要打开的 URL 或要打开或运行的脚本(来自 GameMaker 的资源浏览器)。 当您使用 open() 方法时,您指定的“目标”参数与标准 JavaScript“name”值相同(请注意,除“_self”之外的所有参数都可能导致浏览器阻塞,或询问 user 如果他们希望允许它)并且“params”参数与 JavaScript“specs”参数相同,用于控制新窗口/选项卡应显示的属性(并非所有浏览器都支持所有函数)。 如果您使用图标运行内部脚本,最后两个参数可以保留为空字符串“”。
有效的目标是:
| 目标 | 描述 |
|---|---|
| _blank | Opens the linked document in a new window or tab. |
| _self | Opens the linked document in the same frame as it was clicked (this is default). |
| _parent | Opens the linked document in the parent frame. |
| _top | Opens the linked document in the full body of the window. |
有效参数如下:
| 参数 | 描述 |
|---|---|
| 'height=[px]' | The height of the window, with the minimum value being 100. |
| 'width=[px]' | The width of the window, with the minimum value being 100. |
| 'left=[px]' | The left position of the window. |
| 'top=[px]' | The top position of the window (IE only). |
| 'location=[boolean]' | Whether or not to display the address field (default is 1). |
| 'menubar=[boolean]' | Whether or not to display the menu bar (default is 1). |
| 'resizable=[boolean]' | Whether or not the window is resizable (default is 1). |
| 'scrollbars=[boolean]' | Whether or not to display scroll bars (default is 1). |
| 'status=[boolean]' | Whether or not to add a status bar (default is 1). |
| 'titlebar=[boolean]' | Whether or not to display the title bar. This is ignored unless the calling application is an HTML Application or a trusted dialog box (default is 1); |
| 'toolbar=[boolean]' | Whether or not to display the browser toolbar (default is yes). |
同样值得注意的是,如果你传入的URL参数是一个脚本函数的名称(例如:它不是以“http://”开头),并且脚本名为gmcallback_*,那么你可以直接得到一个html5事件的提要。GameMaker 脚本函数名如果以gmcallback_开头,则不会进行混淆。
clickable_add(x, y, tpe, url, target, params);
| 参数 | 类型 | 描述 |
|---|---|---|
| x | Real | 窗口中的 x 位置。 |
| y | Real | 窗口中的 y 位置。 |
| tpe | Texture Page Entry | 要使用的精灵的纹理页面条目。 |
| url | String | 要链接到的URL(网站地址),或要运行的脚本。 |
| target | String | 这是打开URL的目标区域(参见描述)。 |
| params | String | 图标的各种参数(参见说明)。 |
home_but = clickable_add(32, 32, sprite_get_tpe(spr_MS_Home, 0), "http://macsweeney_games.com", "_blank", "width=700, height=500, menubar=0, toolbar=0, scrollbars=0");
上面的代码在游戏画布运行的页面(32,32)的位置创建了一个可点击的DOM图标。该图标使用从纹理页面引用的精灵“spr_MS_Home”,当单击该图标时,将为指定的URL和已定义的窗口属性打开一个新窗口。