How can I get RTS map panning like how it was done in C&C red alert (with the mouse at the edge of the screen moves the screen in that direction) with a Babylon.js RTS game in the html canvas? This would be simple should I force the game to be full screen, but I don't think this would be practical.

I was thinking of checking that the mouse is near the edge of the canvas to pan but this could be annoying for the user. Perhaps I could force the mouse to be in the bounds of the canvas (in non fullscreen mode) until the user presses some shortcut key, but again I could be breaking the browser experiance.

Your advice?

  • \$\begingroup\$ I don't work with html5, but why not create a field around the canvas which would act as a sort of scroll area. If the mouse is in that field then act as if it touches a border and start scrolling. \$\endgroup\$ – Eejin Jan 3 '15 at 19:41
  • \$\begingroup\$ @Eejin I am aware of that one but I don't like having to be that precise with the mouse. I feel its better to flick it to the 'edge' and have it scroll. \$\endgroup\$ – Nikos Jan 3 '15 at 20:49
  • \$\begingroup\$ What about treating everything outside the canvas as "border" until you actually click there? Otherwise locking the mouse would be the best decision. \$\endgroup\$ – Eejin Jan 3 '15 at 22:37
  • 1
    \$\begingroup\$ @Eejin I like that idea.. could work well if I have a fluid canvas anyway to maximse its size. \$\endgroup\$ – Nikos Jan 3 '15 at 22:46

VirtualBox has a fantastic solution to this problem -- they lock your cursor inside the window, if you press the control key, in my case that's cmd. You have proposed this and I would deffinetly advise for it.

An example implementation of this would be, the user clicks on the game window and everything else darkens, to create the illusion of them being in the letterbox. When the user hits esc for menus or maybe even the lock-in key, turn the lights back on, to express the change.

There really isn't any other way of making an engaging RTS game, without screen panning. And since that is the usual case, players would be used to it already.

If you absolutely want to cater to everyone, I would also add a lock-less edge pan, but I, as a user, would be against that as it feels incredibly clunky.

  • \$\begingroup\$ Yeah, I like this approach alot! \$\endgroup\$ – Nikos Feb 9 '15 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.