1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| local api -- control the street object table, obtained through the sf_start event callback, and stored in module local variables. For details, please refer to (api interface.txt) -- Room and global games use the same client control API local quitFunc -- method used to save and exit the game local myselfUid -- used to save your own uid
--- Start game event callback -- @function sf_start -- @tab nativeapi controls the street object table local function sf_start(uid,nativeapi,qf) -- Usually save the required variables to the module myselfUid = uid api = nativeapi -- save API object table quitFunc = qf end
--- Network data response event callback -- @function sf_message -- @tab data Data table issued by the server local function sf_message(data)
end
--- Keyboard press event callback -- @function sf_keydown -- @int keycode keyboard response code, please refer to Constants.txt -- @boolean repeated Whether it is a repeated key. Generally, when the next key is pressed, it is a new key. If you don't let go, it will always respond to keydown. At this time, repeated is true, indicating that it is a repeated key. local function sf_keydown(keycode,repeated) if keycode==api.Constants.K_F12 then quitFunc() -- Exit the game end end
--- Keyboard lift callback -- @function sf_keyup -- @int keycode keyboard response code, please refer to Constants.txt local sf_keyup = function(keycode)
end
--- Touch response event callback, can only be used on Android platform, ios platform and web platform -- @function sf_touch -- @int touchtype gesture type, please refer to Constants -- @int x x coordinate -- @int y y coordinate, the coordinate returns the design logical size, please refer to the logical coordinates dwidth and dheight in the drawing interface -- @int fingers The number of fingers for this gesture is usually 1 to 3 fingers. Hardware support is required for multiple fingers. Some mobile phone touch screens support 10 fingers, usually up to four fingers. -- @int gid The mode number of this touch, 100-digit full-screen touch number, 200-digit upper half screen number in split-screen touch, 300-digit lower half screen touch number in split-screen mode local function sf_touch(touchtype, x, y,fingers,gid)
end
--- Called every frame, used for constant game updates, 60 frames per second -- @function update -- @number ds The time difference between two update calls, in seconds, accurate to 3 decimal places local function sf_update(ds)
end
--- Game controller responsiveness, including gamepads -- @function sf_gamecontroller -- @tab msg Data response structure table -- @int msg.which indicates which controller or handle sent the message, which is equivalent to the handle ID, starting from 0. Generally, the computer supports 8 handles. -- @int msg.timestamp The timestamp when the message was sent -- @int msg.type Controller response code, for details, please refer to the always-on table on api.Constants. There are currently three messages, axis change messages, button press messages, and button lift messages. -- @int msg.button When msg.type is when the button is pressed or raised, it indicates the number of the button. For details, please refer to: The always-on table on api.Constants -- @int msg.axis When the current type is an axis message, it indicates which axis sends the change message. For example, if the left joystick x changes horizontally, the axis is 0, and if the right joystick changes up and down, the axis is 3. -- @int msg.value represents the current status of the axis change, ranging from -32768 to 32767. When the joystick is at the dot, it is 0. Otherwise, the symbol is the same as the axis direction where it is located. local function sf_gamecontroller(msg)
end
--- Mouse response event -- @function sf_mouse -- @tab msg Data response structure table -- @int msg.type Mouse event type, for details, refer to the always-on table client -- @int msg.button mouse case type, for details, please refer to the always-on table client -- @int msg.x msg.y mouse logical coordinates local function sf_mouse(msg)
end
--Export interface methods return { start=sf_start, message=sf_message, keydown=sf_keydown, keyup=sf_keyup, -- optional touch=sf_touch, update=sf_update, gamecontroller=sf_gamecontroller, mouse=sf_mouse, }
|