How to move camera with keyboard

Forum Home Forum Home > Construct 2 General > How do I....?
 Post Reply Post Reply Page  12>
Author
441 Rep
Post Options Post Options   Quote tribalismdev Quote  Post ReplyReply Direct Link To This Post Topic: How to move camera with keyboard
    Posted: 20 Nov 2011 at 4:47am
Hello. I've been working with Construct 2 and really enjoying it so far. However, I've come to a dilemma in the development of my game. I want the game to not have a player character on screen. So instead of having a character for the camera to follow how do I make it so that I can scroll the camera using the directional keys?
Back to Top

Moderator
30,807 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 4:53am
Check the How do I FAQ at the section Scrolling/camera.

The last examples should nicely get adapted to your needs.
Back to Top
441 Rep
Post Options Post Options   Quote tribalismdev Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 5:07am
Okay. I've created an invisible sprite to use for camera movement. However there seems to be some considerable lag when changing directions this way. Sometimes I have to press the key multiple times before it will finally go in that directions. Also there is some problems with solid objects, since the objects are solid the camera can get snagged on them, even with the camera not set to solid.
Back to Top
2,168 Rep
Post Options Post Options   Quote brockatkinson Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 6:10am
You are using 8 directional movement, yes? That's probably why.

I would recommend that you have you blank event only have ScrollTo on it, and do the movement as events (when keyboard.buttonPressed.Left -> cameraSprite.Move.X = cameraSprite.X - 2 [or whatever it might be]).
Back to Top
441 Rep
Post Options Post Options   Quote tribalismdev Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 6:45am
okay. Well I've ironed out those issues. Is setting up an RTS-like control scheme possible with Construct 2? Like multiple units, click to move, group selection, etc?
Back to Top
19,339 Rep
Post Options Post Options   Quote sqiddster Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 8:38am
relatively difficult, but possible.
Back to Top
11,882 Rep
Post Options Post Options   Quote Yann Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 4:50pm
selecting something would be possible by having a "selected" boolean private variable you set to true if the unit is selected.
you just have to foreach the units and check for these variable set to true and apply your actions.

To group, you could have a 2 dimensional array sized this way :
DIM X = maximum number of groups
DIM Y = maximum number of units per groups

and then you select the units you want to group (that is to say, their "selected" variable get set to true)
and when you use your shortcut to groupe them, you foreach them and store their UID in the arrayat(IDofTheGroup,loopindex)

If you want to recall your selection, you just have to do a
for 0 to DIM Y
    if unit.UID == arrayat(IDofTheGroup,loopindex) -> unit set selected to true

I hope you have some knowledge of c2 else I might be a bit hard to understand... If you don't understand, you don't have enough knowledge yet to make a RTS I guess (:
Back to Top
441 Rep
Post Options Post Options   Quote tribalismdev Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 6:37pm
Oh well I've worked in C++, Java, Ruby, and Python. So arrays are pretty simple. The only thing that makes this task daunting is the event sheet UI. While I love that everything is simplified into a click and pick form, sometimes just hard-coding would be much simpler, such as for tasks like this, if C2 had that kind of support. But I'm not complaining at all. I'll look into it, and thanks for your advice guys.
Back to Top
441 Rep
Post Options Post Options   Quote tribalismdev Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 6:40pm
Also: how does one achieve getting the unit to move to a point clicked? I was trying to work on that last night as I wanted to create simple AI to have a certain unit autonomously seek out another, perform an action on it and then return to what it was doing.
Back to Top

Moderator
30,807 Rep
Post Options Post Options   Quote Kyatric Quote  Post ReplyReply Direct Link To This Post Posted: 20 Nov 2011 at 7:33pm
Mouse click movement : LINK

That should inspire you.
There are other examples in the FAQ.
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down