Bouger la caméra

Started by Delltus, December 23, 2017, 01:12:44 AM

Previous topic - Next topic
December 23, 2017, 01:12:44 AM Last Edit: December 23, 2017, 01:48:45 AM by Delltus
Bonsoir je souhaiterais savoir comment déplacer la caméra vers une porte part exemple qui s'ouvre j'ai regarder sur http://www.solarus-games.org ça dis que depuis 1.5 il faut plus utiliser move.camera est il faut utiliser entité: get_bounding_box ()

j'ai essayer mais je sais pas exactement comment l'utiliser j'avais penser à ça mais j'arrive pas à bien l'utiliser, pouvez vous nous dire comment faire je vous remercie d'avance à vous je vous remercie également pour vos dernière réponse sur les autre sujet que j'ai poster.

function Switch_a:on_activated()
    map:get_entity("Porte_b_3")
    sol.audio.play_sound("door_open")
    sol.audio.play_sound("secret")
  map:open_doors("Porte_a")


Tu as plusieurs facon de faire.

Dans solarus < 1.5, tu peux utiliser une fonction hardcodée map:move_camera
Dans les futures versions, il me semble que cette fonction n'existera plus mais tu peux cependant la coder et modifier son comportement comme bon te semble

On te conseilleras d'utiliser les metatable comme le script ci-dessous

Copies ce code, enregistre le script et dans main.lua, utilise require()

Code (lua) Select
local map_metatable = sol.main.get_metatable("map")

-- Move the camera
function map_metatable:move_camera(x, y, speed, callback, delay_before, delay_after)
  local camera = self:get_camera()
  local game = self:get_game()
  local hero = self:get_hero()

  delay_before = delay_before or 1000
  delay_after = delay_after or 1000

  local back_x, back_y = camera:get_position_to_track(hero)
  game:set_suspended(true)
  camera:start_manual()

  local movement = sol.movement.create("target")
  movement:set_target(camera:get_position_to_track(x, y))
  movement:set_ignore_obstacles(true)
  movement:set_speed(speed)
  movement:start(camera, function()
    local timer_1 = sol.timer.start(self, delay_before, function()
      callback()
      local timer_2 = sol.timer.start(self, delay_after, function()
        local movement = sol.movement.create("target")
        movement:set_target(back_x, back_y)
        movement:set_ignore_obstacles(true)
        movement:set_speed(speed)
        movement:start(camera, function()
          game:set_suspended(false)
          camera:start_tracking(hero)
          if self.on_camera_back ~= nil then
            self:on_camera_back()
          end
        end)
      end)
      timer_2:set_suspended_with_map(false)
    end)
    timer_1:set_suspended_with_map(false)
  end)
end


Donc, dans ton script, tu devrais utiliser

Code (lua) Select

  function Switch_a:on_activated()
    local b3_door = map:get_entity("Porte_b_3") -- ?
    local x, y = map:get_entity("Porte_a"):get_position()
    local speed = 90

    map:move_camera(x, y, speed, function() 
      sol.audio.play_sound("door_open")
      sol.audio.play_sound("secret")
      map:open_doors("Porte_a")
    end, 1000, 1000)
  end

Je débute dans le code peux tu êtres un peux plus clair dans les étapes à suivre tu mas perdu en route ^^ je suis en 1.5.3
merci pour ta réponse je suis prêt à suivre tes introductions

You should first learn Lua: read Lua tutorials, watch Christopho's tutorials and study scripts of other projects. Later, start with small things and testing funcions of the Solarus Lua API, and finally make more complex things. Be patient.
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Je suis d'accord avec toi j'apprend des différents projet ect.. mais pouvez vous me dire comment utiliser

Quotefonction map: move_camera (x, y, vitesse, rappel, delay_before, delay_after)

  caméra locale = map: get_camera ()
  jeu local = map: get_game ()
  Héros local = map: get_hero ()

  delay_before = delay_before ou 1000
  delay_after = delay_after ou 1000

  back_x local, back_y = camera: get_position_to_track (héros)
  jeu: set_suspended (true)
  caméra: start_manual ()

  mouvement local = sol.movement.create ("cible")
  mouvement: set_target (camera: get_position_to_track (x, y))
  mouvement: set_ignore_obstacles (true)
  mouvement: set_speed (vitesse)
  mouvement: démarrer (caméra, fonction ()
    local timer_1 = sol.timer.start (map, delay_before, function ()
      rappeler()
      local timer_2 = sol.timer.start (map, delay_after, function ()
        mouvement local = sol.movement.create ("cible")
        mouvement: set_target (back_x, back_y)
        mouvement: set_ignore_obstacles (true)
        mouvement: set_speed (vitesse)
        mouvement: démarrer (caméra, fonction ()
          jeu: set_suspended (false)
          caméra: start_tracking (héros)
          si map.on_camera_back ~ = nil alors
            carte: on_camera_back ()
          fin
        fin)
      fin)
      timer_2: set_suspended_with_map (false)
    fin)
    timer_1: set_suspended_with_map (false)
  fin)
fin

Pour bouger la caméra.

You cannot definitely use that code to move the camera, because you have broken the code that MetalZelda gave you. Your syntax is all wrong, so you still don't even know the basics of programming. Let's do things in the right order:
1) Learn to code in Lua. -> You are still at this step. Do not jump to step 4, it is too soon!
2) Watch Chris' tutorials, study his scripts.
3) Test small changes of others' code, adapt the code to your purposes and mess around.
4) Start coding your game.
5) Sell your game and get rich!
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Oui, il faudrait que tu apprennes le LUA afin d'y connaitre les bases.
Tu devrais suivre les tutoriaux de Christopho, ca peut parfaitement aider a maitriser et l'éditeur, et le LUA dans une forme basique

https://www.youtube.com/watch?v=rsammSHv7xc&index=1&list=PLzJ4jb-Y0ufzB4nXkSINFhbrtLlnlI4li