Help on avatar chat example

Need help with SmartFoxServer? You didn't find an answer in our documentation? Please, post your questions here!

Moderators: Lapo, Bax

capdetrons
Posts: 72
Joined: 24 Aug 2013, 09:15
Location: Barcelona
Contact:

Help on avatar chat example

Postby capdetrons » 19 Dec 2014, 11:23

Hi,

I am trying to have an avatar collision in my file but I can't seem to understand how events happen.

The onMouseDown function controls the movement of the latest avatar on the stage, right?

I'm trying to have an event ocurr when the character collides against another avatar so, I guess the first one's position variables are updated in the onUserVariablesUpdate function.

I placed a conditional loop in the mouseDown function to see what clips are on stage so I know the collision is happening :

Code: Select all

for (j=0; j<userList_lb.length; j++) {
   var a:Object = userList_lb.getItemAt(j).data;
   // trace("a = "+a);
   var b:MovieClip = board["clip_"+a];
   // trace("b.gender = "+b.gender+newline);
   // trace("myAvatar.gender = "+myAvatar.gender+newline);
   if (myAvatar.gender != b.gender && myAvatar.character.hitTest(b.character)) {
      trace(newline+"myAvatar Hit bClip"+newline);
   }
}


I see it only traces when myAvatar hitTests the other file and I'm attaching an example clip when the collision happens but I don't see how to control the visibility of the avatars from there.

Should I, perhaps try to create a variable to resend to the onUserVariablesUpdate ?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Help on avatar chat example

Postby Lapo » 22 Dec 2014, 10:30

The idea is to test the user's sprite against all other sprites, not just on mouse down but on every frame since other clients are potentially moving all the times.
Lapo
--
gotoAndPlay()
...addicted to flash games
capdetrons
Posts: 72
Joined: 24 Aug 2013, 09:15
Location: Barcelona
Contact:

Re: Help on avatar chat example

Postby capdetrons » 22 Dec 2014, 11:17

Thanks, Lapo,


I am a complete begginer with AS as you can imagine and I've already dedicated a lot of hours to this particular problem.

Does that mean checking elsewhere than onUserVariablesUpdate or onMouseDown? Just that hint, please. Can this be done without having to think about creating more user or room variables?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Help on avatar chat example

Postby Lapo » 22 Dec 2014, 15:13

Yes. You need to check on every frame because both mouse down and variables updates will only tell you what is the new destination of a specific avatar.
Then the client runs the animations from the current position to the new one.

That's where you need to check collisions, during each step of the animation.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
capdetrons
Posts: 72
Joined: 24 Aug 2013, 09:15
Location: Barcelona
Contact:

Re: Help on avatar chat example

Postby capdetrons » 23 Dec 2014, 12:26

Good day,

and thanks, Lapo,

I got it working in a way I don't really understand, but thanks again.

Is it something like the only avatar that can be modified simply is myAvatar?

If I hitTest it agains any other one I can't modify its properties again when the new clip is attached. That is I turn the clip that collides with myAvatar's visibility to false but then I can't set it back again, so I just attach the new clip on top of the avatars to hide them without disabling their visibility.

Anyway, thanks. I need to keep experiencing a lot with this....

Happy new year :)

Return to “SmartFoxServer 1.x Discussions and Help”

Who is online

Users browsing this forum: No registered users and 46 guests