Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Realguigui

#16
Quote from: Christopho on January 28, 2017, 02:27:43 PM
I will have to think, maybe the current behavior is actually the intended one. What I know for sure is that it is undocumented, so there is at least a documentation bug :)

I think the current behavior and the new one have the same posibilities but the second is probably more comprehensible.

Maybe it would be interesting to could modify the origin point of custom entity directly in the editor. We could align precisely the entity and his sprite and see if the positioning is correct before launching the game.
#17
Hello.

I've reuse and modify the code of this thread for making a moving plateform.
Sadly, I have an offset between the custom entity and the associate sprite.
It seems normal in the editor because even I set the origin point of the 32x32 sprite at (16,16), at the opposite it's impossible to set the origin point of the 32x32 custom entity.

Sprite parameters:


Offset in the editor:


On the second picture, the origin point of the sprite (16,16) seems to be at same coordinates of the default origin point (8,13) of the 16x16 upper left square of the 32x32 custom entity. This is probably normal but the result is identical even with this code in the model of custom entity where I modify the origin point of the custom entity:
Code (lua) Select
--****************************************************************************************************
-- EVENEMENT : A LA CREATION DE L'ENTITE PLATEFORME MOBILE AVEC DES VALEURS PAR DEFAUT
--****************************************************************************************************
function entity:on_created()
  -- On créé un sprite a affecter à l'entité
  self:create_sprite("entities/platform")
  -- On parametre la taille de l'entité en px
  self:set_size(32, 32)
  -- On parametre le point d'origine de l'entité par rapport à son coin haut gauche en px
  self:set_origin(16, 16)
...


Game screen


Like you can see, in the game the offset is exactly the same as in the editor.
#18
Hello.

After trying the function map:create_dynamic_tile() with the help of the documentation, it seems that the name of the key in the table "properties" that indicated the name of the pattern is "pattern" and not "tile_pattern_id".

Code with wrong key
Code (lua) Select
local dt_lava = {["name"]="test_lave",["layer"]=1,["x"]=320,["y"]=336,["width"]=32,["height"]=32,["tile_pattern_id"]="lava",["enabled_at_start"]=true}

local dt_test = map:create_dynamic_tile(dt_lava)


Debug Console
Info: Simulation started
Error: In on_started: [string "maps/donjon01_01.lua"]:29: bad argument #1 to create_dynamic_tile (Bad field 'pattern' (string expected, got nil))
Info: Simulation finished


Code with the key "pattern"
Code (lua) Select

local dt_lava = {["name"]="test_lave",["layer"]=1,["x"]=320,["y"]=336,["width"]=32,["height"]=32,["pattern"]="lava",["enabled_at_start"]=true}

local dt_test = map:create_dynamic_tile(dt_lava)


No errors and
#19
Thank you. it's work perfectly.
Sorry for this message due to inattention problem. Maybe you could move it in the development section of this forum
#20
Bugs & Feature requests / sprite:set_animation bug ?
January 17, 2017, 05:45:42 PM
Hello. Sorry for my english but I'm french.

At the almost end of the code below, I use the function "sprite:set_animation" in the line : entity:get_sprite():set_animation("entree",traversage()). In the documentation, I'm reading that the second parameter may be a "function that will be called when the animation finishes". Sadly, the animation and the function start at the same millisecond (I put 2 print os.clock() to verify that). My animation have 9 steps with 100 ms of delay for each.
Well, bug or I forgot something ?

Code of the custom entitie:
-- Lua script of custom entity mur_illusion.
-- This script is executed every time a custom entity with this model is created.

local entity = ...
local game = entity:get_game()
local map = entity:get_map()
-- On recupere le hero dans une variable locale
local hero = map:get_hero()

-- variable qui contient l'autre custom entity qui correspond à l'autre coté du mur illusion
-- on ne l'affecte pas car on ne sait pas s'il est déjà créé au moment de la création de cette entité
local autre_mur = nil

local traversage_en_cours = false

