Newgrounds.com — Everything, By Everyone.

Checking login status…

USERNAME:

PASSWORD:

Logging in…

Logged in as:
.
Logging out…
Inbox My Account Log Out


Forum Topic: i cant get megaman._x to = _xmouse

(99 views • 8 replies)

This topic is 1 page long.

<< < > >>
Sad

AlysiumX

Reply To Post Reply & Quote

Posted at: 5/14/08 08:11 AM

AlysiumX NEUTRAL LEVEL 04

Sign-Up: 11/25/04

Posts: 9

code is as follows :

//if megaman is = to x mouse
if(Math.round(megaman._x) == Math.round(_xmouse)) {
if(mousex == 0 || mousex == 1)
megaman.gotoAndPlay(21);
mousex = 2;
}
//if megaman is greater than x mouse
if(Math.round(megaman._x) > Math.round(_xmouse)){
megaman._x = megaman._x -5;
if(mousex == 1 || mousex == 2)
megaman.gotoAndPlay(67);
mousex = 0;
}
//if megaman is less than x mouse
if(Math.round(megaman._x) < Math.round(_xmouse)){
megaman._x = megaman._x +5;
if(mousex == 0 || mousex == 2)
megaman.gotoAndPlay(53);
mousex = 1;
}

now heres where the problem comes in, say my mouse is at 5 and megaman is at 5, if i move my mouse to 4, megaman is now greater than my mouse (if megaman is > _xmouse) however, megaman can not move, because i told him to move -5(megaman._x = megaman._x - 5;) if he move negative 5 he is now less than 5 and not equal to( -5 + 4 = -1), so he just doesn't move at all. plz help, thx in advance.


None

Cojones893

Reply To Post Reply & Quote

Posted at: 5/14/08 08:19 AM

Cojones893 EVIL LEVEL 21

Sign-Up: 03/09/03

Posts: 2,193

if(Math.round(megaman._x) < Math.round(_xmouse)+5 && Math.round(megaman._x) > Math.round(_xmouse)-5){
megaman._x = _xmouse;
}

This will check to see if your megaman is within a certain range of xmouse. Xmouse+5 and xmouse-5. If he is within that range it just sets him to the xmouse.


None

AlysiumX

Reply To Post Reply & Quote

Posted at: 5/14/08 08:28 AM

AlysiumX NEUTRAL LEVEL 04

Sign-Up: 11/25/04

Posts: 9

ok i almost got it, that code works ,but i just relized i need to add if(megaman._x > _.xmouse - 60) in the case where i add -60 what would i change the value to of the script you just gave me?


None

AlysiumX

Reply To Post Reply & Quote

Posted at: 5/14/08 08:35 AM

AlysiumX NEUTRAL LEVEL 04

Sign-Up: 11/25/04

Posts: 9

nvm, my values are all screwed up, im gonna have to figure this out....


None

AlysiumX

Reply To Post Reply & Quote

Posted at: 5/14/08 08:40 AM

AlysiumX NEUTRAL LEVEL 04

Sign-Up: 11/25/04

Posts: 9

ok heres whats going on now, hes a little offset from the mouse, so i need to add - 60 to put him on the center of the mouse, im just wondering how the code you just game me , works with a - 60 offset.


None

AlysiumX

Reply To Post Reply & Quote

Posted at: 5/14/08 08:42 AM

AlysiumX NEUTRAL LEVEL 04

Sign-Up: 11/25/04

Posts: 9

At 5/14/08 08:40 AM, AlysiumX wrote: ok heres whats going on now, hes a little offset from the mouse, so i need to add - 60 to put him on the center of the mouse, im just wondering how the code you just game me , works with a - 60 offset.

if(Math.round(megaman._x) == Math.round(_xmouse - 60)) {
if(mousex == 0 || mousex == 1)
megaman.gotoAndPlay(21);
mousex = 2;
}
if(Math.round(megaman._x) > Math.round(_xmouse - 60)){
megaman._x = megaman._x - 5;
if(mousex == 1 || mousex == 2)
megaman.gotoAndPlay(67);
mousex = 0;
}
if(Math.round(megaman._x) < Math.round(_xmouse - 60)){
megaman._x = megaman._x + 5;
if(mousex == 0 || mousex == 2)
megaman.gotoAndPlay(53);
mousex = 1;
}

if(Math.round(megaman._x) < Math.round(_xmouse)+5 && Math.round(megaman._x) > Math.round(_xmouse)-5){
megaman._x = _xmouse;
}


None

Cojones893

Reply To Post Reply & Quote

Posted at: 5/14/08 09:03 AM

Cojones893 EVIL LEVEL 21

Sign-Up: 03/09/03

Posts: 2,193

if(Math.round(megaman._x) < Math.round(_xmouse)-55 && Math.round(megaman._x) > Math.round(_xmouse)-65){
megaman._x = _xmouse-60;
}

None

West-End-Pro

Reply To Post Reply & Quote

Posted at: 5/14/08 09:24 AM

West-End-Pro NEUTRAL LEVEL 23

Sign-Up: 02/15/06

Posts: 2,350

Are you calling the code every frame? i.e.

onEnterFrame = function():Void{
// your code here
}


Elated

AlysiumX

Reply To Post Reply & Quote

Posted at: 5/14/08 10:15 AM

AlysiumX NEUTRAL LEVEL 04

Sign-Up: 11/25/04

Posts: 9

i got it thanks for all your help : )


All times are Eastern Daylight Time (GMT -4) | Current Time: 12:17 AM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!