How do I create sprite on peer and broadcast - Multiplayer

Get help using Construct 2

Post » Mon Oct 13, 2014 8:52 am

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
For game development / IT services contact - [email protected]

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
84
S
20
G
3
Posts: 337
Reputation: 7,368

Post » Mon Oct 13, 2014 9:06 am

Start
Condition: Onstart layout
action: Sync Sprite (position only)
Connect etc etc


Host
condition: On doubleclick
action: Create sprite at (mouse.x,mouse.y)

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


Peer
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.
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Mon Oct 13, 2014 9:11 am

kmsravindra wrote: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).
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Mon Oct 13, 2014 9:19 am

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?
For game development / IT services contact - [email protected]

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
84
S
20
G
3
Posts: 337
Reputation: 7,368

Post » Mon Oct 13, 2014 9:37 am

kmsravindra wrote: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?
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Post » Mon Oct 13, 2014 9:48 am

I prefer send message for something like this...
What DuckfaceNinja said.

Anyways, I was at my C2, so did a quick small capx
You do not have the required permissions to view the files attached to this post.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,708

Post » Mon Oct 13, 2014 9:53 am

@DuckfaceNinja...Thanks for this help....In the Pong example, multiplayer.peerstate("peerid","y") is used in the host group to position the paddle -
scan2.jpg


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...
You do not have the required permissions to view the files attached to this post.
For game development / IT services contact - [email protected]

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
84
S
20
G
3
Posts: 337
Reputation: 7,368

Post » Mon Oct 13, 2014 9:55 am

Thanks @DUTOIT...I 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 - some-multiplayer-questions-could-someone-please-educate_p844220?#p844220
For game development / IT services contact - [email protected]

List of published iOS apps -
https://itunes.apple.com/us/artist/ravi ... d693234511
B
84
S
20
G
3
Posts: 337
Reputation: 7,368

Post » Mon Oct 13, 2014 10:04 am

kmsravindra wrote:Thanks @DUTOIT...I 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 - some-multiplayer-questions-could-someone-please-educate_p844220?#p844220


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.
You think you can do these things, but you can't, Nemo!
Just keep reading.
Just keep learning.
B
65
S
16
G
9
Posts: 1,429
Reputation: 12,708

Post » Mon Oct 13, 2014 10:20 am

kmsravindra wrote:@DuckfaceNinja...Thanks 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.

kmsravindra wrote: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".
B
28
S
8
G
4
Posts: 553
Reputation: 4,924

Next

Return to How do I....?

Who is online

Users browsing this forum: elafreat, facecrime, Yahoo [Bot] and 32 guests