Camera bad performance

Hi!

In my game the user can scroll the camera.
However, the scrolling is choppy.

I have my custom Camera object in a GameObject. I change the position of the GameObject holding the camera when I scroll. Like this:

local toMove=dt*CAMERA_SPEED          -- I've tried varying the speed, doesnt help
pos.x=pos.x-toMove
go.set_position(pos)

For some reason this results in a choppy movement of the camera. Spine-animations, sprite-animations and everything else is running just fine without any lag. Any thoughts?

Can you give a bit more details on how you animate the camera. From an update() function?

Yes, this happens in update().
There is not much else. The process:

1) The GameObject holding the camera receives input and internally saves the position of the cursor.
2) The update method reads the variable and checks if the cursor is near an edge and moves the camera as I described in the post above.

Is your level far from origo? Check @Andreas_Jirenius answer it this thread if it seems like your problem: FPS problem testing in Android

not far, but I have a large resolution 1920x1080, I will try altering the VP

Which material should I change? The Camera-Object has no option for material…
Should I change all the regular “sprite” materials?
@Andreas_Jirenius @sicher

It’s the sprite material. Try creating one GO with a sprite with that new material and see if it behaves correctly.

1 Like

I have only Spines and a Tilemap and I’ve tried changing both. It didn’t help.
The issue is only visible in the HTML5 version. I guess it has to do with performance, but it’s strange that everything else is animating and moving just fine.

The resolution wasn’t the problem. Scrolling is still a bit choppy even with a smaller resolution in HTML5

Yes, that is strange. Does it matter what browser you run the game in?

1 Like

GOOD POINT!
It works perfectly in Chrome but lags in Safari.
It’s so pretty in Chrome now :smiley:

I guess there is not much I can do then to make it work in Safari? @sicher @britzl @Andreas_Jirenius

The strange thing is that you say that spine animations and so on are not lagging. I can’t understand why spine and sprite animations are running at high fps while the camera movement is choppy and only in Safari. This, to me is a mystery. Could you please launch the desktop version of your game and bring up the web profiler, take a screen shot and share it with us? I’d also like to get some input from @Ragnar_Svensson or @Andreas_Tadic.

Here is the profiler while scrolling.

There’s no noticeable lag in any of the Spine animations and I can command other GOs to move on the screen by using the mouse and they will move perfectly fine.

BUT as soon as I start scrolling it scrolls choppy in Safari. The scroll-logic is minimal - it just reads the mouse-coordinates and moves the camera (as I wrote above).

The scrolling lag in Safari is there even if I remove all of the game and just leave a couple of GOs.

@britzl

I wonder if it might be related to input handling in Safari. If you get choppy input that might affect the movement depending on your implementation. I’ll try to run some tests when I get the time.

@sicher I doubt it, I’ve tried just moving the camera to the left on each update loop and it scrolls choppy even when it’s just scrolling on its own. I’m making a small reproduction of the bug and will try to demonstrate it in action.

Yes, please try to make a minimal example project of the issue and please share it with us!

I can take a look if you can share a project as suggested. It’s likely nothing to do with performance given everything else is moving smoothly. I’ve also tried running some of our own examples using camera, and it works fine in Safari.

Some hints, although more a case of sanity checking…

  • The “dt” variable I assume is the (unmodified) update function parameter (it should be ~0.016 running at 60 fps, try printing it…).
  • CAMERA_SPEED is unmodified (static)
  • The game object position is not influenced anywhere else (e.g a message in another script or relative to another object).

Yes I think it’s better if I invite you.
I tried reproducing but it didn’t behave the same way…

What email should I add? @Andreas_Tadic

How do I print when debugging HTML5 version? I checked the browser console, but it’s empty.

andreas.tadic@king.com will do fine.