MODULE: rellax 0.4.0

Started by eri0o, Mon 07/10/2019 03:26:58

Previous topic - Next topic

eri0o

rellax version 0.4.0

Get Latest Release rellax.scm | GitHub Repo | Demo Windows | Demo Linux | Download project .zip

Rellax while the camera tracks with cool parallax



This module uses the camera and Viewport API from Adventure Game Studio 3.5.0.

Demo game uses keyboard arrows control, up arrow jumps. WASD should also work.


Usage
Before starting, you must create the following Custom Properties in AGS Editor, for usage with Objects.
Just click on Properties [...] and on the Edit Custom Properties screen, click on Edit Schema ... button, and add the two properties below:

PxPos:
  • Name: PxPos
  • Description: Object's horizontal parallax
  • Type: Number
  • Default Value: 0

PyPos:
  • Name: PyPos
  • Description: Object's vertical parallax
  • Type: Number
  • Default Value: 0

The number defined on Px or Py will be divided by 100 and used to increase the scrolling.
An object with Px and Py 0 is scrolled normally, an object with Px and Py 100 will be fixed on the screen despite camera movement.
Objects with negative Px and Py are usually at the front, and positive values are usually at the back.


Script API

static attribute Character* TargetCharacter
The character being tracked by the Game.Camera.

static attribute bool EnableParallax
Gets/sets whether Parallax is on or off.

static attribute bool EnableSmoothCam
Gets/sets whether Smooth Camera tracking is on or off.

static attribute bool AutomaticallySetupOnRoomLoad
Gets/sets whether to automatically setup on room load. It defaults to yes (true).
Leave as this unless you really need it.

static void SetupRoomManually()
You should not call this, unless AutomaticallySetupOnRoomLoad is false.
Then call this at the end of your room_Load, after you are done setting things up.

static attribute bool AdjustCameraOnRoomLoad
Gets/sets whether to instantly adjust camera to target on room before fade in, when Smooth Camera is on. Default is true.

static attribute RellaxTweenEasingType EasingType
gets/sets the camera tween type to use when the character is stopped.

static attribute float TweenDuration
gets/sets the camera tween duration once the character is stopped.

static attribute int CameraOffsetX
Gets/sets the camera horizontal offset. It's applied without smoothing.

static attribute int CameraOffsetY
Gets/sets the camera vertical offset. It's applied without smoothing.

static attribute int CameraLookAheadX
Gets/sets the camera horizontal lookahead offset. This is an additional offset that is added in the direction the target character is facing (only 4 direction support now).

static attribute int CameraLookAheadY
Gets/sets the camera vertical lookahead offset. This is an additional offset that is added in the direction the target character is facing (only 4 direction support now).

static attribute int CameraLerpFactorX
Gets/sets the factor the camera should use when interpolating in the X axis.

static attribute int CameraLerpFactorY
Gets/sets the factor the camera should use when interpolating in the Y axis.

static attribute int CameraWindowWidth
Gets/sets the camera window width that is centered on the target lookahead point, when the target is outside of the window, the camera moves to keep it inside.

static attribute int CameraWindowHeight
Gets/sets the camera window height that is centered on the target lookahead point, when the target is outside of the window, the camera moves to keep it inside.


License
This module is created by eri0o is provided with MIT License, see LICENSE for more details.
The code on this module is based on the code of Smooth Scrolling + Parallax Module from Alasdair Beckett, which bases on code from Steve McCrea.
It uses easing code based on Edmundo Ruiz and Robert Penner's, works, which are MIT and BSD licensed, respectively (and included in the module script).
The demo game uses CC0 (Public Domain) art provided by jetrel.

Mehrdad

Hi  @eri0o

It's so fantastic!!!  8-0. FPS is great too. Is it possible to add some features like Grab ledge and so on?
My official site: http://www.pershaland.com/

eri0o

#2
The module is just for parallax and smooth camera, the platformer was just for fun to test it under quick movement situations :)

The game project is on GitHub, you can also download it as zip, if you want to play with the code, the platformer bits are all on room1.asc, and it's just around 100 lines of code (if I remember it correctly). It requires the latest 3.5.0 release available!

Erh, maybe the take here is figuring out a new module that would provide some facility for 2D platfomer, but I don't have anything figured out for this for now (except further developing AgsBox2D to support the full Box2D api, but still, details like grab ledge would be onto who is using it :/)

Olleh19

Thanks eri0o, that module will probably come in handy once i start exporting various art groups separated from Photoshop! :) I've always wanted to see how a "plattformer" is made in AGS also, i know there's another plattformer done by abstauber. It didn't work in Ags 4.3.1 tho :-\ parallax scrolling is really cool too indeed.  (nod). Looks like i have to get the latest AGS, will do! 8-)

eri0o

#4
@Olleh19 the platformer here was just a small thing so it was faster to see the parallax effects happening than by just clicking to interact, so a really dedicated person can make a platformer with a much nicer code :]

Just adding minor bug fix that prevented actually turning the smooth scroll off before.

Edit: Small fix so that the parallax still happens even when smoothing is disabled.

Julius Dangerous

___________________________________________________________

eri0o

Thanks!

I have a small update to add in and need to throw a little explanation on how to mod it.

