Movement behaviour

Started by Vauteck, May 15, 2015, 05:17:18 PM

Previous topic - Next topic
Hello,

Nice tutorial on movements Christopho ! The engine and the new editor are really improving nicely !

I have a remark on the movement implementation applied to a menu in your video tutorial ; in the on_draw function, you always draw the menu logo at fixed coordinates (0, -160), and you then rely on the movement you initialized previously in the on_started function to actually move the logo.

This way of doing feels a bit "unnatural", in the sense that since the on_draw function is called regularly, if you draw something at fixed coordinates, it should always be drawn at these coordinates right ?
Also, it feels kinda weird to not initialize the logo position in the on_started function but in the on_draw function instead.
Maybe something like this would feel more "natural" for coders:


function solarus_logo_menu:on_started()
    image.set_position(0, -160)
   // Initialize the movement here
   ...
end

function solarus_logo_menu:on_draw(dst_surface)
    image:draw(dst_surface, image.get_pos_x(), image.get_pos_y())
    // or just
    image:draw(dst_surface)
end 


Anyway, keep up the good work !

Cheers

Vauteck

You are completely right!
Actually it can be done like you say.
function solarus_logo_menu:on_started()
    image:set_xy(0, -160)
   // Initialize the movement here
   ...
end

function solarus_logo_menu:on_draw(dst_surface)
    image:draw(dst_surface)
end


I should have done it this way in the tutorial :)