how to control things in a scene component
Godot - game development for homies » Devlog
version 3.5.2 topic extern properties in a component
Imagine you are doing an enemy component that looks like this:
Troll:Node2D
_ AnimatedSprite:contains an iddle animation of 1 frame for example
__ TrollCollider:KinematicBody2D
___ CollisionShape2D:Rectangle2D
You attach a script to the Troll of Node2D and add this code:
tool
extends Node2D
# externally change the horizontal flip
export var flip_h = false setget setFlipHorizontal, getFlipHorizontal
# set the horizontal flip on the AnimatedSprite
func setFlipHorizontal(_flip_h):
$AnimatedSprite.flip_h = _flip_h
# return the flip horizontal statAnimatedSprite
func getFlipHorizontal():
return $AnimatedSprite.flip_h
With this script everytime you insert the EnemyTroll scene node as component into a level scene you select it and see at the right that you can toggle on/off the flip horizontal variable which affects the direction on which the troll looks forward.
You can use this to setup the game properly.
Godot - game development for homies
Status | Released |
Author | Bastian |
Genre | Educational |
Tags | Godot |
More posts
- loading resources with gdscript4 days ago
- i was wrong!7 days ago
- physics collision and layers7 days ago
- tool ghosts8 days ago
- storing player position8 days ago
- component campfire8 days ago
- camera 2D9 days ago
- component : fadein10 days ago
- blocking my view eh?10 days ago