How do I create sprite on peer and broadcast - Multiplayer

0 favourites
  • 11 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • As a peer / host, I need to create a sprite on the screen in a game on mouse-double click at that position. This sprite needs to be broadcast to all other peers...I am trying to do this for a while now and have not been able to get across. Could some one please help?

    The exact issue is - I am able to create the sprite on peer with a double click, but unable to get it positioned at the mouse-double click position...It gets created on top-left corner at 0,0 position for x,y co-ordinates.

    Inside Peer group - I am setting client input state "x" and client input state "y" on mouse-double click event and sending a message with "create" tag...and

    on Host I have event/action as - On peer message "create" --> create sprite at Multiplayer.Peerstate("peerID", "x") / Multiplayer.Peerstate("peerID", "y")

    But somehow the above code doesnt seem to work in a desired fashion...any help is appreciated

  • [quote:3g2s1ofr]Start

    [quote:3g2s1ofr]Condition: Onstart layout

    action: Sync Sprite (position only)

    Connect etc etc

    [quote:3g2s1ofr]Host

    [quote:3g2s1ofr]condition: On doubleclick

    action: Create sprite at (mouse.x,mouse.y)

    [quote:3g2s1ofr]condition: On message "sprite"

    action: create sprite at (int(tokenat(multiplayer.message,0,"_")),int(tokenat(multiplayer.message,1,"_"))

    [quote:3g2s1ofr]Peer

    [quote:3g2s1ofr]condition: on doubleclick

    action: send message tag: "sprite" message: mouse.x&"_"&mouse.y

    I don't have C2 in front of me now, I might miss something, theoretically this should work.

  • This sprite needs to be broadcast to all other peers...I am trying to do this for a while now and have not been able to get across.

    The only reason sprite is not created on all peer is you didn't sync it with position. It might be created on the default (-1000,-1000).

  • Thanks DuckfaceNinja, I will try this...

    I have a sync - position on sprite...But I was thinking set client input state "x" and "y" to mouse.x / mouse.y on double click and using create sprite at Multiplayer.peerstate("peerid","x") and Multiplayer.peerstate("peerid", "y") should do the trick...I didnt try sending the mouse.x, mouse.y in the message directly...Do you know what is wrong with my approach?

  • I have a sync - position on sprite...But I was thinking set client input state "x" and "y" to mouse.x / mouse.y on double click and using create sprite at Multiplayer.peerstate("peerid","x") and Multiplayer.peerstate("peerid", "y") should do the trick...I didnt try sending the mouse.x, mouse.y in the message directly...Do you know what is wrong with my approach?

    There's nothing wrong with your approach, but it's rather complicate things, I would say it's a not-so-good practice rather than being wrong for something that simple. It's unclear with your Multiplayer.peerstate("peerid","x"), it seems it doesn't associated with any object. Check this first.

    Why?

    Send message will provide pin point accuracy at the double click event on peer.

    If you use sync, the position might be a bit shifted (might even be outside of the screen) depends on the current mouse.x mouse.y on host.

    The difference between sync and send message in terms of usage is as follow:

    Sync is the equivalent of every tick occurence. (actually not equivalent, but same principle)

    Send message is the equivalent of trigger.

    Double-click is a trigger, so it is more intuitive to use send message. If you worry the mouse.x and mouse.y is hackable by peer, you can always restrict the condition in host.

    What game genre are you working anyway?

  • I prefer send message for something like this...

    What DuckfaceNinja said.

    Anyways, I was at my C2, so did a quick small capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • for this help....In the Pong example, multiplayer.peerstate("peerid","y") is used in the host group to position the paddle -

    [attachment=0:3aq1jw7d][/attachment:3aq1jw7d]

    I was trying to use the same approach to create the sprite at the mouse double clicked position...I have used associate peerid etc., as per the pong example...But somehow this approach is not working...cant figure out why...I am trying to understand basics of multiplayer so that I can create something...not yet started on any particular game as such for now...

  • Thanks am now able to make it work with send message approach...Its just that I am still trying to understand what works in MP and what doesnt work in MP...Please see my post in C2 general on multiplayer - questions -

  • Thanks am now able to make it work with send message approach...Its just that I am still trying to understand what works in MP and what doesnt work in MP...Please see my post in C2 general on multiplayer - questions -

    Trust me when I say... Me too. It is a lot of trial and error.

    Edit: the pong example needs the paddle to move every tick of the game.

    Messages are used when something happens it triggers.

    Controls are usually being read every tick, and in pong you want that functionality. Sending messages every tick is looking for trouble.

    That is what sync is for.

    I'm still unraveling all this myself.

  • for this help....In the Pong example, multiplayer.peerstate("peerid","y") is used in the host group to position the paddle

    That is because it is necessary to track the mouse cursor position in pong, so the question is, do you need to track the mouse position? If not, then use send message, there's no reason to increase the networking load by sync.

    I am trying to understand basics of multiplayer so that I can create something

    If you have a good understanding of the event system, almost everything in MP is some sort of very similar in flow, you just got to find the "relation/equivalent".

  • Thanks to DuckfaceNinja and DUTOIT, I finally managed to get this done with some trial and error but still not satisfied with the complete solution...You can get the capx in the below link as to how it is done and some hitches that I still need to research upon...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)