Comments (5)
You shouldn't need to connect any sockets to cell.js.
The client already has an open socket behind the scenes - The job of cell.js is just to add new states/JSON objects to the game grid, move them around (or update them) and also remove them from the game grid when necessary. The user/front end will receive all the JSON objects that are in their cell(s) in real-time (including updates if you change the x/y position of objects in the cell).
You can add additional code to cell.js but you don't need to worry about sockets. In your case you could just create a new 'block' and 'bullet' type to cell.js and create them whenever a payer presses a specific key.
Read this https://github.com/SocketCluster/iogrid/blob/master/cell.js#L1-L45 to see how cell.js works.
In order to interact with players, you need to read data from player.ops
- See how it's currently being used here: https://github.com/SocketCluster/iogrid/blob/master/cell.js#L266-L285 - Every change to the player's state needs to be passed in as player.ops
and processed somewhere in cell.js.
You can add new player.ops properties on the front-end in the main update loop here: https://github.com/SocketCluster/iogrid/blob/master/public/index.html#L360-L376
^ You just send the ops to the server in an 'action' event and it will automatically show up in cell.js as player.ops
.
If you add new objects to cell.js, they will be passed to the front-end in real-time (to this function https://github.com/SocketCluster/iogrid/blob/master/public/index.html#L147-L160), so you will need to render them. Currently only 'player' and 'coin' types are being rendered.
from iogrid.
If IOGrid doesn't suit your needs because you have advanced requirements and really need to control sockets individually, then you probably shouldn't use it and use SocketCluster directly (but that will be a lot of work ;p).
The point of IOGrid lets you make scalable games quickly so it deals with all the complicated networking/socket details for you. Some users have built entire multiplayer games with it in a single weekend but you do need to think about if it's fits your requirements.
from iogrid.
Thank you so much for making this and helping me! I think I'm really close to adding the ability to place linkblocks. The reason why these are "linkblocks" is I want each block to have link metadata tied to it, but I'm mainly just trying to get block placement functionality working. I understand how player operations work now and I can make an action happen when the the place block button is pressed. I've been using your coin-manager.js as a template for creating a linkblock-manager.js and generally just copying your code for adding coins and changing it to blocks in cell.js and index.html.
This has worked up til I get to the addCoin function part. In the addCoin function, new coins are automatically added if the generated random position is valid. However, because I want the user to be able to add blocks on command, in my addLinkblock function I don't know what the "if condition" ought to be. I tried removing the if conditional entirely and making it always true, but in both cases this causes blocks to automatically be added as fast as the cell updates.
In cell.js I'm calling linkblockManager.addLinkblock(player.x, player.y) upon the place block action in the applyPlayerOps function, sort of like how you call coinManager.addCoin() in the dropCoins function. I tried setting playerOp.pb = 0 to prevent it from constantly adding more blocks, but it didn't work. Here's some (possibly) relevant code from linkblock-manager.js:
LinkblockManager.prototype.addLinkblock = function (x, y, link) {
var linkblockId = uuid.v4();
if (true) {
var linkblock = {
id: linkblockId,
type: "linkblock",
link: link,
x: x,
y: y
};
this.linkblocks[linkblockId] = linkblock;
this.linkblockCount++;
return linkblock;
}
return null;
};
...and from cell.js:
if (playerOp.pb) {
var linkblock = self.linkblockManager.addLinkblock(player.x, player.y, player.linkequipped);
if (linkblock) {
linkblocks[linkblock.id] = linkblock;
}
console.log(JSON.stringify(linkblocks));
playerOp.pb = 0;
placedBlock = true;
}
I'm trying to make a prototype world that is capable of having at least dozens of users and at least hundreds of linkblocks simultaneously, so I think IOgrid is perfect for my requirements. I'm ultimately going to want to store the linkblock data in a rethinkdb database. Will this be a problem? Thanks again!
from iogrid.
@austincap You cannot modify the player.op
property from the server-side - This is because the op
property is a special reserved property which is used by the client to pass actions to the server (one direction only).
If you want to attach a new custom property to the player, you can add a custom property directly to the player using: player.pb = true
.
Inside cell.js, treat player.op
as read-only.
from iogrid.
Okay, that makes sense, thanks
from iogrid.
Related Issues (10)
- basic start up error HOT 2
- Can I use yarn install instead of npm install?
- Updating to latest socketcluster version HOT 1
- Error when starting testing/development serve. HOT 8
- [Bug] Delays and map refreshes HOT 2
- Error: listen EADDRINUSE :::15454 HOT 1
- Are there any games currently using this framework? HOT 1
- help
- `iogrid/public/socketcluster.js` can be replaced?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iogrid.