Thelifeofpbion Posted June 28, 2019 Share Posted June 28, 2019 I need help with creating objects in pixi In the backend I have a code running every 1000 millisecond, which passes the id, and x and y positions and I made a for that runs through the list of players. but when the first player comes in, it picks up the sprite "cat" which is a variable. then when the second player enters it also picks up the same variable, but as the first one already had it it becomes invisible. I need help, so that every id I pass in is for it to take an instance of "cat" and if I put the cat variable inside the for it gets creating several cat. const texture = PIXI.Texture.from('images/cat.png'); let cat = new Sprite(texture); const socket = io(); socket.on('newPositions',function(data){ // recebe o pacote 'newPosition' for(let i= 0;i < data.length; i++){ // fazendo um for do tamanho da data cat.x = data[i].x; cat.y = data[i].y; app.stage.addChild(cat); } Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 28, 2019 Share Posted June 28, 2019 I think its more about coding than about PixiJS. Coding multiplayer games is very hard, and by the level of your question I prognoze that you will have really many questions that can be answered just from books or tutorials. I can move this thread to http://www.html5gamedevs.com/forum/2-coding-and-game-design/ if you want. Its better if you actually go through the tutorial https://github.com/kittykatattack/learningPixi, all the examples https://pixijs.io/examples/#/ , version 5 wiki: https://github.com/pixijs/pixi.js/wiki . As for your current problem, you actually have two of them: 1) addChild adds same cat to screen, it does not copy the element you pass to it, it actually re-adds the same cat. You have to create several Sprites instead. 2) you have to remember all that cats somewhere, by using "app.stage.children" or your own array in a variable. Otherwise , for each socket message you will spawn new cats instead of moving old ones. Thelifeofpbion 1 Quote Link to comment Share on other sites More sharing options...
8Observer8 Posted July 9, 2019 Share Posted July 9, 2019 @Thelifeofpbion I found this article: http://buildnewgames.com/real-time-multiplayer/ I think it is useful. Quote We will look at input prediction, lag compensation, client interpolation and more importantly - how to do this in your normal browser using websockets. The article will present a playable demo with parameters to play with, showcasing the concepts discussed. You can use Heroku that allows to connect with GitHub. When you "push" your commits your game will be rebuilt on Heroku. Start here: Thelifeofpbion 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.