Level Director & Camera / Viewport problem

Hi guys

I have built a level using the retro productions Level Director and can get it to run / reference objects directly from the layers etc. and pretty much do most of what I need to do with the level bar one annoying but fundamental task… I can’t for the life of me figure out how to get the viewport or “camera” to follow my player?

I have looked at the demo’s and they all seem to focus on moving the entire surrounding levels rather than the main player itself?

Am I missing something, or should I move on from using this particular tool, I can’t believe you have to move the ‘world’ rather than just have the viewport focus on the player movement?

Any advice / tips would be greatly appreciated!

Cheers

Chuck

In Corona there’s no “camera” object that I know of, and no way to choose specific coordinates to render. Meaning that you do have to move at least the stage group to show other parts of the view.
Since the coordinates inside a group do not change though, this shouldn’t be much of a problem (only the origin of that group would change, without messing up anything else).

Thanks Hachisoft, not really the answer I was looking for, I think I’ll need to look into how groups with Level Director work more closely.

Thanks for your input, much appreciated :slight_smile:

Hi guys, just thought I’d give an update on this post for any of the other newbies out there that may come across a similar issue as this.

Before you re-invent the wheel, check out Caleb’s awesome code for a ‘virtual camera system’. It pretty much saved me days of work trying to figure out a tracking system / camera behaviour! 

http://code.coronalabs.com/code/perspective-virtual-camera-system

Thanks Caleb, you are a legend :wink:

i fully agree. i also love his library.

Hi Chuck,

i just tried the new Version from your link and it seems not to work. I get an error for the code map.xScale and yScale. “map” seems not to be defined and is nil. Do you know what i am doing wrong?

P.S. I also just tried the demo and it is also not working. Perhaps i am to silly to download the code. The error is here:

camera:add(scene[i], math.random(2, camera:layerCount()))

camera:layerCount() seems not be defined in perspective.lua

Cheers

Hi Toga

Have you added the layers and started the tracking yet? Seems like you are tying to search for layers that have not yet been added to the display group i.e. the camera?

Thanks for your answer. I also tried the Perspective Demo (main.lua) which is also on GitHub and it is also not working. I also can not see the Definition of camera:layerCount() in the perspective.lua file on GitHub. Is the demo running on your simulator?

You do not need to use the Perspective library if you’re using level director because you are already adding your objects to layers within the designer and LD exports everything for you, even the parallax speeds of each layer.

Perspective also does not work when physics are involved whereas the LD library does, LD also has the ability to wrap the layers. 

All you need to do is call myLevel:move(dx,dy)

See this example : http://bit.ly/MNPtpA  (requires Graphics 2.0 build)

Thanks Reto - I had a look at the potty bird demo, and it seems straight forward for moving layers at a constant speed, however how would you calculate the Y-axis when using physics & gravity to obtain a mario style feel?

I’ve tried however the behaviour is inconsistent and my player repeatedly falls through on floor collisions.

Hi Retro

I managed to get the Y axis sorted using the move function however I find the Perspective library far smoother at tracking, I find using the level director parallax a bit jittery for want of a better description especially on the y axis, perhaps a lack of dampening? There also seems to be a small bug with the wrapping of layers in that if the image is smaller than the screen size, it won’t wrap until the last image is completely off screen, leaving gaps in the display? stopping movement sometimes leaves a blank screen too, depending on where you are during the wrap phase.

Additionally I’ve managed to get full physics working along with the perspective library, merely tracking the main player who has full physics / collisions set up, so I’m not sure what the limitations are as far as physics goes with perspective but it seems to be working great for me.

Don’t get me wrong your tool is a great level builder, but it’s lacking in a few key areas for me so before I part ways with my cash, I’ll stick with the demo and use perspective in the interim :wink:

Thanks again for the advice on the move functionality!

Hi adrian,

I’m glad you got it sorted.

I think the jittery scroll in the move function (LD_Helper) is caused by this line;

local dt = LD\_Helper:instance():getDeltaTime()

This change should resolve it;

local dt = 1

With regards to the wrap issue I cannot reproduce your symptoms, I would appreciate if you could email me your example even though you may not continue with Level Director.

I will take some tips from Perspective and include them into Level Director but I noticed it moves layers not objects so does not support wrapping, and last time I looked Box2d/Corona SDK does not move the physics shapes if you move the layer/display group, but maybe this has changed.

Thanks

Thanks Retro - seems resetting the dt to 0.8 had the desired effect and it’s working nicely now :slight_smile:

I will send you an example of the project where the wrap is not working correctly - maybe it’s something to do with my settings, thanks again LD is looking very promising now!

Cheers

Adrian

Hello!

Glad people are using Perspective… Is the layerCount() issue still occurring? Not sure what’s happening… the :layerCount() function is declared on line #261. Unless you’re using a previous version, it should work without a hitch.

  • C

Hi Caleb,

i am using Perspective and i also love it. For me it is the best library for Corona concerning scrolling and tracking a player :-)

The problem with :layerCount() is not existing anymore. I think i had a bad timing and downloaded a early version (some days ago) which was incorrect.

I don´t know if the new version 2.02 should completely replace the 1.4.2 Version, but if that should be the case, it is not 100% compatible. I also use your libary for Pinch zoom and pan map functionality in my app. Therefore i only start the auto tracking with camera:track() WITHOUT setting any focus with camera:setFocus(Player).

When i start auo tracking my Screen snaps immediately to another position. For example if i print out scrollX and scrollY in the old Version i get 0, 0. But if i do it in the new version i get the values from display.contentWidth and display.contentHeight. I didn´t investigated it deeper. I only replaced the 1.4.2 Version with the 2.02 Version. Perhaps i have to do something different.

Kind regards,

If what you want is to focus on 0,0, you might want to just call

[lua]

camera:toPoint(0, 0)

[/lua]

  • C

In Corona there’s no “camera” object that I know of, and no way to choose specific coordinates to render. Meaning that you do have to move at least the stage group to show other parts of the view.
Since the coordinates inside a group do not change though, this shouldn’t be much of a problem (only the origin of that group would change, without messing up anything else).

Thanks Hachisoft, not really the answer I was looking for, I think I’ll need to look into how groups with Level Director work more closely.

Thanks for your input, much appreciated :slight_smile:

Hi guys, just thought I’d give an update on this post for any of the other newbies out there that may come across a similar issue as this.

Before you re-invent the wheel, check out Caleb’s awesome code for a ‘virtual camera system’. It pretty much saved me days of work trying to figure out a tracking system / camera behaviour! 

http://code.coronalabs.com/code/perspective-virtual-camera-system

Thanks Caleb, you are a legend :wink:

i fully agree. i also love his library.