scrolling background loopable issues

Started by jamesreg, Thu 03/06/2010 20:36:47

Previous topic - Next topic

jamesreg

I am trying to do a space battle scene where you have a large space background and your look like your moving around though a viewscreen on a ship.

I am using this code

if (cKirk.x > 4590) cKirk.x = 405;
  if (cKirk.x < 404) cKirk.x = 4590;
  if (cKirk.y > 4690) cKirk.y = 305;
  if (cKirk.y < 304) cKirk.y = 4690;

to tell you when you get to the edges and to loop the screen around

we are using the arrow keys to move the character and using pressing function for the sensitivity

problem is when we get to the edge the screen stops you have to stop pressing the arrow key and press again to get it to loop

we tried to solve this by doing a keypress request and manually tell it to press in that direction when you get to the edge

however it does loop but is sluggish or not perfect

does anyone have a better idea or way of doing this where it will appear instantly to make the loop?

Calin Leafshade

where are you putting that code?

repeatedly_execute_always()?

jamesreg

Quote from: Calin Leafshade on Thu 03/06/2010 20:40:39
where are you putting that code?

repeatedly_execute_always()?
function room_RepExec()

Calin Leafshade

and how are you making cKirk move? with a move command or directly altering the x and y?

jamesreg

Quote from: Calin Leafshade on Thu 03/06/2010 21:44:54
and how are you making cKirk move? with a move command or directly altering the x and y?


moving with the keyboard using the  KeyboardMovement.SetMode(eKeyboardMovement_Pressing);  command
so that the character/viewscreen responds to keeping the arrows pressed like you would move in other games like this.


Calin Leafshade

Hmm i'll have to look up that modules commands.. i'll get back to you..

but sticking your code in repeatedly_execute_always() should work.. although I would adapt it to something like:

Code: ags

 if (cKirk.x > 4590) cKirk.x = 405 + (cKirk.x - 4590);


this will stop cKirk from 'snapping' to the edges.

also remember to use else ifs to stop multiple cases from being true as the position changes.

jamesreg

Its also not picking up that when your pressing the directinal arrow that when it loops your still pressing it and it causes but its not picking that up after the loop and keep the screen scrolling

Quote from: Calin Leafshade on Thu 03/06/2010 22:20:12
Hmm i'll have to look up that modules commands.. i'll get back to you..

but sticking your code in repeatedly_execute_always() should work.. although I would adapt it to something like:

Code: ags

 if (cKirk.x > 4590) cKirk.x = 405 + (cKirk.x - 4590);


this will stop cKirk from 'snapping' to the edges.

also remember to use else ifs to stop multiple cases from being true as the position changes.

Gilbert

#7
The reason is that the KeyboardMovement module that comes with AGS was not written to deal with looping rooms (well, AGS itself was not designed to have looping rooms either).

It uses on_key_press() to first check whether an arrow key has been pressed and if so starts moving the player. Then in repeatedly_execute() it checks whether arrow keys are being held and issues a move to the player again only when the direction has changed.

One solution to this is to hack KeyboardMovement, so that it also checks whether the player has "warped" and acknowledges this as a screen looping being taken (for example, when the player is walking towards the right and suddenly his x-coordinate has decreased instead of increasing, then a warping has been taken place).

Try to add these in KeyboardMovement_102.asc (untested):

On top of the script:
Code: ags

int player_lastx, player_lasty;


Then in repeatedly_execute(), modify the bottom part like this:
Code: ags

...
			}
                                          
			player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); // walk player character to the new coordinates
		}
		KeyboardMovement_CurrentDirection = newdirection; // update current direction to new direction
		player_lastx=player.x;     player_lasty=player.y;   //ADD THIS
	} 
	KeyboardMovement_CurrentDirection = newdirection; // update current direction to new direction
	} else if (KeyboardMovement_CurrentDirection!=eKeyboardMovement_Stop)            //START ADDING FROM HERE
		int dx=0, dy=0;
		if (player.x<player_lastx&&(KeyboardMovement_CurrentDirection==eKeyboardMovement_Right||KeyboardMovement_CurrentDirection==eKeyboardMovement_UpRight||KeyboardMovement_CurrentDirection==eKeyboardMovement_DownRight)) dx=DISTANCE;
		if (player.x>player_lastx&&(KeyboardMovement_CurrentDirection==eKeyboardMovement_Left||KeyboardMovement_CurrentDirection==eKeyboardMovement_UpLeft||KeyboardMovement_CurrentDirection==eKeyboardMovement_DownLeft)) dx=-DISTANCE;
		if (player.y<player_lasty&&(KeyboardMovement_CurrentDirection==eKeyboardMovement_Down||KeyboardMovement_CurrentDirection==eKeyboardMovement_DownRight||KeyboardMovement_CurrentDirection==eKeyboardMovement_DownLeft)) dy=DISTANCE;
		if (player.y>player_lasty&&(KeyboardMovement_CurrentDirection==eKeyboardMovement_Up||KeyboardMovement_CurrentDirection==eKeyboardMovement_UpLeft||KeyboardMovement_CurrentDirection==eKeyboardMovement_UpRight)) dy=-DISTANCE;
		if (dx||dy) player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); 
		player_lastx=player.x;        player_lasty=player.y;       //TO HERE
}


And in on_key_press():
Code: ags

...
			}

			player.WalkStraight(player.x + dx, player.y + dy, eNoBlock); // walk player character to the new coordinates
		}
		KeyboardMovement_CurrentDirection = newdirection; // update current direction to new direction
		player_lastx=player.x;        player_lasty=player.y;       //ADD THIS

	}


Edit: It's a bit hard to see, but look for the CAPS in the comments to see what have been added.

jamesreg

This is working much better then it did before with above coding but there is still a slight hesitation or pause before changing locations anyway to fix that?

Gilbert

I think it's possibly caused by using WalkStraight(), as what it currently does, is to restart the walking when a "warp" happens. I'll see if this can be improved when I have time. Maybe the best solution is to not use WalkStraight(), but only set the viewport manually in each loop (but this is only good when the player character is not visible).

jamesreg

Quote from: Gilbet V7000a on Mon 07/06/2010 01:52:01
I think it's possibly caused by using WalkStraight(), as what it currently does, is to restart the walking when a "warp" happens. I'll see if this can be improved when I have time. Maybe the best solution is to not use WalkStraight(), but only set the viewport manually in each loop (but this is only good when the player character is not visible).

The player character will not be viewable at all

Gilbert

Yes, I know this is the case in your game, so setting the viewport continuously shouldn't be a problem here.

Gilbert

Hmmm. BTW, did you try implementing what Calin had suggested also? That should eliminate some of the 'jumps' when a warping occurs.

I've made a quick test here (compile with V3.1.2) and the scrolling seems to be okay to me (only left and right panning implemented and you can change the speed by adjusting the player's walkspeed in the room script). It may be possible that your room is quite large which causes lags in the scrolling. If this is the case I think it's hard to fix.

There're also some mistakes in my original codes (now fixed I think), but I think you've spotted that already.

SMF spam blocked by CleanTalk