Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Camera to follow rpg topdown character, but how?
Started by IndieEnthusiast Jul 07 2018 08:41 AM

1 reply to this topic
[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 154 posts
  • Corona SDK

Hi,

 

After spending some frustrating hours, I am resorting to asking in this forum for opinion of experts out there.

I have a map.json file and I am using Berrys Tiled engine to load it.

 

How to make sure the camera follows the character ?

 

- The character when moves to the right, the camera should follow it

- Similar behavior when character moves up or down

- The map.x should move opposite to the direction of player.x so that there is a feeling that the camera is on the character

 

But how exactly to do it?

 

I tried :

local function movecharacter (event)
myAnimation.x = myAnimation.x + motionx;
myAnimation.y = myAnimation.y + motiony;
 
if (myAnimation.x > 300) then
  camera.x = myAnimation.x + display.contentCenterX
end
camera.y = myAnimation.y - display.contentCenterY
 
 
print (camera.x)
 
end
Runtime:addEventListener("enterFrame", movecharacter)
 
the map moves out of the left edge...and moves with the character...confused..how to implement this.


[TOPIC: post.html]
#2

IndieEnthusiast

[GLOBAL: userInfoPane.html]
IndieEnthusiast
  • Contributor

  • 154 posts
  • Corona SDK

Nevermind solved it using, map was going the other way and also set a limit to what width the map should move :
 
if (myAnimation.x > 160 and myAnimation.x < visual.width-220) then
  camera.x = display.contentCenterX - myAnimation.x
end
 
if (myAnimation.y < 155) then
  camera.y = display.contentCenterY - myAnimation.y - 180
end
 
--print (myAnimation.y)
end
Runtime:addEventListener("enterFrame", movecharacter)
 
 
But noticed that the game was crashing...quite a lot when using runtime listener



[topic_controls]
[/topic_controls]