how to detect the speed and forsce of the mouse

  • shadowkeeper
  • Born
  • Born
  • shadowkeeper
  • Posts: 1

Post 3+ Months Ago

hie all i am a new to flash as well as to this forum also

Code: [ Select ]
this.onEnterFrame = function() {
    //player._y = _ymouse;
    player._x += (_xmouse-player._x)/5;
    if (_xmouse>player._x+5) {
        //trace("X MOuse "+_xmouse);
        //hittest();
        _root.player.gotoAndStop(2);//
    } else if (_xmouse>=430 && _xmouse<=530) {
        _root.player.gotoAndStop(3);
    } else if (_xmouse>=530 && _xmouse<=630) {
        _root.player.gotoAndStop(4);
    } else if (_xmouse<player._x-5) {
        //trace("X MOuse "+_xmouse);
        _root.player.gotoAndStop(11);
    } else if (_xmouse<=200 && _xmouse>=100) {
        _root.player.gotoAndStop(12);
    } else if (_xmouse<=100 && _xmouse>=0) {
        _root.player.gotoAndStop(13);
    } else if (_ymouse<350 ) {
        _root.player.gotoAndStop(21);
    }else if(_ymouse>400){
        _root.player.gotoAndStop(23);
    }else {
        _root.player.gotoAndStop(1);
    }
};
  1. this.onEnterFrame = function() {
  2.     //player._y = _ymouse;
  3.     player._x += (_xmouse-player._x)/5;
  4.     if (_xmouse>player._x+5) {
  5.         //trace("X MOuse "+_xmouse);
  6.         //hittest();
  7.         _root.player.gotoAndStop(2);//
  8.     } else if (_xmouse>=430 && _xmouse<=530) {
  9.         _root.player.gotoAndStop(3);
  10.     } else if (_xmouse>=530 && _xmouse<=630) {
  11.         _root.player.gotoAndStop(4);
  12.     } else if (_xmouse<player._x-5) {
  13.         //trace("X MOuse "+_xmouse);
  14.         _root.player.gotoAndStop(11);
  15.     } else if (_xmouse<=200 && _xmouse>=100) {
  16.         _root.player.gotoAndStop(12);
  17.     } else if (_xmouse<=100 && _xmouse>=0) {
  18.         _root.player.gotoAndStop(13);
  19.     } else if (_ymouse<350 ) {
  20.         _root.player.gotoAndStop(21);
  21.     }else if(_ymouse>400){
  22.         _root.player.gotoAndStop(23);
  23.     }else {
  24.         _root.player.gotoAndStop(1);
  25.     }
  26. };


here i am moving my player with the mouse but it is playing 2 aminations at the same time when the mouse is moved above 430 it is playing two animations


i wanted if the mouse is slightly moved right then it should play the first animation of the right side and if mouse is moved with some force it should play the second animation and if the mouse is moved with greater force it should play the third animation and the same for the left side and the top side how to this an suggestions plzz
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ibrabdo
  • Novice
  • Novice
  • User avatar
  • Posts: 29

Post 3+ Months Ago

try this code (just for the x axis you can do the same thing for the y axis):
Code: [ Select ]
this.onLoad = function(){
    Posstart = 0 ;
    Posend = _root.player._x ;
    displace = 0 ;
    time = 0 ;
};
this.onEnterFrame = function(){
    player._x += (_xmouse-player._x)/5;
    Posstart = Posend ;
    Posend = _root.player._x ;
    displace = Posstart - Posend ;
    trace(displace);
    if(Math.abs(displace)< 20 && time == 0){
        _root.player.gotoAndStop(1);
    }
    if(Math.abs(displace)> 20 && Math.abs(displace)< 50 && time == 0){
        _root.player.gotoAndStop(2);
    }
    if(Math.abs(displace)> 50 ){
        _root.player.gotoAndStop(3);
        time = 1 ;
    }
    if(time>0 && time < 10){
        time += 1 ;
    }else{
        time = 0 ;
    }
};
  1. this.onLoad = function(){
  2.     Posstart = 0 ;
  3.     Posend = _root.player._x ;
  4.     displace = 0 ;
  5.     time = 0 ;
  6. };
  7. this.onEnterFrame = function(){
  8.     player._x += (_xmouse-player._x)/5;
  9.     Posstart = Posend ;
  10.     Posend = _root.player._x ;
  11.     displace = Posstart - Posend ;
  12.     trace(displace);
  13.     if(Math.abs(displace)< 20 && time == 0){
  14.         _root.player.gotoAndStop(1);
  15.     }
  16.     if(Math.abs(displace)> 20 && Math.abs(displace)< 50 && time == 0){
  17.         _root.player.gotoAndStop(2);
  18.     }
  19.     if(Math.abs(displace)> 50 ){
  20.         _root.player.gotoAndStop(3);
  21.         time = 1 ;
  22.     }
  23.     if(time>0 && time < 10){
  24.         time += 1 ;
  25.     }else{
  26.         time = 0 ;
  27.     }
  28. };

i wish if this could help you ...
  • ibrabdo
  • Novice
  • Novice
  • User avatar
  • Posts: 29

Post 3+ Months Ago

And if u want to detect the speed and the force of the mouse you can try the same thing with the _xmouse:
Code: [ Select ]
this.onLoad = function(){
    Posstart = 0 ;
    Posend = _root._xmouse ;
    displace = 0 ;
};
this.onEnterFrame = function(){
    Posstart = Posend ;
    Posend = _root._xmouse ;
    displace = Posstart - Posend ;
    trace(displace);
};
  1. this.onLoad = function(){
  2.     Posstart = 0 ;
  3.     Posend = _root._xmouse ;
  4.     displace = 0 ;
  5. };
  6. this.onEnterFrame = function(){
  7.     Posstart = Posend ;
  8.     Posend = _root._xmouse ;
  9.     displace = Posstart - Posend ;
  10.     trace(displace);
  11. };


the value of "displace" gives you here the force and the speed of the mouse

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 10 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.