Camera movement for a strategy game

Software: Away3D 4.x

DinkMcDinkleman, Newbie
Posted: 17 March 2012 07:59 PM   Total Posts: 30

All,

I’m abstracting in my mind how I’d like to try and implement camera movement similar to games such as WarCraft II/III or StarCraft, where the camera moves along the x/y when the mouse reaches certain regions of the screen.

The best I can come up with is to divide the edges into eight areas.  Four corners and four sides.  If the mouse is in a corner the camera moves in the x and y directions, if on a side, only the x or y direction.

How I’m wanting to do this would be invisible planes.  If the mouse moves over the plane, it will cause the camera x and or y values to change accordingly.  Is there a better way of doing this?

Thank you!

   

Alex Bogartz, Sr. Member
Posted: 17 March 2012 08:32 PM   Total Posts: 216   [ # 1 ]

Yeah, just listen for mouse movement or check the mouse X and Y in your enter frame loop.

If x<blah, do this, if y>foo, do that.

   

inSertCodE, Sr. Member
Posted: 18 March 2012 03:31 PM   Total Posts: 105   [ # 2 ]

Why Invisible planes? Add the listeners scroll to the Stage, not to in-game objects.
Another thing I did is add an small invisible plane 1x1 and have the camera follow it. Then to move/rotate the camera I just temper with the plane.

   

DinkMcDinkleman, Newbie
Posted: 20 March 2012 01:08 AM   Total Posts: 30   [ # 3 ]

So, I can do this very easily with if statements.  However, where I have a problem is if I want to place UI elements at the top or bottom of the stage, as well as limiting the camera’s x and y range so the user never scrolls “off-world”.  The conditional becomes a little large for my liking.  Wouldn’t a large conditional executed every frame really slow things down?

@inSertCodE

Add the listeners scroll to the Stage

Unless I’m missing it, I don’t really see that there are built-in “scroll listeners” for either ActionScript or Away3D - I assume you mean I should just code my own?  This was the reason I’d thought of using invisible planes - so I could section off certain areas of the screen to trigger scrolling and keep other areas from doing so.

not to in-game objects

Thank you for this, you are absolutely right - for one, it would likely be slower and mean extra processing.  For another, I would constantly have to move the planes so they stayed right in front of the camera, thus slowing things down even more.  Great advice I hadn’t thought of.  Thank you.

   

DinkMcDinkleman, Newbie
Posted: 20 March 2012 01:30 AM   Total Posts: 30   [ # 4 ]

Actually - I think I have decided to go a different way altogether.  I will use sprites with mouse over listeners to implement and limit camera movement.  I just need to make sure I understand correctly - I can still add ActionScript sprites and work with them as normal, correct?  Is there a considerable loss in speed if I do so?

   

inSertCodE, Sr. Member
Posted: 20 March 2012 01:45 PM   Total Posts: 105   [ # 5 ]
DinkMcDinkleman - 20 March 2012 01:08 AM

Unless I’m missing it, I don’t really see that there are built-in “scroll listeners” for either ActionScript or Away3D - I assume you mean I should just code my own?  This was the reason I’d thought of using invisible planes - so I could section off certain areas of the screen to trigger scrolling and keep other areas from doing so.

Nono, not “scroll listeners” literally. Mouse events listeners where you check the mouse position and do your thing.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X