scroll camera platform game window in parts

  • I'm sure it's somewhere on the forum was an example of what you need but I can not find it.

    So when player sprite is touch edge of game window, game window skip forwart moves about the size of what is total size of the game window. (in up down left or right)

    So camera should scrolls for example every 800 pix pixels (left and right) but 480 pix (up and down)

  • bump

  • I can't open Construct 2 now to make an example, but try taking a look at this:

    (can't post URL, so take a look at the FAQ, in the link "Metal Slug/Mario type of scrolling")

    With this logic, I guess it's easy to fit your style of camera in your game.

    I'll try to do an example as soon as I can. I was trying earlier today but I had some problems.

    The idea I was trying is that if the player hits the end of the window, you scroll the camera accordingly (with Scroll X and Scroll Y in "System").

    Another idea was to create an invisible sprite in the middle of the screen, add the behavior "scroll to" in it and if the player goes beyond the window (viewport), you change the position of the invisible sprite accordingly. It worked, but I couldn't find a way to make it move smoothly (so it's a nice effect). It always moved absolutely, so the camera moved to abruptly.

    I hope what I said made sense. I'll try and make a example when I can, but I'm in a hurry right now. So I'm sorry if I wasn't clear enough in my instructions, I wrote it fast.

  • Try:

    System Every Tick

    System: Set Scroll X to scrollx + clamp(LayoutWidth /2 + floor(MySprite.X /LayoutWidth) * LayoutWidth - scrollx,0-dt*scrollSpeed,dt*scrollSpeed)

    System: Set Scroll Y to scrolly + clamp(LayoutWidth /2 + floor(MySprite.Y /LayoutWidth) * LayoutWidth - scrolly,0-dt*scrollSpeed,dt*scrollSpeed)

    Where MySprite is the character that triggers the movement and scrollSpeed is a variable that you can use to set whatever speed of transition you require.

    Is this what you mean?

  • bump

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • delgado

    Here's a example I made that hopefully is what you want.

    What I've done there is this:

    I create the background, the player and a invisible sprite that I called "camera".

    "camera" has the scrollTo behaviour, so the camera is always following this sprite.

    I align the camera sprite in the middle of the window, by clicking in it, "Align" -> "Window" -> "center horizontal" / "center vertical".

    Then in the event sheet I see if the player passes the viewportRight or Left. If yes, I move the "camera" sprite according to the windows width size of the project. In this case it's 640, so I put 640. If you ever change the windows width in the Project Properties, change the 640 to the new value you changed. (but don't forget to align horizontal/vertically again, otherwise it will not work as expected).

    I hope this is what you want and that my explanation is clear. English is not my first language.

    dropbox.com/s/d62dj98kbqh2ccd/camera-example.capx

    Edit:

    There's an error if you go all the way to the end of the layout and then go back. The camera don't align properly... well, I don't now how to fix it. I'd try to take a look at it now, but new it's christmas and I don't have that much time. Sorry.

  • Martiny its good when i go left and right but when i walko up and down nothing happens. Thanks for your trouble.

    Im still looking for solution, someone Please take a look at this example:

    dl.dropboxusercontent.com/u/44710358/Viatoree.exe

  • Martiny's example is all you need. Just look at the code and add events for Y. You shouldn't really need to be spoon-fed this after the amount of time you've been using C2.

  • @Martiny It took me a moment to adapt your example to my needs and you know what? it works :) thanks for a great example!

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