Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Candle on Sun 18/12/2005 21:52:39

Title: Click screen and drag?
Post by: Candle on Sun 18/12/2005 21:52:39
Can you click on the screen and move the  to the left or right the screen?
Title: Re: Click screen and drag?
Post by: Akumayo on Sun 18/12/2005 22:07:51
Maybe this manual clip will help, I'll be you could do something with this function:

SetViewport
SetViewport (int x, int y)

Locks the screen viewport to having the top-left hand corner at (X,Y) in a scrolling room. This allows you to manually pan across a scrolling room or to have the screen follow a non-player character.
The lock is released when you either call ReleaseViewport or the player changes rooms.

NOTE: The co-ordinates supplied are 320x200-scale co-ordinates, and will be automatically multiplied up by the engine.

NOTE: This function has no effect if the current room isn't a scrolling room.

Example:

int ypos = 0;
while (ypos < 60) {
Ã,  SetViewport(0, ypos);
Ã,  Wait(1);
Ã,  ypos++;
}
ReleaseViewport();

will scroll the screen down from the top 60 pixels, then release it back to follow the player around.
Title: Re: Click screen and drag?
Post by: Candle on Sun 18/12/2005 22:10:14
I was thinking more like a Panorama view where you click and drag the screen so would this work for that?
Title: Re: Click screen and drag?
Post by: Akumayo on Sun 18/12/2005 22:15:20
Maybe, like, if you had two arrow shaped GUI's pointing left/right, then you could code them:

int panoramax;

//script for left arrow clicked
panoramax -= 1;
SetViewport(panoramax, 0);Ã,  //scroll screen one pixel left

//script for right arrow clicked
panoramax += 1;
SetViewport(panoramax, 0);Ã,  //scroll screen one pixel right
Title: Re: Click screen and drag?
Post by: Candle on Sun 18/12/2005 22:24:37
That would work if you use the right and left click but in the Panorama type view you just right click on the screen and drag it , so if you want to go left you just drag to the left .same for the right.
Try this and see what I mean.
http://www.mytempdir.com/329325 click on the screen.
Title: Re: Click screen and drag?
Post by: Ashen on Sun 18/12/2005 22:36:54
Try something like :

//Top of room script
int panoramax = -1;


// Room repeatedly_execute
if (mouse.IsButtonDown(eMouseRight)) {
  if (panoramax == -1) panoramax = mouse.x; // Set initial point
  if (mouse.x < panoramax) SetViewport(GetViewportX()-1, GetViewportY());
  // If mouse moves LEFT of initial click, pan screen LEFT
  else if (mouse.x > panoramax) SetViewport(GetViewportX()+1, GetViewportY());
  // If mouse moves RIGHT of initial click, pan screen RIGHT
}
else panoramax = -1; // Reset when right button released

(I'm assuming you only want it in a specific room, rather than every one. If you do want it in every room, just move these into the global script.)

You might want to increase the +/- 1 in the SetViewport() commands, to increase the scrolling speed, and you'll probably want to add something to make it loop (when you reach one side of the room, automaticaly go back to the other) - the code for that is around somewhere.

You could possibly even add something so that it scrolls faster, the further you move the mouse.
Title: Re: Click screen and drag?
Post by: Akumayo on Sun 18/12/2005 22:39:10
Well, I tried to post before Ashen (btw, great script Ashen, I tried to come up with it, but couldn't), but here's my code anyway.Ã,  It scrolls based on the player clicking left/right arrow keys.

Top of global script:

currentx;
export currentx;


Script Header:

import currentx;


Game Start:

currentx = 0;


In repeatedly_execute:

if (character[player.ID].Room == (insert panoramic room number here)) {
Ã, if (IsKeyPressed(375) == 1) {
Ã,  Ã, currentx -= 1;
Ã,  Ã, SetViewport(currentx, 0); Ã, //scroll the screen left while left arrow is down and you're in panoramic room
Ã, }
Ã, if (IsKeyPressed(377) == 1) {
Ã,  Ã, currentx += 1;
Ã,  Ã, SetViewport(currentx, 0); Ã, //scroll the screen right while right arrow is down and you're in panoramic room
Ã, }
}
Title: Re: Click screen and drag?
Post by: Candle on Sun 18/12/2005 22:43:49
Thanks Ashen and Akumayo, the code Ashen gave works just like I want.
Title: Re: Click screen and drag?
Post by: Ashen on Sun 18/12/2005 22:48:47
Glad it worked!

A few (really minor) things about Akumayo's code (mostly for posterity):
You don't need to set currentx to 0 in game_start, as it defaults to that. It would, however, be hand to set it to GetViewportX() before starting the scroll. Since you've exported/imported it globally,this could be done in one of the Player enters screen interactions.
Also, character[player.ID] is unnecessary - just using player is fine.

But yeah, that's a nice way of doing it.
Title: Re: Click screen and drag?
Post by: Akumayo on Sun 18/12/2005 22:50:56
...Someday...I will defeat you... :=
Title: Re: Click screen and drag?
Post by: Candle on Sun 18/12/2005 23:00:18
Here is a template for anyone that wants to use it .
http://www.xtrafile.com/uploads/2a2729de25.rar.html

Thanks again guys.
Title: Re: Click screen and drag?
Post by: Candle on Mon 19/12/2005 04:09:54
Someone finds the time this would make a nice Module with some speed controls added and maybe up and down drag too.
Title: Re: Click screen and drag?
Post by: Candle on Mon 09/01/2006 08:44:09
I was just wonding how I could play a sound while the mouse is being dragged to move in the room?
It would be foot steps.
Where would I add PlaySoundEx(3, 4);

if (mouse.IsButtonDown(eMouseRight)) {
Ã,  if (panoramax == -1) panoramax = mouse.x; // Set initial point
Ã,  if (mouse.x < panoramax) SetViewport(GetViewportX()-4, GetViewportY());
Ã,  // If mouse moves LEFT of initial click, pan screen LEFT
Ã,  else if (mouse.x > panoramax) SetViewport(GetViewportX()+4, GetViewportY());
Ã,  // If mouse moves RIGHT of initial click, pan screen RIGHT
}
else panoramax = -1; // Reset when right button releasedÃ, 
Title: Re: Click screen and drag?
Post by: Ashen on Mon 09/01/2006 11:38:57
Anywhere in the if(mouse.IsButtonDown(eMouseRight)) { condition should work - just add it in at the top.

Also, you'd be better making it if (IsChannelPlaying(4) == 0) PlaySoundEx(3, 4); - otherwise the sound will be restarted every loop, rather than playing through.
Title: Re: Click screen and drag?
Post by: Candle on Mon 09/01/2006 18:59:19
Thanks Ashen.