mirror of
https://github.com/godotengine/godot.git
synced 2024-11-10 22:23:07 +00:00
-renamed function to get object from instance id
-added function to get list of tiles used
This commit is contained in:
parent
3b434eacde
commit
be46be7801
@ -3,10 +3,25 @@ extends Node
|
||||
|
||||
var current_scene = null
|
||||
|
||||
|
||||
func goto_scene(path):
|
||||
|
||||
# This function will usually be called from a signal callback,
|
||||
# or some other function from the running scene.
|
||||
# Deleting the current scene at this point might be
|
||||
# a bad idea, because it may be inside of a callback or function of it.
|
||||
# The worst case will be a crash or unexpected behavior.
|
||||
|
||||
# The way around this is deferring the load to a later time, when
|
||||
# it is ensured that no code from the current scene is running:
|
||||
|
||||
call_deferred("_deferred_goto_scene",path)
|
||||
|
||||
|
||||
func _deferred_goto_scene(path):
|
||||
|
||||
# Immediately free the current scene,
|
||||
# there is no risk here.
|
||||
# there is no risk here.
|
||||
current_scene.free()
|
||||
|
||||
# Load new scene
|
||||
@ -18,19 +33,6 @@ func _deferred_goto_scene(path):
|
||||
# Add it to the active scene, as child of root
|
||||
get_tree().get_root().add_child(current_scene)
|
||||
|
||||
func goto_scene(path):
|
||||
|
||||
# This function will usually be called from a signal callback,
|
||||
# or some other function from the running scene.
|
||||
# Deleting the current scene at this point might be
|
||||
# a bad idea, because it may be inside of a callback or function of it.
|
||||
# The worst case will be a crash or unexpected behavior.
|
||||
|
||||
# The way around this is deferring the load to a later time, when
|
||||
# it is ensured that no code from the current scene is running:
|
||||
|
||||
call_deferred("_deferred_goto_scene",path)
|
||||
|
||||
|
||||
func _ready():
|
||||
# Get the current scene, the first time.
|
||||
|
@ -98,7 +98,7 @@ const char *GDFunctions::get_func_name(Function p_func) {
|
||||
"dict2inst",
|
||||
"hash",
|
||||
"print_stack",
|
||||
"get_inst",
|
||||
"instance_from_id",
|
||||
};
|
||||
|
||||
return _names[p_func];
|
||||
@ -904,7 +904,7 @@ void GDFunctions::call(Function p_func,const Variant **p_args,int p_arg_count,Va
|
||||
};
|
||||
} break;
|
||||
|
||||
case GET_INST: {
|
||||
case INSTANCE_FROM_ID: {
|
||||
|
||||
VALIDATE_ARG_COUNT(1);
|
||||
if (p_args[0]->get_type()!=Variant::INT && p_args[0]->get_type()!=Variant::REAL) {
|
||||
@ -1316,8 +1316,8 @@ MethodInfo GDFunctions::get_info(Function p_func) {
|
||||
return mi;
|
||||
} break;
|
||||
|
||||
case GET_INST: {
|
||||
MethodInfo mi("get_info",PropertyInfo(Variant::INT,"instance_id"));
|
||||
case INSTANCE_FROM_ID: {
|
||||
MethodInfo mi("instance_from_id",PropertyInfo(Variant::INT,"instance_id"));
|
||||
mi.return_val.type=Variant::OBJECT;
|
||||
return mi;
|
||||
} break;
|
||||
|
@ -94,7 +94,7 @@ public:
|
||||
DICT2INST,
|
||||
HASH,
|
||||
PRINT_STACK,
|
||||
GET_INST,
|
||||
INSTANCE_FROM_ID,
|
||||
FUNC_MAX
|
||||
|
||||
};
|
||||
|
@ -1024,6 +1024,19 @@ bool TileMap::is_y_sort_mode_enabled() const {
|
||||
return y_sort_mode;
|
||||
}
|
||||
|
||||
Array TileMap::get_used_cells() const {
|
||||
|
||||
Array a;
|
||||
a.resize(tile_map.size());
|
||||
int i=0;
|
||||
for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
|
||||
|
||||
Vector2 p (E->key().x,E->key().y);
|
||||
a[i++]=p;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
void TileMap::_bind_methods() {
|
||||
|
||||
@ -1080,6 +1093,8 @@ void TileMap::_bind_methods() {
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("clear"),&TileMap::clear);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("get_used_cells"),&TileMap::get_used_cells);
|
||||
|
||||
ObjectTypeDB::bind_method(_MD("map_to_world","mappos","ignore_half_ofs"),&TileMap::map_to_world,DEFVAL(false));
|
||||
ObjectTypeDB::bind_method(_MD("world_to_map","worldpos"),&TileMap::world_to_map);
|
||||
|
||||
|
@ -171,6 +171,8 @@ private:
|
||||
|
||||
_FORCE_INLINE_ Vector2 _map_to_world(int p_x,int p_y,bool p_ignore_ofs=false) const;
|
||||
|
||||
Array get_used_cells() const;
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user