positions on a zoomed-in enviroment

Hi there!

So let me explain my problem: in my game, whenever a character attacks another, the game zooms in on them (using this method here: http://developer.coronalabs.com/forum/2012/12/19/zoom-effect) after the attack is done, the game zooms back out. that works great

However, I ran into a problem when adding special effects, numbers and other things.

When the game is Zoomed-In Corona preserves the same position of all elements. It means that, for example, a character that was at x=250 y=250 before the zoom its still registered to be at the same coordinates during the zoom even if he looks to be elsewhere. so, if i try to put something on top of the character it shows at the wrong place.

I’m pretty sure there is a mathematical way of telling where the actual sprite is, but to my shame I just cant figure it out.

I hope my problem is understandable, I tried to include pictures, but I’m not allowed to show screenshots.

[import]uid: 136402 topic_id: 35510 reply_id: 335510[/import]

Are you adding the new images to the zoomed display group? [import]uid: 93133 topic_id: 35510 reply_id: 141107[/import]

It’s been a long day so I’m afraid I can’t think of the exact answer for you, but I would think you need to adjust the position of the new object using the inverse of the xScale and yScale of the display group that you zoomed into.

So if you already have

player.x=250
player.y = 250

then zoomed in using

myGroup.xScale = 2
myGroup.yScale = 2

You have doubled the size of the display group.
If you want to place the new object in the same place as the player you need to place it at:

newObject.x = player.x / myGroup.xScale
newObject.y = player.y / myGroup.yScale

As I say I don’t think this is exactly right, but I think the principle is roughly correct. I’ve probably forgotten to take into consideration something like the world coordinates.

Hopefully this helps you find the answer though :slight_smile:

Edit: just looked at nick_sherman’s again answer afterwards, and I think his idea is also correct. If you put the new object into the same display group as the other zoomed out objects, it’s position will be relevant to the display group. In which case you can then set it’s position based on whatever object in the group you want it to appear near (e.g. the player). [import]uid: 84115 topic_id: 35510 reply_id: 141231[/import]

Thanks for the replies! :slight_smile:

I ended up following Nick’s advice, tho I didn’t want to at first. The effects I wanted to add also change scale, so having them change scale while being scaled by the Zoom seemed really confusing at first. But I’m making it work for now.

[import]uid: 136402 topic_id: 35510 reply_id: 141255[/import]

Are you adding the new images to the zoomed display group? [import]uid: 93133 topic_id: 35510 reply_id: 141107[/import]

It’s been a long day so I’m afraid I can’t think of the exact answer for you, but I would think you need to adjust the position of the new object using the inverse of the xScale and yScale of the display group that you zoomed into.

So if you already have

player.x=250
player.y = 250

then zoomed in using

myGroup.xScale = 2
myGroup.yScale = 2

You have doubled the size of the display group.
If you want to place the new object in the same place as the player you need to place it at:

newObject.x = player.x / myGroup.xScale
newObject.y = player.y / myGroup.yScale

As I say I don’t think this is exactly right, but I think the principle is roughly correct. I’ve probably forgotten to take into consideration something like the world coordinates.

Hopefully this helps you find the answer though :slight_smile:

Edit: just looked at nick_sherman’s again answer afterwards, and I think his idea is also correct. If you put the new object into the same display group as the other zoomed out objects, it’s position will be relevant to the display group. In which case you can then set it’s position based on whatever object in the group you want it to appear near (e.g. the player). [import]uid: 84115 topic_id: 35510 reply_id: 141231[/import]

Thanks for the replies! :slight_smile:

I ended up following Nick’s advice, tho I didn’t want to at first. The effects I wanted to add also change scale, so having them change scale while being scaled by the Zoom seemed really confusing at first. But I’m making it work for now.

[import]uid: 136402 topic_id: 35510 reply_id: 141255[/import]