触发双击功能,并按住最后一次点击 AS3
Trigger double click function, and holding on the last click AS3
我有一个游戏,我的角色向右或向左移动,有一个 MOUSE_DOWN 事件监听器。角色跳跃,带有 DOUBLE_CLICK 事件监听器。
我想要这样,如果玩家双击 并按住最后一次单击 ,那么角色就会跳跃并移动。
就像现在一样,跳跃功能只有在玩家双击并释放鼠标时才有效。
这有可能吗??
所以只是为了让它更清楚一点。当玩家双击并松开时,角色会跳到他站立的地方。这已经有效。
但是如果玩家双击并按住,那么跳跃功能和移动功能都应该被触发。
提前致谢!
包{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Main extends MovieClip {
public var character:Character = new Character;
public var world:World = new World;
var moveRight:Boolean = false;
var moveLeft:Boolean = false;
var jumping:Boolean = false;
var moveSpeed:Number = 1;
var orgMoveSpeed:Number = 1;
var accSpeed:Number = 0.6;
var maxMoveSpeed:Number = 20;
var gravity:Number = 1;
var orgGrav:Number = 1;
var gravAcc:Number = 0.6
var maxFallSpeed:Number = 15;
var jumpPower:Number = 15;
var jumpGrav:Number = 0.6;
var orgJumpPower:Number =15;
public function Main() {
// constructor code
addChild(world)
addChild(character)
stage.doubleClickEnabled=true;
stage.addEventListener(MouseEvent.MOUSE_DOWN, moveFunction)
stage.addEventListener(MouseEvent.MOUSE_UP, stopMoveFunction)
stage.addEventListener(MouseEvent.DOUBLE_CLICK, jumpFunction)
addEventListener(Event.ENTER_FRAME, moveWorld)
}
function moveFunction(m:MouseEvent)
{
//If the player clicks on right side of the screen, the player moves right.. etc.
if(mouseX>stage.stageWidth/2)
{
moveRight = true
}else{
moveLeft = true
}
}
function stopMoveFunction(m:MouseEvent)
{
moveLeft = false;
moveRight = false;
}
function jumpFunction(m:MouseEvent)
{
if(hitGroundCol)
{
jumping=true;
}
}
function moveWorld(e:Event)
{
//_______MOVE FUNCTION _____________________
if (moveRight)
{
world.x -= moveSpeed
moveSpeed += accSpeed
character.OddSlugViz.rotation += moveSpeed
}else if (moveLeft)
{
world.x += moveSpeed
moveSpeed += accSpeed
character.OddSlugViz.rotation -= moveSpeed
}else{
moveSpeed = orgMoveSpeed;
}
if (moveSpeed>maxMoveSpeed)
{
moveSpeed = maxMoveSpeed;
}
//_________Jump_________________
if (jumping)
{
world.y += jumpPower
jumpPower -= jumpGrav
if (jumpPower<1)
{
jumping = false;
jumpPower = orgJumpPower;
}
}
}
}
}
一个简单的解决方案是跟踪一次单击甚至启动计时器或超时,如果另一个鼠标按下事件在时间限制内发生(100 毫秒?您必须测试以了解您想要的自然程度它), 然后执行事件.. 这样你就可以跟踪鼠标是否被按住, 并且它是双击, 而无需使用双击事件。
我有一个游戏,我的角色向右或向左移动,有一个 MOUSE_DOWN 事件监听器。角色跳跃,带有 DOUBLE_CLICK 事件监听器。 我想要这样,如果玩家双击 并按住最后一次单击 ,那么角色就会跳跃并移动。 就像现在一样,跳跃功能只有在玩家双击并释放鼠标时才有效。 这有可能吗??
所以只是为了让它更清楚一点。当玩家双击并松开时,角色会跳到他站立的地方。这已经有效。 但是如果玩家双击并按住,那么跳跃功能和移动功能都应该被触发。
提前致谢!
包{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.events.Event;
public class Main extends MovieClip {
public var character:Character = new Character;
public var world:World = new World;
var moveRight:Boolean = false;
var moveLeft:Boolean = false;
var jumping:Boolean = false;
var moveSpeed:Number = 1;
var orgMoveSpeed:Number = 1;
var accSpeed:Number = 0.6;
var maxMoveSpeed:Number = 20;
var gravity:Number = 1;
var orgGrav:Number = 1;
var gravAcc:Number = 0.6
var maxFallSpeed:Number = 15;
var jumpPower:Number = 15;
var jumpGrav:Number = 0.6;
var orgJumpPower:Number =15;
public function Main() {
// constructor code
addChild(world)
addChild(character)
stage.doubleClickEnabled=true;
stage.addEventListener(MouseEvent.MOUSE_DOWN, moveFunction)
stage.addEventListener(MouseEvent.MOUSE_UP, stopMoveFunction)
stage.addEventListener(MouseEvent.DOUBLE_CLICK, jumpFunction)
addEventListener(Event.ENTER_FRAME, moveWorld)
}
function moveFunction(m:MouseEvent)
{
//If the player clicks on right side of the screen, the player moves right.. etc.
if(mouseX>stage.stageWidth/2)
{
moveRight = true
}else{
moveLeft = true
}
}
function stopMoveFunction(m:MouseEvent)
{
moveLeft = false;
moveRight = false;
}
function jumpFunction(m:MouseEvent)
{
if(hitGroundCol)
{
jumping=true;
}
}
function moveWorld(e:Event)
{
//_______MOVE FUNCTION _____________________
if (moveRight)
{
world.x -= moveSpeed
moveSpeed += accSpeed
character.OddSlugViz.rotation += moveSpeed
}else if (moveLeft)
{
world.x += moveSpeed
moveSpeed += accSpeed
character.OddSlugViz.rotation -= moveSpeed
}else{
moveSpeed = orgMoveSpeed;
}
if (moveSpeed>maxMoveSpeed)
{
moveSpeed = maxMoveSpeed;
}
//_________Jump_________________
if (jumping)
{
world.y += jumpPower
jumpPower -= jumpGrav
if (jumpPower<1)
{
jumping = false;
jumpPower = orgJumpPower;
}
}
}
}
}
一个简单的解决方案是跟踪一次单击甚至启动计时器或超时,如果另一个鼠标按下事件在时间限制内发生(100 毫秒?您必须测试以了解您想要的自然程度它), 然后执行事件.. 这样你就可以跟踪鼠标是否被按住, 并且它是双击, 而无需使用双击事件。