MODULE: Smooth Scrolling & Parallax v1.7.1

Started by Ali, Fri 07/12/2007 21:14:09

Previous topic - Next topic

Matti

It seems that one isn't able to manually manipulate the viewport in non-parallax-rooms, even if the parallax effect is turned off - or did I do something wrong? Is there a way you could change that?

Or - even better - to allow the viewport manipulation in parallax-rooms, so that it isn't depending on the player's coordinates?

Ali

You can switch the parallax effect on and off, but I haven't created an option to turn smooth scrolling on and off. I may do this when I get the time to update the script.

As a workaround for now, try switching to a dummy character to allow for camera movement.

Let me know if that helps!

Matti

The dummy character idea is good, but unfortunately wouldn't work in my case.

Well, I just wait and would be happy if you update your script at some point.

Ali

I've added an update, with a cleaned up script. Hopefully you can use the SmoothScroll_StopScroll() function to do what you need.

Let me know if there are any more problems!

hedgefield

Link is broken? I get a 0kb file when I download the 1.4 module.


Ali

Yeah me too!

I've uploaded the module again and updated the link. It works for me now, and so does the demo.


Helme

Did you manage to fix the 'dissapearing-objects'-bug?
It's really strange that in my games some objects have the problem and some don't.

Ali

I work on this sporadically with huge breaks in between when real life gets in the way of AGSing.  I accidentally implemented the same function twice at one point, but it's okay now.

I'm afraid I don't remember the details of the bug you mention. An older version required that parallax objects be the first ones created in a room, but that's no longer the case.  Please make sure you have the latest version, and let me know.

With different versions of AGS and different graphical modes there have been issues at the start of rooms where objects jump around. It's hard for me to keep track of this, because of multiple versions of the editor and the fact that it is always being updated. A simple solution to this problem is to use 'Instant Transitions' and a black GUI to create fading effects.

If these don't help, please describe the problem in more detail. Or you could PM me your WIP to see if I can solve the problem.

Helme

I used an older version, but I deleted the script and replaced it with 1.4.
But the problem stayed the same. Only the first objects works correctly with the parallax effect. Other objetcs dissapear after re-entering the room.

Ali

Thanks Helme,

The problem was that the module didn't store parallax objects original locations correctly unless they were created before other objects. With luck, version 1.5 should sort this out:

http://www.2dadventure.com/ags/smooth_scroll_module_1.5_b.zip

I'm not sure you're really supposed to get through version numbers this quickly... let me know if the new one works!

Helme

The file has the size of 0 byte - I think it should be bigger  ::)

Ali

Sorry, the link was correct on the first post, but not on the one above. I've corrected it now, but I don't know why this keeps happening!

Helme


AGD2

This is an excellent module. Really impressed with the effects it's capable of creating. :)

In the latest version, however, it seems that Smoothing the motion for distant objects in hi-res might have been broken.

I have a certain distant object (mountains) set up to use View 8, with the object's 4 offset frames assigned to Loop 0.

The effect worked in the previous version of the module, but after upgrading to this new one, the object seems to cycle through all 4 frames, rather than panning smoothly along.

Ali

Glad to hear your using the module, but sorry to hear about that problem!

I'm afraid I can't recreate it. I guess this is an effect that looked right before you updated the module?

The smoothing works correctly for me in the demo for resolutions of 640x400 upwards, and with high-res coordinates on and off. Could you give me any more information like the PxPos value of the object, or see if the demo works for you?

AGD2

First I should mention that I previously edited all of the 4.0 values under this section:

