kaplay
kaplay copied to clipboard
feat: shake() function for sprites
there is camera shake however, i think a sprite shake would be useful aswell
a shake function for the (sprite component? really anything that can be drawn)
you would use the function with an intensity parameter, and an optional duration parameter, and the sprite would then shake back and forth without changing the transform of the area
giving all other objects a fixed() component and then doing camShake()
I'm not sure if the duration parameter would be necessary.
this is a cool idea, could make it like only shake X axis or Y or both, about the duration it could use the same parameters as the improved shake i suggested
something like this?
/**
* Shakes an object
* @param initialPos The position it initially was at
* @param time How long will it shake for
* @param strength The strength of the shake (how much it will move in pixels)
* @param interval How long between each shake
*/
shakePanic(initialPos: Vec2, time?: number, strength?: number, interval?: number) : shakePanicReturnType {
time = time ?? 1
strength = strength ?? 10
interval = interval ?? 0.05
let shakeLoop = this.loop(interval, () => {
const newPos = initialPos.add(rand(-strength, strength), rand(-strength, strength))
this.pos = newPos
})
function cancelFunction() {
shakeLoop.cancel()
this.pos = initialPos
}
this.wait(time, cancelFunction)
return {
cancel: cancelFunction
}
}
Best to make it a component, so it works for any object with pos, not just sprites. Camera will become an object in 4000.
yeah it's actually part of a component im writing for juice functions