Strange engine behavior.

jetrajetra Posts: 4Member
edited August 2016 in 2D

I am testing on some features for my project. So here is very simple minimal test case.
Make new project, add Control to scene, save everything, and configure project as


Next, add script to Control:

# flag for blocking continuous button press
var allow_movement = true

func _ready():
# just resize to someting smaller
set_size(Vector2(8, 8))

func _process(delta):
# one-shot one-pixel movements
if (Input.is_action_pressed("ui_left") && allow_movement):
allow_movement = false
set_pos(get_pos() + Vector2(-1, 0))
if (Input.is_action_pressed("ui_right") && allow_movement):
allow_movement = false
set_pos(get_pos() + Vector2(1, 0))
if (Input.is_action_pressed("ui_up") && allow_movement):
allow_movement = false
set_pos(get_pos() + Vector2(0, -1))
if (Input.is_action_pressed("ui_down") && allow_movement):
allow_movement = false
set_pos(get_pos() + Vector2(0, 1))

func _input(event):
# when movement button is released - we are ready to move again
if (event.is_action_released("ui_left") ||\
event.is_action_released("ui_right") ||\
event.is_action_released("ui_up") ||\
allow_movement = true

func _draw():
# draw rectangle at our position
draw_rect(Rect2(get_pos(), get_size()), Color(1, 1, 1))
# draw across viewport 1-pixel vertical lines interleaved with pixel line gap
for i in range(0, get_viewport().get_rect().size.width, 2):
draw_line(Vector2(i, 0), Vector2(i, get_viewport().get_rect().size.height), Color(0, 0, 0, 0.25))
From this i want small pixel world (64x64 pixels), some square able to move pixel-by-pixel on it, and some pattern on background.

Then strange things happen.

1. Background moves as i move my square (why? i told it to draw lines based on parent Viewport properties).
2. My square jumps over 2 pixels, instead of 1 (you can just count button presses from edge to edge - 32, not 64)

I try different ways to move and different objects - by setting their Rects, Sizes, Pos, Margins - they always move by 2 pixels.

Is this a whole lot of strange bugs? Or i'm completely out of understanding engine logic?


  • jetrajetra Posts: 4Member
    Ok. I got, that lines are drawn in Control local coordinate system.<br /><br />But why objects are moved by 2 pixel step?<br /><br />Btw, if you change set_pos and get_pos to set_size and get_size - you'll see that size is changing in 1-pixel steps.
  • jetrajetra Posts: 4Member
    Guys, why silence?<br />I need to dive in Godot, and i face a brick wall.<br />I have exp in other game engines, but i can't get into this logic.<br />How can i move object in 1-pixel steps?<br /><br />And why this code on Control doesn't work as expected (clicks are registered in strange places, not in AABB)?<br />
    extends Control<br /><br />func _ready():<br />	set_process(true)<br />	set_process_input(true)<br /><br />func _process(delta):<br />	update()<br /><br />func _draw():<br />	draw_rect(Rect2(get_pos(), get_size()), Color(1, 0, 0))<br /><br />func _input(event):<br />	if (event.type == InputEvent.MOUSE_BUTTON &amp;&amp; event.button_index == BUTTON_LEFT &amp;&amp; event.pressed):<br />		if (Rect2(get_pos(), get_size()).has_point(get_global_mouse_pos())):<br />			set_pos(get_pos() + Vector2(32, 0))
    <br /><br />What's the whole deal with positions? Where am i wrong? I just cannot find answers anywhere.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file