Created
October 12, 2017 17:26
-
-
Save noidexe/0820cb1737048f4c59b9f32b706330a8 to your computer and use it in GitHub Desktop.
Godot sample script: GDScript vs C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Godot; | |
using System; | |
public class SharpBird : Node2D | |
{ | |
// Member variables here, example: | |
// private int a = 2; | |
// private string b = "textvar"; | |
private double direction; | |
Random r = new Random(); | |
public override void _Ready() | |
{ | |
// Called every time the node is added to the scene. | |
// Initialization here | |
AnimatedSprite sprite = GetNode("sprite") as AnimatedSprite; | |
//Red tint to distinguish it from the GDScript one | |
sprite.SetModulate(new Color(1.0f, 0.0f, 0.0f)); | |
sprite.Play("idle"); | |
direction = (r.NextDouble()*10)-5.0; | |
} | |
public override void _Process(float delta) | |
{ | |
Vector2 newPos = GetPosition(); | |
newPos.x += (float)direction; | |
SetPosition(newPos); | |
} | |
async void _on_Area2D_area_entered( Area2D area) | |
{ | |
AnimatedSprite sprite = GetNode("sprite") as AnimatedSprite; | |
sprite.Play("die"); | |
await ToSignal(sprite, "animation_finished"); | |
QueueFree(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extends Node2D | |
# class member variables go here, for example: | |
# var a = 2 | |
# var b = "textvar" | |
var direction | |
func _ready(): | |
randomize() | |
# Called every time the node is added to the scene. | |
# Initialization here | |
get_node("sprite").play("idle") | |
direction = rand_range(-5,5) | |
pass | |
func _process(delta): | |
position.x += direction | |
func _on_Area2D_area_entered( area ): | |
$sprite.play("die") | |
$sprite.connect("animation_finished", self, "on_animation_finished") | |
pass # replace with function body | |
func on_animation_finished(): | |
queue_free() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment