- Godot Engine Game Development Projects
- Chris Bradfield
- 316字
- 2021-06-18 18:51:31
What is a tween?
A tween is a way to interpolate (change gradually) some value over time (from a start value to an end value) using a particular function. For example, you might choose a function that steadily changes the value or one that starts slow but ramps up in speed. Tweening is also sometimes referred to as easing.
When using a Tween node in Godot, you can assign it to alter one or more properties of a node. In this case, you're going to increase the Scale of the coin and also cause it to fade out using the Modulate property.
Add this line to the _ready() function of Coin:
$Tween.interpolate_property($AnimatedSprite, 'scale',
$AnimatedSprite.scale,
$AnimatedSprite.scale * 3, 0.3,
Tween.TRANS_QUAD,
Tween.EASE_IN_OUT)
The interpolate_property() function causes the Tween to change a node's property. There are seven parameters:
- The node to affect
- The property to alter
- The property's starting value
- The property's ending value
- The duration (in seconds)
- The function to use
- The direction
The tween should start playing when the player picks up the coin. Replace queue_free() in the pickup() function:
func pickup():
monitoring = false
$Tween.start()
Setting monitoring to false ensures that the area_enter() signal won't be emitted if the player touches the coin during the tween animation.
Finally, the coin should be deleted when the animation finishes, so connect the Tween node's tween_completed() signal:
func _on_Tween_tween_completed(object, key):
queue_free()
Now, when you run the game, you should see the coins growing larger when they're picked up. This is good, but tweens are even more effective when applied to multiple properties at once. You can add another interpolate_property(), this time to change the sprite's opacity. This is done by altering the modulate property, which is a Color object, and changing its alpha channel from 1 (opaque) to 0 (transparent). Refer to the following code:
$Tween.interpolate_property($AnimatedSprite, 'modulate',
Color(1, 1, 1, 1),
Color(1, 1, 1, 0), 0.3,
Tween.TRANS_QUAD,
Tween.EASE_IN_OUT)
- Photoshop CS4經(jīng)典380例
- 反饋系統(tǒng):多學(xué)科視角(原書第2版)
- PostgreSQL Administration Essentials
- 高維聚類知識發(fā)現(xiàn)關(guān)鍵技術(shù)研究及應(yīng)用
- Ruby on Rails敏捷開發(fā)最佳實踐
- 網(wǎng)絡(luò)布線與小型局域網(wǎng)搭建
- 突破,Objective-C開發(fā)速學(xué)手冊
- Hadoop應(yīng)用開發(fā)基礎(chǔ)
- 精通數(shù)據(jù)科學(xué):從線性回歸到深度學(xué)習(xí)
- 自動化生產(chǎn)線安裝與調(diào)試(三菱FX系列)(第二版)
- 生成對抗網(wǎng)絡(luò)項目實戰(zhàn)
- 單片機(jī)C51應(yīng)用技術(shù)
- x86/x64體系探索及編程
- Eclipse全程指南
- Flash CS3動畫制作