[Resolved] Rotating groups and adding objects

Hello,

I am working on a game where I sometimes have to add objects to a group. Because the objects have to rotate together.
But when the group is already rotated, when I add a new object to the group, it will not be placed in the group on its current position. But on the position in the group where it would be if it was rotated with the group.

But I want those objects to be added to the group on the position where I put them even when the group was rotated already. Does anyone have any tips on how I could handle this in a different way?

I hope this is a good explanation. Otherwise please ask me to clear it up. unfortunatly I cannot post any screenshots or gameplay examples because im working with an NDA.

Thanks in advance

Alexander [import]uid: 118839 topic_id: 33378 reply_id: 333378[/import]

Lets say that you are adding the object “obj” to the group “grp” and doing this in a ‘tap’ event listener, so the location you want to add the “obj” is precisely where the user tapped the screen…

[lua]-- tap event listener
– param: e.x and e.y are the location on the screen where the user tapped, relative to stage 0,0
function tap(e)
local obj = createObject() – go create an object to be added where the user tapped
grp:insert( obj ) – add the new object to the group

– this is the magic bit you’re looking for…
– convert the tap location to a location in the group and set the object to that location
obj.x, obj.y = grp:contentToLocal( e.x, e.y )

return true – always return true from tap listeners
end

– add tap listener
Runtime:addEventListener(“tap”,tap)[/lua]

Please note that I have written this off the top of my head. Some debugging may be required. Please complain if it really won’t work and I’ll get it working locally. [import]uid: 8271 topic_id: 33378 reply_id: 132580[/import]

Thanks!! That worked perfectly :slight_smile: [import]uid: 118839 topic_id: 33378 reply_id: 132584[/import]

Lets say that you are adding the object “obj” to the group “grp” and doing this in a ‘tap’ event listener, so the location you want to add the “obj” is precisely where the user tapped the screen…

[lua]-- tap event listener
– param: e.x and e.y are the location on the screen where the user tapped, relative to stage 0,0
function tap(e)
local obj = createObject() – go create an object to be added where the user tapped
grp:insert( obj ) – add the new object to the group

– this is the magic bit you’re looking for…
– convert the tap location to a location in the group and set the object to that location
obj.x, obj.y = grp:contentToLocal( e.x, e.y )

return true – always return true from tap listeners
end

– add tap listener
Runtime:addEventListener(“tap”,tap)[/lua]

Please note that I have written this off the top of my head. Some debugging may be required. Please complain if it really won’t work and I’ll get it working locally. [import]uid: 8271 topic_id: 33378 reply_id: 132580[/import]

Thanks!! That worked perfectly :slight_smile: [import]uid: 118839 topic_id: 33378 reply_id: 132584[/import]