Updated tutorial_canvas_transforms (markdown)

Juan Linietsky 2015-04-17 10:33:08 -03:00
parent 4a932a0b3d
commit e2dd4c019d

@ -42,4 +42,19 @@ Finally then, to convert a CanvasItem local coordinates to screen coordinates, j
var screen_coord = get_viewport_transform() * ( get_global_transform() * local_pos )
```
Keep in mind, however, that it is generally not desired to work with screen coordinates. The recommended approach is to simply work in Canvas coordinates (CanvasItem.get_global_transform()), to allow automatic screen resolution resizing to work properly.
Keep in mind, however, that it is generally not desired to work with screen coordinates. The recommended approach is to simply work in Canvas coordinates (CanvasItem.get_global_transform()), to allow automatic screen resolution resizing to work properly.
### Feeding Custom Input Events
It is often desired to feed custom input events to the scene tree. With the above knowledge, to correctly do this, it must be done the following way:
```python
var local_pos = Vector2(10,20) # anything local
var ie = InputEvent()
ie.type=InputEvent.MOUSE_BUTTON
ie.button_index=1 # left click
ie.pos = get_viewport_transform() * ( get_global_transform() * local_pos )
get_tree().input_event(ie)
```