Also I discovered there's no way a character that walks really fast and have movement linked to animation can have a smooth scroll on the background AND not have the character blurred, so if anyone plans to use this, I recommend adding a check that if the level has a big scroll to change the movement type of the character (again, this is only a problem if the character walks really fast). Other alternative is a old-school Zelda like scrolling - just lerp rounding for camera sized grid.

Monsieur OUXX

#7
Can you describe how your module differs from the SmoothScrolling module, which offered smooth scrolling & Parallax (by Ali) and foreground+background parallax too?
 

eri0o

Basic changes are:

- use of AGS 3.5.0 Camera API, even though a single camera.
- parallax on y axis
- fractional parallax, instead of pre-defined values


Additionally, but totally subjective:
- algorithm works better for the specific demoed case of a character that jumps in a platform.
- code is simpler and easier to understand and modify (like, zone based scrolling like NES Zelda is easy to mod to achieve it)

"Bug" still present:
- character with movement linked to animation moving fast will produce "ghosting" when scrolling as the previous module did. I tried a ton of things and decided is just best to not have movement linked to animation with large scrolling areas and fast characters.

Known issue:

I need to close an issue opened on GitHub and release a new version of this.

Monsieur OUXX

 

Ali

Great stuff, my module is getting pretty old. I've put a link to this one on the first post.

Monsieur OUXX

Quote from: Ali on Mon 03/02/2020 16:16:04
Great stuff, my module is getting pretty old. I've put a link to this one on the first post.

Your module was awesome, but it's nice to have a module made for 3.5 natively.
 

eri0o

#12
Thank you Ali! You are awesome! I used your module for so much for so long! And you make cool games, and you are fun and have beautiful hair :]

---

Edit:

Pushed a minor bug fix update:

  • Prevents wrong position updates by moving calculations to late repeatedly execute always.
  • Fix crash by wrong player loop when loading a new room.

ld-airgrafix

#13
Thank you so much for this, it works so well and smooth

eri0o

Small update, adding some attributes to the module API!


  • Adds CameraOffsetX and CameraOffsetY so you can easily add an offset on the camera, useful when you have a big room and want to set the camera offset differently between areas. Offset is not set instantaneously, the transition when changing offsets is smooth.
  • Adds CameraLookAheadX and CameraLookAheadY so you can set the lookahead offset to your liking (defaults are 48 and 16). These are offsets that are added or subtracted depending the direction your target character is facing - for now, only supports 4 direction movement.

Now, I really liked having a very tiny API but I recently needed to do some more things with it in a game and decided it was best to add to the module itself. If someone has needs here when using it, please write and we try to figure out a solution.

Snarky

Quote from: eri0o on Mon 03/02/2020 13:46:50
- character with movement linked to animation moving fast will produce "ghosting" when scrolling as the previous module did. I tried a ton of things and decided is just best to not have movement linked to animation with large scrolling areas and fast characters.

Something that just occurred to me is that it might be possible to have movement linked to animation that is automatically disabled (and movement speeds adjusted accordingly) only when the background is scrolling. That way you avoid gliding whenever the background is static, but get smooth scrolling without character "ghosting" or jittering when it scrolls. (The trade-off is of course that the character will glide whenever the room is scrolling, but my hypothesis is that this will be less noticeable.)

eri0o

I think it would be something that needs to run before the function that tells the character to go to place "x", so what could be done theoretically is a function that guesses from a x,y point if the target character moving to that spot would require the room to scroll. This is a guess from looking how the pathfinding is fed to the characters in ags.

To do this, we need to know the path the character will take and see if any step on it will cause the room to scroll.

I think the easiest way is to use a dummy character and make it walk instantly and then "break" when there's a scroll and feed this info to do the change before the Process Click / walk to is ran, and leave the handling of this to the developer.

In my game I do a simpler thing than this which is: rooms that scroll are always the "gliding type" and rooms that don't make the player character use the other type of movement. In rooms that scroll I try to minimize regions that don't scroll by either giving large black border (if interior) or having carefully placed obstacle (in exterior areas).

Snarky

Quote from: eri0o on Thu 30/07/2020 13:07:10
I think it would be something that needs to run before the function that tells the character to go to place "x"

I was hoping Character.MovementLinkedToAnimation could be switched on the fly while walking. It would also require some sort of IsCurrentlyScrolling module state, at least internally.

eri0o

That state is easy to provide. I can give a try to this tonight and also check if the movement linked to animation can be set while walking - I really don't know.

I was also looking into adding more functions that would be used by the lerp, like those in the tween module, but have not yet figured the right way to do, but the idea would be so you could have a "spring" camera or other fun equations.

Flugeldufel

Hi eri0o, first of all thank you for this awesome module. But now I noticed something - no big issue, but a little bit annoying. When the player walks in a scrollable room from one edge to the other, the background ends a few pixels too soon. When he walks back again, the same happens to the other side (as shown in the picture). So after one walk to the other edge and back, both edges of the background are cut off.  ???



The Game's resolution is 320x180, the rooms are of different width, but it happens in every scrollable room.
I'm using the latest AGS Version (3.5.0 Patch 4) and no other modules (except 'Tween' of course)

Thanks and sorry if I missed the answer somewhere...

SMF spam blocked by CleanTalk