How to move camera with keyboard

Get help using Construct 2

Post » Sun Nov 20, 2011 4:47 am

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?
G
1
Posts: 8
Reputation: 441

Post » Sun Nov 20, 2011 4:53 am

Check the How do I FAQ at the section Scrolling/camera.

The last examples should nicely get adapted to your needs.
Moderator
B
154
S
53
G
28
Posts: 5,402
Reputation: 41,302

Post » Sun Nov 20, 2011 5:07 am

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.
G
1
Posts: 8
Reputation: 441

Post » Sun Nov 20, 2011 6:10 am

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]).
B
12
G
2
Posts: 84
Reputation: 2,608

Post » Sun Nov 20, 2011 6:45 am

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?
G
1
Posts: 8
Reputation: 441

Post » Sun Nov 20, 2011 8:38 am

relatively difficult, but possible.
B
68
S
23
G
17
Posts: 2,675
Reputation: 26,419

Post » Sun Nov 20, 2011 4:50 pm

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 (:
B
46
S
20
G
13
Posts: 1,405
Reputation: 14,993

Post » Sun Nov 20, 2011 6:37 pm

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.
G
1
Posts: 8
Reputation: 441

Post » Sun Nov 20, 2011 6:40 pm

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.
G
1
Posts: 8
Reputation: 441

Post » Sun Nov 20, 2011 7:33 pm

Mouse click movement : LINK

That should inspire you.
There are other examples in the FAQ.
Moderator
B
154
S
53
G
28
Posts: 5,402
Reputation: 41,302

Next

Return to How do I....?

Who is online

Users browsing this forum: 509Dave16, Behamut, Gweely, HZGaming, LevelUpJordan, ramones, rayray, skozax and 2 guests