Proper way to implement a camera?

51 views
Skip to first unread message

R Blau

unread,
Mar 22, 2018, 4:39:54 PM3/22/18
to StageXL
What's the suggested way to implement a large 2D space that can be panned through?

I achieved it with stage.setTransform(..) and it feels nice, but I noticed that Mouse Events for objects on that stage don't work as they should. The clicking area stays on its original place when I move away the viewport.

Is this a bug? Am I missing something here?

Bernhard Pichler

unread,
Mar 23, 2018, 1:29:21 PM3/23/18
to R Blau, StageXL
Hi,

Do you want to pan the whole stage, or only a smaller part of the stage (like window)?

If you only want to pan a smaller part, you can use the ViewportContainer display object.
https://github.com/bp74/StageXL/blob/master/lib/src/display_ex/viewport_container.dart

If you want to pan the whole stage it is very easy:

var panningSprite = new Sprite();
stage.addChile(panningSprite  );

now add all your display objects to the panning sprite and move it:
panningSprite.x = 100; 
panningSprite.y = 200;  

hope this helps,
Bernhard




--
You received this message because you are subscribed to the Google Groups "StageXL" group.
Visit this group at https://groups.google.com/group/stagexl.
To view this discussion on the web visit https://groups.google.com/d/msgid/stagexl/e91c91e3-2fa5-465e-809f-6a60c6347723%40googlegroups.com.

R Blau

unread,
Mar 23, 2018, 3:00:44 PM3/23/18
to StageXL
Yeah, that's exactly what I needed (to pan the whole stage). Thank you very much!

Certainly looking forward to work with this library. Seems very promising so far. 
Reply all
Reply to author
Forward
0 new messages