How to move camera with keyboard

0 favourites
  • 12 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • 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?

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

    The last examples should nicely get adapted to your needs.

  • 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.

  • 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]).

  • 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?

  • relatively difficult, but possible.

  • 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 (:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

  • Mouse click movement : LINK

    That should inspire you.

    There are other examples in the FAQ.

  • Thank you Kyatic. I have one last question then I should be out of everyone's hair for a while. I'm trying to set up a pointer on a HUD layer that will always point to an object's location, kind of like a map marker, but I can't seem to get it to point at the created object. The way I'm trying to set it up is like this:

    EveryTick

    If ObjectIsPlaced = 1

    then Set pointer angle to Object.X , Object.Y

    When ran it just points in a random direction and stays there. =\

  • If you have several instances of Object, the pointer will pick the very first one.

    Unless you pick the target object before to make sure it is its coordinates that are given to Pointer.

    You should post a capx (save to single file) to illustrate what you currently get instead of the intended as you described it.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)