Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Binoculars  (Read 3718 times)

0 Members and 1 Guest are viewing this topic.

iain

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
    • View Profile
    • http://ichatburn.co.uk
Binoculars
« on: February 22, 2008, 03:58:58 PM »

I'm trying to recreate those binoculars you see by the seaside which you can put money in and view, but it could also be some regular binoculars.This is done quite well in the game Barrow Hill in the cabin.

I've come up with a script below that works ok but with a few problems. "bins" is a png overlay 2400*1800 to make it look like you're looking through some binoculars (2 black circle fringes, see image below) and view is the scene behind that which you can look around by moving the mouse and is 3264*2448.  My game resolution is 1024*768, the bins image is bigger because it goes offscreen at the edges, I would tile it like in the torchlight script but its a bit beyond me at this point.

Mainly the movement is too fast and also it doesn't seem to stop moving even after I stop moving my mouse. The WaitFor (bins); bit is an attempt to make the view image and the binoculars to move together so it looks realistic, it hasnt worked that well though and the they will still move without the view a bit. Adding Sleep(20) helps a bit with that but it makes everything very jerky.

I used skip instead of scroll because i didnt like that you have to wait for it to move to a point even though your mouse had already moved somewhere else and I've have problems controlling scroll speed in other scenes, scrollpixel works but is jerky,scroll speed simply doesnt work for me, i can make it slower but anything less than 10 doesnt make any difference, is this a bug because I think it worked at one point?

Is there anyway to reduce the mouse sensitivity/speed? I think that would help if I could.


Code: [Select]
var bins = Scene.GetNode("bins");
var view = Scene.GetNode("view");
Game.MainObject=null;
Scene.AutoScroll=true;
actor.Active = false;
Scene.SkipTo(1632,1224); //half resolution of the view image
bins.SkipTo(Scene.MouseX-1200,Scene.MouseY-900);
Sleep(1800); //to stop movement before the scene has initialised


while(true)
{

   
   Scene.SkipTo (Scene.MouseX,Scene.MouseY);
   bins.SkipTo(Scene.MouseX-1200,Scene.MouseY-900);
   //the binoculars follow minus half their resolutiion to keep them centered
   WaitFor (bins); //wait so the bins and view move together
   WaitFor (Scene.SkipTo);
   
}

Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Binoculars
« Reply #1 on: February 22, 2008, 05:01:37 PM »

one way of slowing down the movement is thinking of mouse movement as of a differencial value and not of an absolute value.

var oldX = Game.MouseX;
var oldY = Game.MouseY;

while(1) // endless loop
{
  var dx = Game.MouseX - oldX;
  var dy = Game.MouseY - oldY;
 
//  now you know how many pixels mouse moved and can specify whatever ratio for SkipTo you wish
   ... do something here
//  at the end we store new position into our old:

  oldX = Game.MouseX;
  oldY = Game.MouseY;
  Sleep(1);
}

I hope this can give you some idea.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

iain

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
    • View Profile
    • http://ichatburn.co.uk
Re: Binoculars
« Reply #2 on: February 22, 2008, 06:20:58 PM »

Thanks for helping metamorphium. When you say "do something here" is that where the code inside my loop goes or should this all be in a seperate loop? sorry i'm a bit unsure how implement the ratio change so it move just a little less, should the dx/dy value be taken off?
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Binoculars
« Reply #3 on: February 22, 2008, 09:32:01 PM »

ah, ok. You'd attach this script to your scene, so it'll work as an endless loop (while(1))

Let's say that you need for every four mouse points to move one point in each direction:

Code: [Select]
var oldX = Game.MouseX;
var oldY = Game.MouseY;

var SceneX = 0; //We preset scene to some X, Y point
var SceneY = 0;
Scene.SkipTo(SceneX,SceneY); // we skip to that point


while(1) // endless loop
{
  var dx = Game.MouseX - oldX;
  var dy = Game.MouseY - oldY;
 
//  now you know how many pixels mouse moved and can specify whatever ratio for SkipTo you wish

SceneX = SceneX + dx / 4; // we divide mouse difference by four to achieve that for 4 mouse pixels, we move one scene. It works both directions as multiplying by negative value produces negative. :)
SceneY = SceneY + dy / 4; // ditto for Y coordinate

Scene.SkipTo(SceneX, SceneY); // And skip to the newly calculated coordinates.
//  at the end we store new position into our old:

  oldX = Game.MouseX;
  oldY = Game.MouseY;
  Sleep(1);
}

Entirely untested, but should work.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

iain

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 10
    • View Profile
    • http://ichatburn.co.uk
Re: Binoculars
« Reply #4 on: February 23, 2008, 01:37:15 AM »

That's great. I had to tweak the ratio to dx / 2 + 2*dx;  as it was moving too slow and couldn't get to the edge of my image. Very useful that, cheers!

Logged
 

Page created in 0.042 seconds with 19 queries.