Code: ags
if (PxObj[objectpass].GetProperty("PxPos")==-1){


... to values of 26.0.  I wanted to have distant mountains scrolling very, very slowly as the character walks.

However, when walking to the LEFT, the codeblock above makes the mountains scroll from right to left. I needed them to scroll left to right instead.  In previous versions of the module, it seemed that if I altered the following lines:

     
Code: ags
PxObj[objectpass].X=PxObjOriginX[objectpass]+FloatToInt(IntToFloat(viewx)/4.0); 

PxObj[objectpass].Y=PxObjOriginY[objectpass]+FloatToInt(IntToFloat(viewy)/4.0); 


..and replaced the instances of + with a -  this would make the mountains scroll the opposite direction instead.  In the latest module version, doing that seems to mess up the smooth scrolling View/Frames, though.

I guess what would be handy, is if you could implement a new PxPos number for distant scrolling objects (like mountains) that scroll left to right, rather than right to left. Either that, or allow the user to somehow specify which direction a distant object should scroll.


Another question:

If I put the following code in the room_Load() function of a screen with parallax scrolling:

function room_Load(){
player.x=20;
player.y=327;
SmoothScroll_PxOn();
}

..if the previous room's background was scrolled to the right, and the player character is then moved into the new room and positioned on the left side, the new room's background will initially be scrolled over the the right too (the inherited position from the previous room). However, after fade-in, the background & parallax objects quickly scroll over to where he's standing on the left.  

What's the best way of ensuring that both the scrolling background and any parallax objects are already set into their correct positions, relative to the player's x/y pos, prior to the screen fading in? So that the player doesn't have to watch them scrolling into position every time a new room loads?


Thanks!

Ali

If I make the changes you describe in function PositionObj(), I get code that looks like this:

Code: ags
else if (PxObj[objectpass].GetProperty("PxPos")==-1){
    
PxObj[objectpass].X=PxObjOriginX[objectpass]+FloatToInt(IntToFloat(viewx)/26.0);

PxObj[objectpass].Y=PxObjOriginY[objectpass]+FloatToInt(IntToFloat(viewy)/26.0); 
      
if (PxObj[objectpass].GetProperty("PxView")!=0){
      
   fractionx = (IntToFloat(viewx)/26.0)-IntToFloat(FloatToInt(IntToFloat(viewx)/26.0, eRoundDown));
        
   fractiony = (IntToFloat(viewy)/26.0)-IntToFloat(FloatToInt(IntToFloat(viewy)/26.0, eRoundDown));


Here I've replaced 4.0 six times.

When changing these values, it's advisable to make sure the object's initial positions are adjusted accordingly by making this change in function SetOrigins:

Code: ags

else if (object[objectpass].GetProperty("PxPos")==1){
        
//Set horizontal origin for object:
PxObjStartX[NumberObj]= object[objectpass].X;
PxObjOriginX[NumberObj] = object[objectpass].X + FloatToInt((IntToFloat(object[objectpass].X)/IntToFloat(Room.Width))*(IntToFloat(Room.Width-System.ViewportWidth)/26.0));
        
//Set vertical origin for object:
PxObjStartY[NumberObj]=object[objectpass].Y;
PxObjOriginY[NumberObj]= object[objectpass].Y + FloatToInt((IntToFloat(object[objectpass].Y)/IntToFloat(Room.Height))*(IntToFloat(Room.Height-System.ViewportHeight)/26.0));
}


Here I've replaced 4.0 twice.

This gives me the effect of an object in the background scrolling very slowly. The smoothing effect works, but is not as pleasing to the eye because of the lack of sub-pixel movement.

Quote from: AGD2 on Sun 06/12/2009 08:25:07
I wanted to have distant mountains scrolling very, very slowly as the character walks.

I'm having a little trouble understanding what effect you're tring to achieve, here. A distant object like mountains ought to move more relative to the screen, not less. Changing 4.0 to 26.0 makes my parallax objects appear nearer.

Quote from: AGD2 on Sun 06/12/2009 08:25:07
I guess what would be handy, is if you could implement a new PxPos number for distant scrolling objects (like mountains) that scroll left to right, rather than right to left. Either that, or allow the user to somehow specify which direction a distant object should scroll.

If the player walks left, a distant object ought to travel left relative to the screen too. If it travelled in the opposite direction it would appear to be in the foreground. To get that effect you can use positive PxPos values, or have I misunderstood?

If checking over the script doesn't solve the problem, perhaps you could explain the effect you're looking for.

Quote from: AGD2 on Sun 06/12/2009 08:25:07
What's the best way of ensuring that both the scrolling background and any parallax objects are already set into their correct positions, relative to the player's x/y pos, prior to the screen fading in? So that the player doesn't have to watch them scrolling into position every time a new room loads?

If for some reason you can't specify the coordinates in the ChangeRoom function in the outgoing room, you could use something like this in the roomLoad function
Code: ags
if (player.x!=20 && player.x!=327) player.ChangeRoom (1, 20, 327);


I'll try to make the module support this better in the future, but I can't work it out just now. For the time being, that workaround is your best bet.

I hope that helps!

AGD2

I edited all the same instances as you, changing 4.0 to 26.0 and achieved the same effect. Changing the pluses to minuses in these lines :

Code: ags

PxObj[objectpass].X=PxObjOriginX[objectpass]-FloatToInt(IntToFloat(viewx)/26.0);

PxObj[objectpass].Y=PxObjOriginY[objectpass]-FloatToInt(IntToFloat(viewy)/26.0);


...makes the mountains object scroll the other way, but the frames/sub-pixel movement is jerky, like the frames are displaying in the wrong order. However, if I set the mountain object's PxView Property to 0, it gives me the effect I want (just without using the sub-pixel View/Frames, which, as you mentioned, can't really be noticed at that slow speed anyway).

I know that changing the pluses to minuses isn't really what's intended for negative PxPos values, but it seemed to work before without making the sub-pixel movement jerky, so I just thought I'd mention it, in case something had broken between versions. Either way though, I can still achieve the effect I need.

As for what I'm trying to do. Take a look at this video of the Amiga game Shadow of the Beast and skip to the 2:30 mark:

http://www.youtube.com/watch?v=WnHY7qUPPro

As the character walks in one direction, the distant mountains appear almost static. But if you look closely,you can see that they're slowly scrolling in the opposite direction than the one the character is walking in.

Granted, the screen I'm working with isn't a direct side-on view like Shadow of the Beast. It has more of an isometric angle with more depth. But due to the diagonal angle the character is moving at, it just looks "right" for the mountains to be traveling away from him, rather than in the same direction.

QuoteI'll try to make the module support this better in the future, but I can't work it out just now. For the time being, that workaround is your best bet.

Sounds good, and thanks for the suggested code. Works a treat! :)

SMF spam blocked by CleanTalk