Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Enemy built when not displayed.
Started by Painconfess Jan 02 2016 04:13 AM

3 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Painconfess

[GLOBAL: userInfoPane.html]
Painconfess
  • Enthusiast

  • 49 posts
  • Corona SDK

I just noticed, that if I make large object in Tiled, the enemy is being built when map is loaded, not when it should be built using object culling. I noticed that it will print things from enemy.lua to console when it shouldnt. 

 

This is the code that you gave me to use object culling.

local function addObjectType(params)
   params.objects = params.objects or {}
 
   local function buildObject(event)
     local obj = params.build(event)
     if obj then
   event.object.builtObject = obj
   obj.mapObject = event.object
   params.objects[obj] = obj
end
   end
 
   for layer in map.objectLayers() do
     layer.addObjectListener("type", params.objectType, "drawn", buildObject)
     layer.addObjectListener("type", params.objectType, "erased", function(event)
      if (event.object.builtObject) then
      params.objects[event.object.builtObject] = nil
      params.remove(event.object.builtObject)
      end
    end)
end
 
end
 
So all in all, my enemy is built when it should be culled :)


[TOPIC: post.html]
#2

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

Can you give me a bit more information? How big is the enemy? How big is the map? What things is it printing to the console when it shouldn't? Is it getting created when it's well off the screen?

 

- Caleb



[TOPIC: post.html]
#3

Painconfess

[GLOBAL: userInfoPane.html]
Painconfess
  • Enthusiast

  • 49 posts
  • Corona SDK

Yes it is getting created when it well off the screen (positioned player and enemy to the other sides of the map).

Map's tile size is 96x96 with 100x100 tiles. It is printing things in enemy.lua and enterFrame function the enemy has. For example my enterFrame function prints "ZOMBIE" from the first line of the function.

 

I noticed its not about the size of the rectangle Tiled object. It has something to do with its position. These are the player's starting coordinate and my zombie's "bug" coordinates:

player: x = 5631.54, y = ​2780.62

zombie: x = 808.63, y= 2848,73 ( width 932, height 437 )

 

(the map is not completely done, this is why the x coordinate is not so great in player :) )

 

EDIT:

Now I am testing with different player starting locaitons (mainly changing y coordinate) and these are the results:

 

Not wanted build happens (player y coordinates):

 

2312

2476

2628

2780

2752

2980

 

Does not happen (yay!)

3380 or greater ( on 3380 the objectType.remove() was also called, nowhere else this happened)

1920 or less

 

Zombie's coordinates and size were the same as mentioned before. player.x varied slightly.

 

EDIT: Now I made the same testing with zombie By switching places with player and zombie, and changed the coordinate with zombie the same way than player (changing y coordinate) and the unwanted build is not happening at all

 

all in all the bug happens when zombie.x < player.x and if zombie.y - player.y > ~ 800

 

Hope this helps at all  :D



[TOPIC: post.html]
#4

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

Hm... I'll check this out.

 

- Caleb




[topic_controls]
 
[/topic_controls]