--****************************************************************************************************
-- EVENEMENT : A LA CREATION DE L'ENTITE MUR ILLUSION
--****************************************************************************************************
function entity:on_created()
  -- RECUPERATION DE L'AUTRE MUR
  -- On recupere le préfixe de notre entité (partie à gauche du dernier "_")
  -- On cherche la position du "_" suivi d'un chiffre
  local index = string.find(entity:get_name(),"_%d")
  -- On recupere les lettres du nom de notre variable de la 1ere position jusqu'a la valeur de l'index pour obtenir notre prefixe
  local prefixe = string.sub(entity:get_name(),1,index)
  -- Si le mur opposé existe (s'il y a 2 entités sur la carte qui ont le meme préfixe)
  if map:get_entities_count(prefixe) == 2 then
    -- On recupere le mur de sortie opposé grace au nommage formalisé
    -- pour chaque entité trouvé sur la map qui ont le meme préfixe
    for found_entity in map:get_entities(prefixe) do
      -- Si cette entité n'est pas l'entité actuelle alors
      if found_entity ~= entity then
        -- On a trouvé notre autre entité et on l'affecte à notre var
        autre_mur = found_entity
       
        -- On attend un instant pendant que le code continue de s'executer que les entitées et leur fonctions soient initialisées pour ...
        sol.timer.start(100, function()
          -- ... transmettre notre entité à l'autre mur au cas ou il ne nous ai pas récupéré au moment de sa creation car créé en 1er
          autre_mur:set_mur_oppose(entity)
          return false
        end)

      end     
    end
  end


  -- On initialise certains parametres que l'on a pas pu initialisés avec l'editeur
  -- On rend l'entité intraversable
  entity:set_traversable_by(false)

  -- On parametre un test de collision de type "facing" avec lancement de la fonction hero mur interaction
  entity:add_collision_test("facing",hero_mur_interaction)

end

--****************************************************************************************************
-- FONCTION EXTERNE QUI PERMET DE PARAMETRER LE MUR OPPOSE
--****************************************************************************************************
function entity:set_mur_oppose(other_entity)
  autre_mur = other_entity
end


--****************************************************************************************************
-- FONCTION LANCEE LORSQUE LE HERO ENTRE EN CONTACT "DE FACE" AVEC LE MUR ILLUSION (TEST DE COLLISION)
--****************************************************************************************************
function hero_mur_interaction()
  -- Si le hero pousse le mur
  if hero:get_animation()=="pushing" and traversage_en_cours == false then

    -- On signale qu'il y a traversage en cours pour eviter que le processus se relance immédiatement
    traversage_en_cours = true

    -- On freeze le hero
    hero:freeze()

    -- On rend invisible le hero
    hero:set_visible(false)

    print ("avant animation: " .. os.clock())

    -- On lance l'animation d'entrée dans le mur
    entity:get_sprite():set_animation("entree",traversage())

  end
   
end



function traversage()

  print ("fonction traversage: " .. os.clock())
 
  -- On remets l'animation "normal" sur le mur illusion
  entity:get_sprite():set_animation("normal")

  -- On lance l'animation "sortie"
   
  -- On recupere les coordonnées qui font face au mur opposé
  local x,y,layer = autre_mur:get_facing_position()
 
  -- Selon la  direction du mur ont ajoute quelques pixels dans la bonne direction pour ne pas se retrouver coincé dans le mur
  if autre_mur:get_direction() == 0 then
      -- On déplace le hero au dela du mur opposé
      hero:set_position(x+10,y,layer)
  end

  if autre_mur:get_direction() == 1 then
      -- On déplace le hero au dela du mur opposé
      hero:set_position(x,y-10,layer)
  end

  if autre_mur:get_direction() == 2 then
      -- On déplace le hero au dela du mur opposé
      hero:set_position(x-10,y,layer)
  end

  if autre_mur:get_direction() == 3 then
      -- On déplace le hero au dela du mur opposé
      hero:set_position(x,y+30,layer)
  end

  -- On defreeze le hero
    hero:unfreeze()

  -- On rend visible le hero
    hero:set_visible(true)

  -- On signale que le mur est de nouveau traversable
  traversage_en_cours = false

end



Debug Console:(I tried 2 times to go throught the wall)
Info: Solarus 1.5.1
Info: Opening quest 'C:/Users/atic/Google Drive/old school'
Info: Sound volume: 100
Info: Music volume: 100
Info: Joypad support enabled: true
Info: 2D acceleration: no
Info: Turbo mode: no
Warning: Cannot use quest size 320x240: this quest only supports 256x224 to 256x240. Using 256x224 instead.
Info: Video mode: normal
Info: LuaJIT: yes (LuaJIT 2.0.3)
This is a sample quest for Solarus.
Info: Language: fr
Info: Lua console: yes
Info: Simulation started
avant animation: 14.907
fonction traversage: 14.907
avant animation: 19.33
fonction traversage: 19.33
Info: Simulation finished


Thanks for your help.