touilleMan / godot-python

Python support for Godot 🐍🐍🐍
Other
1.83k stars 136 forks source link

Transform2D doesn't have same attributes as in GDScript #346

Open MarioMey opened 2 years ago

MarioMey commented 2 years ago

By trying the first code of the Matrixes and Transformation documentation, I do this:

from godot import exposed, Area2D, Transform2D
@exposed
class Coso(Area2D):
    def _ready(self):
        t = Transform2D()
        t.x *= 2
        t.y *= 2
        self.transform = t

... and I get this:

Traceback (most recent call last):
  File "build/x11-64/pythonscript/_godot_instance.pxi", line 98, in _godot.pythonscript_instance_call_method
  File "/home/mariomey/md-godot/test/TestTransform2D.py", line 13, in _ready
    t.x *= 2
AttributeError: 'godot.builtins.Transform2D' object has no attribute 'x'

So, the only way (I found) to achieve exactly the same, is:

from godot import exposed, Area2D, Transform2D, Vector2
...
        vx, vy, vo = Vector2(1,0), Vector2(0,1), Vector2(0,0)
        vx *= 2
        vy *= 2
        t = Transform2D(vx, vy, vo)
        self.transform = t

Why we can't modify a Transform2D object as in GDScript?

MarioMey commented 2 years ago

Also (as in here), it does exist but it is not writable:

from godot import exposed, export, Area2D, Transform2D, Vector2
@exposed
class Coso(Area2D):
    def _ready(self):
        t = Transform2D()
        t.origin = Vector2(350, 150)
        self.transform = t

Console:

Traceback (most recent call last):
  File "build/x11-64/pythonscript/_godot_instance.pxi", line 98, in _godot.pythonscript_instance_call_method
  File "/home/mariomey/md-godot/test/TestTransform2D.py", line 9, in _ready
    s.origin = Vector2(350, 150)
AttributeError: attribute 'origin' of 'godot.builtins.Transform2D' objects is not writable