Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

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

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


[GLOBAL: userInfoPane.html]
  • Observer

  • 21 posts
  • Corona SDK



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).



[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Corona Geek

  • 2,219 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
    return value
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.