Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Stop camera follow at certain point
Started by hi1 Apr 10 2017 09:05 AM

1 reply to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

hi1

[GLOBAL: userInfoPane.html]
hi1
  • Observer

  • 21 posts
  • Corona SDK

Hi,

 

I am working on a grid based game where a player moves along a grid-like board. The board is a big larger than the display size of the screen, which makes it necessary to have the camera follow the main player. However, when the user reaches one of the sides of the board (top/bottom/left/right), much of the board is cut off due to the object always being centered.

 

While looking through the perspective library, I have not found any specific modules to make it so that the camera has max follow ranges. Is there any way to add a max value to the camera so once it reaches a certain point rather than centering the follow object on the screen, it goes a bit off center to retain other parts of the scene?

 

If you need any more clarification, please let me know (I understand it is a tad bit confusing to explain).

 

Thanks.



[TOPIC: post.html]
#2

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,943 posts
  • Corona SDK

What you need is math.clamp.  This doesn't exist as standard but you can use this

function math.clamp(value, low, high)  
    if low and value <= low then
        return low
    elseif high and value >= high then
        return high
    end
    return value
end 
Basically you set the bounds for the camera as low, high and then track the player x,y with value.  This will ensure the camera never exceeds the bounds you set for it. Obviously call it for both x and y axis.



[topic_controls]
[/topic_controls]