Click screen and drag?

Started by Candle, Sun 18/12/2005 21:52:39

Previous topic - Next topic

Candle

Can you click on the screen and move the  to the left or right the screen?

Akumayo

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.
"Power is not a means - it is an end."

Candle

I was thinking more like a Panorama view where you click and drag the screen so would this work for that?

Akumayo

#3
Maybe, like, if you had two arrow shaped GUI's pointing left/right, then you could code them:
Code: ags

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
"Power is not a means - it is an end."

Candle

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.

Ashen

#5
Try something like :
Code: ags

//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.
I know what you're thinking ... Don't think that.

Akumayo

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:
Code: ags

currentx;
export currentx;


Script Header:
Code: ags

import currentx;


Game Start:
Code: ags

currentx = 0;


In repeatedly_execute:
Code: ags

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
 Ã, }
}
"Power is not a means - it is an end."

Candle

Thanks Ashen and Akumayo, the code Ashen gave works just like I want.

Ashen

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.
I know what you're thinking ... Don't think that.

Akumayo

...Someday...I will defeat you... :=
"Power is not a means - it is an end."

Candle

Here is a template for anyone that wants to use it .
http://www.xtrafile.com/uploads/2a2729de25.rar.html

Thanks again guys.

Candle

Someone finds the time this would make a nice Module with some speed controls added and maybe up and down drag too.

Candle

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);
Code: ags

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Ã,  

Ashen

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.
I know what you're thinking ... Don't think that.

Candle


SMF spam blocked by CleanTalk