Movatterモバイル変換


[0]ホーム

URL:


LoveJS Player

LoveJS Player

LoveJS Player

Yet another lovejs player. This player is based onLove 11.5 andEmscription 3.1.68. It outputs a single html file that contains the engine and game you pass in.

Parameters

You can parameterize the output file by providinglovejs.json in the top level of your .love file

You can customize theHEIGHT andWIDTH of the default html shell using the appropriate tags, or you can provide your own custom html shell.

Note that if you are passing in your own html shell or style sheet those files should be present in your .love file and their paths should be provided bySTYLE_FILE andHTML_FILE.

Currently onlylove115-compat-beta1 is the only available version of love.

Recommendations on further customizable parameters are welcome.

{"TITLE":"Your Game","WIDTH":1280,"HEIGHT":720,"VERSION":"love115-compat-beta1","STYLE_FILE":"/path/to/style.css","HTML_FILE":"/path/to/index.html"}

Extensions

This bundler extends Love2D to accept incoming signals from the JS environment.

JS: love_send_event

Sending Signals from JS to Lua

love_send_event(key-string,value-string, value-number) => nil

To create an event"key" with arguments"value" and10 call the following from javascript.

Note the types are fixed, the first two variables must be strings and the last must be a number. This is a limitation of the SDL_UserEvent struct. This may be ameliorated in the future by replacing the event integration with polling.

LoveState['love_send_event']("key","value",10)

On the love2d side you can catch this event using an event handler

functionlove.handlers.key(value,code)print(value)print(code)end

Lua: js.call

Calling JS from Lua, no returns

js.call(js-string) => nil

You can usejs.call to execute a js string. No return value is provided. Coupling this withlove_send_event lets you create asynchronous callbacks into the js environment.

Be careful, there are no checks on the string being executed. Errors may crash your game.

-- js is preloaded so it can be required anywherelocaljs=require("js")js.call("console.log(\"hello\");")

Lua: js.send-event

Send event to canvas in JS environment

js["send-event"](event-name-string) => nil

js["send-event"] sends an event that can be picked up by event listeners attached to the canvas element. No return value is provided. Coupling this withlove_send_event lets you create asynchronous callbacks into the js environment.

-- js is preloaded so it can be required anywherelocaljs=require("js")js["send-event"]("game-start")
functiongameStartEvent(_e){console.log("Game Start!");}LoveState["canvas"].addEventListener("game-start",gameStartEvent);

Lua: js.send-custom-json-event

Send event to canvas in JS environment with a custom json object

js["send-custom-json-event"](event-name-string, json-string) => nil

js["send-custom-json-event"] sends an event that can be picked up by event listeners attached to the canvas element. A custom json object will be available under the eventsdetail key. No return value is provided. Coupling this withlove_send_event lets you create asynchronous callbacks into the js environment. You must format the outgoingjson-string as json or there will be an error in the JS environment.

-- js is preloaded so it can be required anywherelocaljs=require("js")-- load your own json librarylocaljson=require("lib.json")localmessage={}message["name"]="Test Name"js["send-custom-json-event"]("game-start",json.encode(message))
functiongameStartEvent(e){console.log(e.detail.name);}LoveState["canvas"].addEventListener("game-start",gameStartEvent);

Lua: websocket.supported

Check if websockets are supported

websocket.supported() => bool


Lua: websocket.new

Open a new websocket

websocket.new(handle-string, address-string) => WS


Lua: websocket.deinitialize

websocket.deinitalize() => nil


Lua: WS.send_utf8_text

Send a string over the websocket

WS:send_utf8_text(utf8text-string) => nil


Lua: WS.send_close

Send close event over the websocket

WS:send_close(code-number,reason-string) => nil


Lua: WS.delete

Delete websocket

WS:delete() => nil


Lua: WS.get_protocol

Get the websocket protocol

WS:get_protocol() => string


Lua: WS.get_url

Get websocket connected URL

WS:get_url() => string


Lua: WS.get_extensions

Get websocket extensions

WS:get_extensions() => string


Lua: WS.get_ready_state

Get websocket ready state

WS:get_ready_state() => number


Websocket Events

Receiving signals via websockets

WS:get_ready_state() => number

Incoming websocket events are passed into Love2D via the event system.

There are four events passed in,websocketmessage,websocketopen,websocketerror, andwebsocketclose. Each event passes in a message (string) and a code (number). Write your own handlers to handle these incoming events.

Thehandle string passed towebsockets.new will prepend the name of the four events generated by the websocket system.

-- websocket is preloaded so may be required anywherelocalwebsocket=require("websocket")-- create a new websocket with handle "myhandle-" connected-- to the your localhost port 9000localWS=websocket.new("myhandle-","ws://localhost:9000")love["handlers"]["myhandle-websocketopen"]=function(message)print(message)-- message for websocketopen should always be an empty stringWS.send_utf8_text("connected!!")endlove["handlers"]["myhandle-websocketmessage"]=function(message)print(message)-- incoming message from serverendlove["handlers"]["myhandle-websocketclose"]=function(message)print(message)-- json formatted message to be parsedendlove["handlers"]["myhandle-websocketerror"]=function(message)print(message)-- message from websocketerror is an empty string.end

StatusIn development
CategoryTool
PlatformsHTML5
Rating
Rated 4.7 out of 5 stars
(3 total ratings)
AuthorAlex ☕🇨🇦
Made withLÖVE
Tagshtml5,LÖVE,software
Code licenseMIT License
Asset licenseCreative Commons Attribution_ShareAlike v4.0 International
LinksSource code
itch.io·View all by Alex ☕🇨🇦·Report·Embed
ToolsFree

[8]ページ先頭

©2009-2025 Movatter.jp