[Solved] Sprites not visible when entities created

Started by SyF, March 26, 2020, 08:15:39 PM

Previous topic - Next topic
Hello guys, it is been a long time I don't write in this forum ;)

I've got a problem when I create a boss with separated parts. I successed to create all these parts one by one with no issue (for example function "3A. create_shoulder" in the "boss2_crane" file) ... But I want to optimise my script with the new function "03. create_part_boss".

However, when I use this function, the sprite of these part are not visible in the map.
But, thanks to my print, I know these entities are created.

Do you have any idea ?

PS:
The scripts are attached (sorry for the franglish  ;D )

Hey, I'm not sure how many other people use their phones to look at this site, but I can't open those files. Have you thought about hosting on Gitlab or GitHub, or putting the relevant code in your post in code format?

Anyway, without being able to see the code, are you using `sol.sprite.create()` or are you using `enemy:create_sprite()`? Usually what you want in this circumstance is probably `enemy:create_sprite`

I have already encountered a similar problem, the sprite was displayed but outside the screen area and was therefore not visible.

Hi Max,
I use "enemy:create_enemy()" in this case.
When I used the optional variable "sprite" in it, it didn't work. So I added manually the animation. But I still have nothing.

Here you can see the code (where I create the new enemies) on your phone ;)

local enemy = ...
local game = enemy:get_game()
local map = enemy:get_map()
local hero = map:get_hero()


-- Distance entre entité
local x_CS = 20 -- Position shoulder
local x_SO = 20
local x_OA = 20
local x_AH = 20
local y_CH = 34

-- Position orb
local x_CO = x_CS + x_SO

-- Position arm
local x_CA = x_CO + x_OA

-- Position dragons
local x_CH =  x_CA + x_AH
local x_CH_n = -x_CH
local y_CH_n =  -y_CH


local properties = {
  life = 2,
  damage = 2,
  speed_ground = 0,
  movement_ground = "random",
  }

local max_life = properties.life
local body_sprite


-----------------------------------------------------
--01. Creation of the boss
function enemy:on_created()

  enemy:set_life(max_life)
  enemy:set_damage(properties.damage)
  enemy:set_hurt_style("boss")
  enemy:set_treasure("heart_container")
  enemy:set_attack_consequence("explosion", "ignored")
  enemy:set_attack_consequence("sword", "protected")
  body_sprite = enemy:create_sprite("enemies/" .. enemy:get_breed())

local x_boss,y_boss,layer_boss = enemy:get_position()
  enemy:create_part_boss("shoulder","boss/boss2_tentacle","shoulder",x_boss,y_boss,layer_boss,x_CS,y_CH)
  --enemy:create_part_boss("orb","boss/boss2_tentacle","orb",x_boss,y_boss,layer_boss,x_CO,y_CH)
  --enemy:create_part_boss("arm","boss/boss2_tentacle","arm",x_boss,y_boss,layer_boss,x_CA,y_CH)
  --enemy:create_part_boss("dragons","boss/boss2_dragons","stopped",x_boss,y_boss,layer_boss,x_CH,y_CH)

end

-----------------------------------------------------
--02. When the boss moves
function enemy:on_restarted()

local x_boss,y_boss,y_layer = enemy:get_position()
  movement = sol.movement.create("target")
  movement:set_target(hero)
  movement:set_speed(properties.speed_ground)
  movement:start(enemy)

end

-----------------------------------------------------
--03. Create parts of boss
function enemy:create_part_boss(var_name,var_breed,var_animation,var_x_boss,var_y_boss,var_layer_boss,var_x,var_y)
  for i =1,4 do
--if i == 1 then
map:create_enemy{
  name = var_name,
  layer = var_layer_boss,
  x = var_x_boss + var_x,
  y = var_y,
  direction = 1,
  breed = var_breed,
  }
--end
end

-- Set the right animation
for entity in map:get_entities(var_name) do
entity:get_sprite():set_animation(var_animation)
end
end
-----------------------------------------------------
--03.A Create the shoulders
--function enemy:create_shoulders(var_x,var_y,var_layer)
--
--shoulder_1 = map:create_enemy{
--  name = "shoulder",
--  layer = var_layer,
--  x = var_x + x_CS,
--  y = var_y + y_CH,
--  direction = 0,
--  breed = "boss/boss2_tentacle",
--  }
-- 
---- Set the right animation
--for entity in map:get_entities("shoulder") do
--  entity:get_sprite():set_animation("shoulder")
--end
--
--end
--

-----------------------------------------------------
--04. When the boss is dead
function enemy:on_dead()
game: set_value("defeated_boss",2)
--map:open_doors("door_boss_") ouvrir les portes de sortie
sol.audio.stop_music()
end

-----------------------------------------------------
--05. Move heads based on the boss's movement
function enemy:on_position_changed(x_move, y_move, layer_move)
    head_1:move_head(x_move + x_CH,y_move + y_CH,layer_move)
    head_2:move_head(x_move + x_CH_n,y_move + y_CH,layer_move)
end

As mr froggy asked above,did you check that all sprite and enemy properties are correct?
Some things to check: position of the sprites in the image and of the enemy in the map, that the enemy and sprites exist, the sprites' origin point, etc. Make sure that you start an animation and that it does exist. Remember that the engine in many cases starts automatically the walking animation on enemies, and if that one does not exist you may see nothing at all (it is easy to override this built-in behavior using sprite/entity events, as I do with my enemies).
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

April 01, 2020, 03:58:20 PM #5 Last Edit: April 01, 2020, 07:22:56 PM by SyF
Hello guys,

I checked the position and I saw the sprite are displayed outside the screen. I didn't indicate the correct position for them  ;D
Thanks for your comment Froggy and Diarandor  ;)