Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
This library is like setTimeout
and setInterval
controlled by updates from a game loop.
This way, if you want to something to happen in your game after 60 updates, you just have to write:
await delay(60)
transitionToNextScreen()
In order for this to work, you need to call update
on every update. If you are using PixiJS this would mean that somewhere in your code you have to write:
ticker.add(update)
delay(duration, options)
- Wait a set duration of game updatesawait delay(60)
// Do something once after 60 game updates
forever(callback, interval, options)
- Call a function forever
, each interval game updateconst interval = 60
forever(() => {
// Do something forever each 60 game updates
}, interval)
every(callback, duration, options)
- Call a function every
update until duration is reachedconst duration = 60
await l1.every(() => {
// Do something every game update until 60 game updates have passed
}, duration)
update(deltaTime)
- Needs to be called on every game updategetAll()
- Get all behaviors
get(id)
- Get one behavior by id
getByLabel(label)
- Get a list of behaviors with a label
cancel(behavior)
- Takes an id
or behavior
object. Marks the behavior for cancellation. Will be cancelled after all behaviors have been processed in the current game update.
Start by calling createInstance
.
const { update, delay } = createInstance()
// Call update every game update
ticker.add(update)
await delay(60)
npm install l1
TODO: Better examples
import * as l1 from 'l1'
import * as PIXI from 'pixi.js'
const app = new PIXI.Application()
document.body.appendChild(app.view)
app.ticker.add(l1.update)
app.loader.load(() => {
const square = new PIXI.Sprite(texture)
app.stage.addChild(square)
// Move 1 pixel every 3 ticks
const move = l1.repeat(
() => {
square.x += 1
if (square.x > 500) {
l1.cancel('move')
}
},
3,
{ id: 'move' },
)
})
cancel
just marks the behavior for cancellation, but it won't actually be cancelled until the next update
Therefore, you might need to wait a game update before you continue:
const gameOver = () => {
cancel('gameLoop')
// Ensures that the game doesn't continue until the `gameLoop` behavior has been deleted
await delay(1)
// Continue
}
update
durationUse performance.now
import * as l1 from 'l1'
app.ticker.add((deltaTime) => {
const before = performance.now()
l1.update(deltaTime)
const after = performance.now()
const delta = after - before
})
Wrap l1.update
with a try catch
import * as l1 from 'l1'
app.ticker.add((deltaTime) => {
try {
l1.update(deltaTime)
} catch (error) {
console.error(error)
logToExternalService(error)
}
})
Use a for..of
loop
for (const item of list) {
doStuff(item)
await delay(50)
}
FAQs
Delayed and repeated code execution for games
We found that l1 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.