Karai17
Party member
Posts: 909
Joined: Sun Sep 02, 2012 10:46 pm

Kadoba wrote: I'm pretty sure this is because Object:updateDrawInfo() isn't being called. Objects keep an internal table that holds their drawing information. Anytime you resize or move the object you should call that function. Having said that, I recommend you don't use ATL objects at all as real objects. They're called "objects" because that's what Tiled calls them, but they're really just placeholder data for your own objects. The correct usage is to read data from them and replace ObjectLayers with your own custom layers. I know this isn't obvious and I've been trying to take steps to make new users more aware of it.

Do you think you could elaborate more on this? I'm quite new to lua, love, games and ATL so I'm not sure what the best practices are for many things (yet!)
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

KingRecycle
Prole
Posts: 44
Joined: Thu May 24, 2012 1:01 am

Ahh nice. Yeah, subtracting mouse position from translation does work.

Now to figure out how to detect if the cursor is within a specific tile.

Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Whenever you load the map just convert all object data into your own objects. Then you replace the object layers with your own custom layers.

Code: Select all

-- Load the map

-- Go through every layer
for position, layer in pairs(map.layerOrder) do

-- If you find a layer that is an object layer then we convert it
if layer.class == "ObjectLayer" then

-- Remove the layer from the map
table.remove(map.layerOrder, position)
map.layers[layer.name] = nil

-- Create a custom layer with the same name and position as the old
local customLayer = map.newCustomLayer(layer.name, position)
customLayer.objects = {}

-- Convert each object into your own object types
for index, object in pairs(layer.objects) do
customLayer.objects[index]  = newClass(object.name, object.x, object.y, object.properties)
end

-- Have the custom layer draw the objects
function customLayer:draw()
for k, object in ipairs(customLayer.objects) do
object:draw()
end
end

-- Have the custom layer update the objects
function customLayer:update(dt)
for k, object in ipairs(customLayer.objects) do
object:update(dt)
end
end
end

-- Forward the love callbacks to the layers
function love.update(dt) map:callback("update", dt) end
function love.draw() map:draw() end
Alternatively you can do an in-place conversion and avoid the custom layer.

Code: Select all

-- Load the map

-- Go through every layer
for position, layer in pairs(map.layerOrder) do

-- If you find a layer that is an object layer then we convert it
if layer.class == "ObjectLayer" then

-- Convert each object into your own object types
for index, object in pairs(layer.objects) do
layer.objects[index]  = newClass(object.name, object.x, object.y, object.properties)
end

-- Change the draw function
function layer:draw()
for k, object in ipairs(customLayer.objects) do
object:draw()
end
end

-- Define the update function
function layer:update(dt)
for k, object in ipairs(customLayer.objects) do
object:update(dt)
end
end
end

-- Forward the love callbacks to the layers
function love.update(dt) map:callback("update", dt) end
function love.draw() map:draw() end
This is so you can have exact control over the ways your objects and layers work.
KingRecycle wrote:Ahh nice. Yeah, subtracting mouse position from translation does work.

Now to figure out how to detect if the cursor is within a specific tile.
dividing the position by the tilesize and then flooring it should work.

gregkwaste
Prole
Posts: 19
Joined: Fri Aug 31, 2012 8:32 am

gregkwaste wrote:i had a very stupid problem trying to move some objects in an object layer , i just now i concluded that it was not due to faulty code. The way that the code iterates in the object tables follows the exact same way that the user enters the tiles in tiled. That is very annoying because it forces you to replace all the objects from the beginning if you want to move them with a specific order (just as i do...). It would be a lot nicer if the loader loaded somehow sorted the objects by their map position.
That problem seems very specific. You can always just sort the objects yourself after you load the map.

Code: Select all

function sortByPosition(a, b)
if a.y == b.y then return a.x < b.x end
return a.y < b.y
end

for name, layer in pairs(map.layers) do
if layer.class == "ObjectLayer" then
table.sort(layer.objects, sortByPosition)
end
end

wow, seems a good way to work around . Thanks

Uhfgood
Prole
Posts: 35
Joined: Sat Jul 28, 2012 10:04 pm
Location: Oregon, US
Contact:

Thanks for making this available. Forgive me if I missed it somewhere in the thread but I have a few questions here.

Can you achieve a parallax effect with multiple layers with the loader, or is that something you have to do manually (either by creating separate maps for the parallaxing, or manipulating layer offsets directly).

I want to actually flip the whole map in the game, so is there a way i could do this? (So that tiles that are on say the left hand side of the screen are now on the right, also with the individual tiles flipped, like if the tiles on the left hand side of the screen formed an arrow that pointed to the right, when you flipped, the arrow tiles would be on the right side pointing to the left)

Thirdly can you only load in portions of a (tmx) map file?

Edit: I also wanted to ask real quick about "skinning" ie changing out tilesets (say you want to do day to night on the same tilemap but with different tileset)

Karai17
Party member
Posts: 909
Joined: Sun Sep 02, 2012 10:46 pm

