Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shake() function for sprites #281

Open
candycarmel opened this issue Jul 26, 2024 · 4 comments
Open

feat: shake() function for sprites #281

candycarmel opened this issue Jul 26, 2024 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@candycarmel
Copy link

candycarmel commented Jul 26, 2024

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.

@amyspark-ng
Copy link
Contributor

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

@lajbel lajbel added the enhancement New feature or request label Aug 22, 2024
@lajbel lajbel added this to the 3001 milestone Aug 22, 2024
@lajbel lajbel modified the milestones: 3001, 4000 Sep 3, 2024
@amyspark-ng
Copy link
Contributor

amyspark-ng commented Sep 24, 2024

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
	}
}

@mflerackers
Copy link
Member

Best to make it a component, so it works for any object with pos, not just sprites. Camera will become an object in 4000.

@amyspark-ng
Copy link
Contributor

yeah it's actually part of a component im writing for juice functions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: TODO
Development

No branches or pull requests

4 participants