Solarus-Games English Forum

Solarus => Development => Topic started by: Zefk on May 15, 2017, 01:51:17 PM

Title: [Solved]Screen vs entity position?
Post by: Zefk on May 15, 2017, 01:51:17 PM
Is there a formula I could use to calculate screen image x,y coordinates to the entity position? For example, drawing an image at the hero. I am not sure that entity:get_position() is related to this because is not that position different than image x,y coordinates?
Title: Re: Screen vs entity position?
Post by: zutokaza on May 15, 2017, 04:32:51 PM
I think getting the position of the entities with entity:get_position() only works for drawing if your map is 320 x 240. It has to be the same as the quest size.

I am not really sure how to solve this. There might need to be drawing checks as the map scrolls. Some calculations would work until the hero starts in a location where the map scrolls.

Maybe @Diarandor or Christopho knows?
Title: Re: Screen vs entity position?
Post by: Christopho on May 15, 2017, 05:08:27 PM
entity:get_position() give coordinates relative to the map. You can find coordinates relative to the screen if you just subtract the camera position.
Title: [Solved]Screen vs entity position?
Post by: Zefk on May 15, 2017, 05:27:31 PM
That was the first thing I tried because I saw it in the Children of Solarus game_over.lua script. (https://github.com/solarus-games/children-of-solarus/blob/master/data/menus/game_over.lua) It seems I forgot to repeat my timer when checking my script, so a mistake on my part. Thank you Christopho and Zutokaza for the assistance. My script works perfectly now.