Is there any particular reason why ATL indexes form 0 instead of 1? The lua convention is to index from 1 and trying to match ATL with other relevant libraries has been a bit of a nightmare with #infinity-1 off-by-1 errors. Would it not be better for ATL to match lua's convention and play nicely with everyone else?
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Uhfgood wrote:Thanks for making this available. Forgive me if I missed it somewhere in the thread but I have a few questions here.

Can you achieve a parallax effect with multiple layers with the loader, or is that something you have to do manually (either by creating separate maps for the parallaxing, or manipulating layer offsets directly).

I want to actually flip the whole map in the game, so is there a way i could do this? (So that tiles that are on say the left hand side of the screen are now on the right, also with the individual tiles flipped, like if the tiles on the left hand side of the screen formed an arrow that pointed to the right, when you flipped, the arrow tiles would be on the right side pointing to the left)

Thirdly can you only load in portions of a (tmx) map file?

Edit: I also wanted to ask real quick about "skinning" ie changing out tilesets (say you want to do day to night on the same tilemap but with different tileset)
A lot of those effects would be hard to do currently but I think adding support for them wouldn't be too difficult. I will try working on it tomorrow. I'll post again later with more specifics.
Karai17 wrote:Is there any particular reason why ATL indexes form 0 instead of 1? The lua convention is to index from 1 and trying to match ATL with other relevant libraries has been a bit of a nightmare with #infinity-1 off-by-1 errors. Would it not be better for ATL to match lua's convention and play nicely with everyone else?
Yes. It's to match up with the tile locations inside Tiled. ATL actually use to index from 1 and it was very confusing. What sort of libraries are you talking about?

Karai17
Party member
Posts: 909
Joined: Sun Sep 02, 2012 10:46 pm

The one I am specifically talking about is a pathfinding library, located here: viewtopic.php?f=5&t=9322&p=67103#p67103

As you can see in this image, my collision map is offset by 1 on both the x and y axes. So to properly detect collisions for my path finding, I need to add 1 to x/y of my player and the x/y of my monster(s) to match up with my collision map. After the path is generated, I need to then remove 1 form the x/y of those same entities to actually move along the path on the actual map. A bit of a headache and I still don't have it working

In contrast, if ATL were to follow lua convention and index from 1, There is only a single point of reference which needs to be offset, much like traversing an array in nearly any other language that uses index offsets (start from 0).
Last edited by Karai17 on Wed Oct 03, 2012 10:49 pm, edited 1 time in total.
STI - An awesome Tiled library
LÖVE3D - A 3D library for LÖVE 0.10+

Dev Blog | GitHub | excessive ❤ moé

SudoCode
Citizen
Posts: 61
Joined: Fri May 04, 2012 7:05 pm

Uhfgood wrote: Edit: I also wanted to ask real quick about "skinning" ie changing out tilesets (say you want to do day to night on the same tilemap but with different tileset)

You'd probably be better off using pixel effects for this.

Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Karai17 wrote:The one I am specifically talking about is a pathfinding library, located here: viewtopic.php?f=5&t=9322&p=67103#p67103

As you can see in this image, my collision map is offset by 1 on both the x and y axes. So to properly detect collisions for my path finding, I need to add 1 to x/y of my player and the x/y of my monster(s) to match up with my collision map. After the path is generated, I need to then remove 1 form the x/y of those same entities to actually move along the path on the actual map. A bit of a headache and I still don't have it working

In contrast, if ATL were to follow lua convention and index from 1, There is only a single point of reference which needs to be offset, much like traversing an array in nearly any other language that uses index offsets (start from 0).
The only time I can think of where not starting from 1 in lua would be a problem would be when you're using simple arrays as lists. That's because Lua table functions, the # operator, and ipairs will not work properly if you have indexes outside of [1, n+1]. Spacial data structures do not need those so I'm having difficulty understanding where starting from 0 would be a problem.

Actually, taking a look through the Jumper library it seems like the maps have to be fixed dimensions starting from (1,1). It could probably gain a lot from being boundless but that's not my call.

Like I said, ATL use to start tile indexes at (1,1) and that was very confusing since it did not line-up with Tiled. It was frustrating for the exact reasons you are mentioning. You had to take 1 off every time you needed to access a tile.

A possible work-around for you would be to move every tile by +1 x and +1 y once the map is loaded. Or you could just start building your map from (1,1) inside Tiled itself.

Code: Select all

-- Untested code
map.width = map.width+1
map.height = map.height+1
for k,layer in pairs(map.layers) do
if layer.className == "ObjectLayer" then
for k, obj in pairs(layer.objects) do
obj.x = obj.x + map.tileWidth
obj.y = obj.y + map.tileHeight
end
elseif layer.className == "TileLayer" then
local cells = {}
for x,y,tile in layer:iterate() do
if not cells[x+1] then cells[x+1] = {}
cells[x+1][y+1]  = tile
end
layer.cells = cells
end
end

### Who is online

Users browsing this forum: No registered users and 30 guests