Skip to content

Instantly share code, notes, and snippets.

@philipshen
Last active June 19, 2018 13:06
Show Gist options
  • Save philipshen/82ac3e849b580edbc7a71966db5a107a to your computer and use it in GitHub Desktop.
Save philipshen/82ac3e849b580edbc7a71966db5a107a to your computer and use it in GitHub Desktop.
// FACTORY
createBullet(position: cc.Vec2, velocity: number, angle: number) {
const newBullet = cc.instantiate(this.bullet) // 1
newBullet.setPosition(position) // 2
newBullet.rotation = angle
const body = newBullet.getComponent(cc.RigidBody) // 3
body.linearVelocity = cc.v2(MathUtilities.sind(angle) * velocity,
MathUtilities.cosd(angle) * velocity)
this.node.addChild(newBullet) // 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment