relative position of a object

I have a map built that is very large. I am trying to integrate the particle candy product into the map to add smoke and fire in places. The problem that I am trying to fix is that the objects in particle candy are place by relative position to the screen, not the absolute position on the map.

I have objects setup as Spawn points for the effects, I just need to be able to convert their world coordinates to relative screen coordinates. I see conversion utilities to go the other way, but nothing that would help me bring it back.

I grab my objects

1
2
3
4
5
6
-- Load the map
local map = lime.loadMap("Chapter 1.tmx")
local objectlayer = map:getObjectLayer("Player Objects")
local stack1 = objectlayer:getObject("Nuclear Stack 1")
local stack2 = objectlayer:getObject("Nuclear Stack 2")
local stack3 = objectlayer:getObject("Nuclear Stack 3")

I've not had a chance to play with Particle Candy yet however am I right in thinking that a worldToScreenPosition function would fit the bill?

I believe so. I am assuming that would give me the relative position of my object.x and object.y from the x and y origin of the current viewable screen. Then when my x dips below 480 (landscape view of the game), I can enable the emitters and run a main() loop changing emitter position along side the object position to have them map up.

I assume/hope so too :-) I will give it a try now and report back.

It is nearly 3am so I can't fully guarantee this will work but add it into lime-utils.lua and give it a whirl :-)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
--- Converts a world position into a screen position
-- @param map The current Map.
-- @param position The world position.
-- @return The screen position.
function worldToScreenPosition(map, position)
 
        local newPosition = {}
        
        if map.world then
                newPosition.x = position.x - map.world.x
                newPosition.y = position.y - map.world.y
        end
        
        return newPosition
end

On second thought, I don't think that will work. I will look at it again after some sleep.

Cheers

no rush at all

Ok so I got it to work. Not sure if I am going about it in the most efficient way, but after running the bloody thing about a million times, the code is bound to be a little sloppy.

So...first I load the map and get my objects

1
2
3
4
5
6
-- Load the map
local map = lime.loadMap("Chapter 1.tmx")
local objectlayer = map:getObjectLayer("Player Objects")
local stack1 = objectlayer:getObject("Nuclear Stack 1")
local stack2 = objectlayer:getObject("Nuclear Stack 2")
local stack3 = objectlayer:getObject("Nuclear Stack 3")
views:1740 update:2011/10/13 16:39:51
corona forums © 2003-2011