summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/camera_2d.cpp31
-rw-r--r--scene/2d/camera_2d.h2
-rw-r--r--scene/2d/canvas_item.cpp11
-rw-r--r--scene/2d/canvas_item.h1
-rw-r--r--scene/2d/tile_map.cpp36
-rw-r--r--scene/2d/tile_map.h3
6 files changed, 81 insertions, 3 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index 27e07a35be..f98a50e3e0 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -408,6 +408,35 @@ void Camera2D::force_update_scroll() {
_update_scroll();
}
+void Camera2D::reset_smoothing() {
+
+ smoothed_camera_pos = camera_pos;
+ _update_scroll();
+}
+
+void Camera2D::align() {
+
+ Size2 screen_size = get_viewport_rect().size;
+ screen_size=get_viewport_rect().size;
+ Point2 current_camera_pos = get_global_transform().get_origin();
+ if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) {
+ if (h_ofs<0) {
+ camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs;
+ } else {
+ camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs;
+ }
+ if (v_ofs<0) {
+ camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs;
+ } else {
+ camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
+ }
+ } else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){
+
+ camera_pos=current_camera_pos;
+ }
+
+ _update_scroll();
+}
void Camera2D::set_follow_smoothing(float p_speed) {
@@ -543,6 +572,8 @@ void Camera2D::_bind_methods() {
ObjectTypeDB::bind_method(_MD("is_follow_smoothing_enabled"),&Camera2D::is_follow_smoothing_enabled);
ObjectTypeDB::bind_method(_MD("force_update_scroll"),&Camera2D::force_update_scroll);
+ ObjectTypeDB::bind_method(_MD("reset_smoothing"),&Camera2D::reset_smoothing);
+ ObjectTypeDB::bind_method(_MD("align"),&Camera2D::align);
ObjectTypeDB::bind_method(_MD("_set_old_smoothing","follow_smoothing"),&Camera2D::_set_old_smoothing);
diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h
index 22e5bc382a..b3f55d798d 100644
--- a/scene/2d/camera_2d.h
+++ b/scene/2d/camera_2d.h
@@ -128,6 +128,8 @@ public:
Vector2 get_camera_pos() const;
void force_update_scroll();
+ void reset_smoothing();
+ void align();
Camera2D();
};
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index bc5bff3b8e..eb4f457975 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -948,6 +948,15 @@ Ref<CanvasItemMaterial> CanvasItem::get_material() const{
return material;
}
+Vector2 CanvasItem::make_canvas_pos_local(const Vector2& screen_point) const {
+
+ ERR_FAIL_COND_V(!is_inside_tree(),screen_point);
+
+ Matrix32 local_matrix = (get_canvas_transform() *
+ get_global_transform()).affine_inverse();
+
+ return local_matrix.xform(screen_point);
+}
InputEvent CanvasItem::make_input_local(const InputEvent& p_event) const {
@@ -1052,6 +1061,8 @@ void CanvasItem::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_use_parent_material","enable"),&CanvasItem::set_use_parent_material);
ObjectTypeDB::bind_method(_MD("get_use_parent_material"),&CanvasItem::get_use_parent_material);
+ ObjectTypeDB::bind_method(_MD("make_canvas_pos_local","screen_point"),
+ &CanvasItem::make_canvas_pos_local);
ObjectTypeDB::bind_method(_MD("make_input_local","event"),&CanvasItem::make_input_local);
BIND_VMETHOD(MethodInfo("_draw"));
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 8a61b449fd..b894310ce2 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -263,6 +263,7 @@ public:
bool get_use_parent_material() const;
InputEvent make_input_local(const InputEvent& pevent) const;
+ Vector2 make_canvas_pos_local(const Vector2& screen_point) const;
Vector2 get_global_mouse_pos() const;
Vector2 get_local_mouse_pos() const;
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 1f16b36466..1a4f88c30e 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -222,6 +222,10 @@ void TileMap::_fix_cell_transform(Matrix32& xform,const Cell& p_cell, const Vect
Size2 s=p_sc;
Vector2 offset = p_offset;
+
+ if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT)
+ offset.y+=cell_size.y;
+
if (s.y > s.x) {
if ((p_cell.flip_h && (p_cell.flip_v || p_cell.transpose)) || (p_cell.flip_v && !p_cell.transpose))
@@ -240,7 +244,7 @@ void TileMap::_fix_cell_transform(Matrix32& xform,const Cell& p_cell, const Vect
if (p_cell.flip_h) {
xform.elements[0].x=-xform.elements[0].x;
xform.elements[1].x=-xform.elements[1].x;
- if (tile_origin==TILE_ORIGIN_TOP_LEFT)
+ if (tile_origin==TILE_ORIGIN_TOP_LEFT || tile_origin==TILE_ORIGIN_BOTTOM_LEFT)
offset.x=s.x-offset.x;
}
if (p_cell.flip_v) {
@@ -248,6 +252,12 @@ void TileMap::_fix_cell_transform(Matrix32& xform,const Cell& p_cell, const Vect
xform.elements[1].y=-xform.elements[1].y;
if (tile_origin==TILE_ORIGIN_TOP_LEFT)
offset.y=s.y-offset.y;
+ else if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT) {
+ if(p_cell.transpose)
+ offset.y+=s.y;
+ else
+ offset.y-=s.y;
+ }
}
xform.elements[2].x+=offset.x;
xform.elements[2].y+=offset.y;
@@ -411,6 +421,24 @@ void TileMap::_update_dirty_quadrants() {
if (tile_origin==TILE_ORIGIN_TOP_LEFT) {
rect.pos+=tile_ofs;
+
+ } else if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT) {
+
+ rect.pos+=tile_ofs;
+
+ if(c.transpose)
+ {
+ if(c.flip_h)
+ rect.pos.x-=cell_size.x;
+ else
+ rect.pos.x+=cell_size.x;
+ } else {
+ if(c.flip_v)
+ rect.pos.y-=cell_size.y;
+ else
+ rect.pos.y+=cell_size.y;
+ }
+
} else if (tile_origin==TILE_ORIGIN_CENTER) {
rect.pos+=tcenter;
@@ -584,6 +612,9 @@ Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const
q.pos+=get_cell_draw_offset();
if (tile_origin==TILE_ORIGIN_CENTER)
q.pos+=cell_size/2;
+ else if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT)
+ q.pos.y+=cell_size.y;
+
xform.set_origin( q.pos );
// q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
@@ -1242,7 +1273,7 @@ void TileMap::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/quadrant_size",PROPERTY_HINT_RANGE,"1,128,1"),_SCS("set_quadrant_size"),_SCS("get_quadrant_size"));
ADD_PROPERTY( PropertyInfo(Variant::MATRIX32,"cell/custom_transform"),_SCS("set_custom_transform"),_SCS("get_custom_transform"));
ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/half_offset",PROPERTY_HINT_ENUM,"Offset X,Offset Y,Disabled"),_SCS("set_half_offset"),_SCS("get_half_offset"));
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/tile_origin",PROPERTY_HINT_ENUM,"Top Left,Center"),_SCS("set_tile_origin"),_SCS("get_tile_origin"));
+ ADD_PROPERTY( PropertyInfo(Variant::INT,"cell/tile_origin",PROPERTY_HINT_ENUM,"Top Left,Center,Bottom Left"),_SCS("set_tile_origin"),_SCS("get_tile_origin"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"cell/y_sort"),_SCS("set_y_sort_mode"),_SCS("is_y_sort_mode_enabled"));
ADD_PROPERTY( PropertyInfo(Variant::BOOL,"collision/use_kinematic",PROPERTY_HINT_NONE,""),_SCS("set_collision_use_kinematic"),_SCS("get_collision_use_kinematic"));
ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/friction",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_collision_friction"),_SCS("get_collision_friction"));
@@ -1264,6 +1295,7 @@ void TileMap::_bind_methods() {
BIND_CONSTANT( HALF_OFFSET_DISABLED );
BIND_CONSTANT( TILE_ORIGIN_TOP_LEFT );
BIND_CONSTANT( TILE_ORIGIN_CENTER );
+ BIND_CONSTANT( TILE_ORIGIN_BOTTOM_LEFT );
}
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index cec5ac0a1b..b48fdde43f 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -54,7 +54,8 @@ public:
enum TileOrigin {
TILE_ORIGIN_TOP_LEFT,
- TILE_ORIGIN_CENTER
+ TILE_ORIGIN_CENTER,
+ TILE_ORIGIN_BOTTOM_LEFT
};