Author Topic: Movement behaviour  (Read 864 times)

Vauteck

  • Newbie
  • *
  • Posts: 1
    • View Profile
Movement behaviour
« on: May 15, 2015, 05:17:18 pm »
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:

Code: [Select]
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

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1172
    • View Profile
Re: Movement behaviour
« Reply #1 on: May 16, 2015, 08:06:03 am »
You are completely right!
Actually it can be done like you say.
Code: [Select]
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 :)