From what I understand, this piece of code makes the bird face upwards (around 22.5 degrees) and fall down looking 90 degrees at the floor.
However, I want to delay this slightly so the bird looks upwards for slightly longer, and then faces downwards. I have tried using the timeout function, but after the period of time I set, the bird freezes and can no longer jump.
Any help with this problem is appreciated, thank you
The dt variable and update function is the standard way and I’ve used it a lot. However, someone recently posted the following chunk of code that I think he called a “null tween” - null, because no entity is actually tweened. It is just a sneaky way to get access to the time delay function built into tween.js.
It requires that you have the tween.js library loaded, so it may not be a good approach if you don’t want to do that. It is a good idea to get familiar with the update function, but I’ve found this simple chunk of code to be very handy for when I just want something delayed in a simple way. The “1” is the amount of delay in seconds.
this.app.tween({}).to({}, 1, pc.Linear)
.on('complete', function() {
// do whatever here
}, this).start();
This did not work for my case when I tried, it didn’t really do anything. @wturber’s response did help but I need to know how to restart it for every click.
I’m very far from being an expert coder, but my experience is that the “null tween” timer ends and will restart when called again. Note that “do whatever here” follows the .on(‘complete’). That is because the tween has completed. Calling it again should restart it. Though I can imagine possible complications if you call it again before it has had time to complete the first time.
@_Lio3LivioN, @wturber suggestion seems great, but if you are trying to execute that code in your Flappy bird project that you posted in the other topic I think it will fail.
That project uses an older version of the tween library. Try experimenting in an empty project first by attaching the latest tween library, to check how the code should behave.