91
Technical forum / Re: Start walk animation on releasing the mouse button
« on: December 10, 2012, 10:59:02 AM »
in scripts/game.script
on "RightClick"
{
// if inventory item selected? deselect it
if (Game.SelectedItem != null){
Game.SelectedItem = null;
return;
}
var ActObj = Game.ActiveObject;
// is the righ-click menu visible? hide it
if(WinMenu.Visible == true) WinMenu.Visible = false;
else if(ActObj!=null)
{
// if the clicked object can handle any of the "verbs", display the right-click menu
if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") || ActObj.CanHandleEvent("LookAt"))
{
// store the clicked object in a global variable MenuObject
MenuObject = Game.ActiveObject;
var Caption = WinMenu.GetControl("caption");
Caption.Text = MenuObject.Caption;
// adjust menu's position
WinMenu.X = Game.MouseX - WinMenu.Width / 2;
if(WinMenu.X < 0) WinMenu.X = 0;
if(WinMenu.X+WinMenu.Width>Game.ScreenWidth) WinMenu.X = Game.ScreenWidth-WinMenu.Width;
WinMenu.Y = Game.MouseY - WinMenu.Height / 2;
if(WinMenu.Y<0) WinMenu.Y = 0;
if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight-WinMenu.Height;
// and show the right-click menu
WinMenu.Visible = true;
// stop the actor from whatever he was going to do
actor.Reset();
}
// no verbs supported, no menu is needed; just send the RightClick event to the object
else ActObj.ApplyEvent("RightClick");
}
Scene.ApplyEvent("RightClick");
}
and scripts/scene.script
on "RightClick"
{
// if inventory item selected? deselect it
if (Game.SelectedItem != null){
Game.SelectedItem = null;
return;
}
var ActObj = Game.ActiveObject;
// is the righ-click menu visible? hide it
if(WinMenu.Visible == true) WinMenu.Visible = false;
else if(ActObj!=null)
{
// if the clicked object can handle any of the "verbs", display the right-click menu
if(ActObj.CanHandleEvent("Take") || ActObj.CanHandleEvent("Talk") || ActObj.CanHandleEvent("LookAt"))
{
// store the clicked object in a global variable MenuObject
MenuObject = Game.ActiveObject;
var Caption = WinMenu.GetControl("caption");
Caption.Text = MenuObject.Caption;
// adjust menu's position
WinMenu.X = Game.MouseX - WinMenu.Width / 2;
if(WinMenu.X < 0) WinMenu.X = 0;
if(WinMenu.X+WinMenu.Width>Game.ScreenWidth) WinMenu.X = Game.ScreenWidth-WinMenu.Width;
WinMenu.Y = Game.MouseY - WinMenu.Height / 2;
if(WinMenu.Y<0) WinMenu.Y = 0;
if(WinMenu.Y+WinMenu.Height>Game.ScreenHeight) WinMenu.Y = Game.ScreenHeight-WinMenu.Height;
// and show the right-click menu
WinMenu.Visible = true;
// stop the actor from whatever he was going to do
actor.Reset();
}
// no verbs supported, no menu is needed; just send the RightClick event to the object
else ActObj.ApplyEvent("RightClick");
}
Scene.ApplyEvent("RightClick");
}
and scripts/scene.script
Code: WME Script
- #include "scripts\base.inc"
- ////////////////////////////////////////////////////////////////////////////////
- on "LeftClick"
- {
- // when the scene is left-clicked, just send the actor to the specified point
- }
- on "RightClick"
- {
- // when the scene is Right-clicked, just send the actor to the specified point
- }