Hello, I have a group of images that represent a world map in my game. In my game, the player is focused in on a particular country at a time with the country positioned in the center of the screen. After a short period of time, another country is chosen. I’ve created coordinates (in cf_game_settings.lua) for each country and some math code in game.lua that use these coords to determine how much to move the map group in the x and y directions.
The next code that I’m working on creates the illusion that the player is getting further from and then closer to earth as the country changes. I’m running into some issues here… In the code you’ll see my attempt to manipulate two properties simultaneously:
-
change that map group’s x and y values.
-
scale the map group’s size (up and down)
To help me do this, I have chained two transition.to() functions together, thus creating a two-part movement.
In the first transition.to() I set the x and y values, moving the map group so that the halfway point between the two countries is centered on the screen. To increase the size of the map group I use a multiplier.
In the second transition.to() I set the x and y values, moving the map group so that the next country is centered on the screen. With the multiplier, I return to the map group’s original size.
I’ve made a video to show you what I currently have! I’m proud of myself for getting this far on my own, but I’m aware that there are some issues - mainly that the scaling of the map group throws off the accuracy of the math used to determine the values that x and y will be set to. Because of this, the map group seems to move way out of its way, especially when moving between two countries that are close to one another. Even more so, if the randomly selected country happens to be the current country, the map group is moved so that the country moves away from the center of the screen before coming back to the center.
Here’s the code:
cameraevent.lua
local cameraEvent = {} function cameraEvent.focus(transitionToCountryDuration, country, countryFill, previousCountry, previousCountryFill, mapGroup) local transitionToCountryDuration = transitionToCountryDuration local country = country local countryFill = countryFill local previousCountry = previousCountry local previousCountryFill = previousCountryFill local mapGroup = mapGroup local zoomMultiplier = .3 local xCoord=(\_W/2)-(country.coords.x\*zoomMultiplier)-((countryFill.width\*zoomMultiplier)/2) local yCoord=(\_H/2)-(country.coords.y\*zoomMultiplier)-((countryFill.height\*zoomMultiplier)/2) local previousXCoord=(\_W/2)-(previousCountry.coords.x\*zoomMultiplier)-((previousCountryFill.width\*zoomMultiplier)/2) local previousYCoord=(\_H/2)-(previousCountry.coords.y\*zoomMultiplier)-((previousCountryFill.height\*zoomMultiplier)/2) local distanceX = xCoord - previousXCoord local distanceY = yCoord - previousYCoord print(distanceX) print(distanceY) zoomMultiplier = .24 local mapTimer = transition.to( mapGroup, { transition=easing.inCirc, time=transitionToCountryDuration/2, x=mapGroup.x + distanceX/2, y=mapGroup.y + distanceY/2, xScale=1\*zoomMultiplier, yScale=1\*zoomMultiplier, onComplete=function(event) zoomMultiplier = .3 mapTimer = transition.to(mapGroup, { transition=easing.inCirc, time=transitionToCountryDuration/2, x=xCoord, y=yCoord, xScale=1\*zoomMultiplier, yScale=1\*zoomMultiplier }) end }) end return cameraEvent
I’d be super thankful to anyone willing to take a shot at this as I know that it is a huge chunk of my game hahaha and probably not such an easy feat either.