newBie here

Members

8

• Rank
Newbie
1. Best way to check collision for many elements

Hi, i am curious what is best way to make collision. At this moment I make it this way: i have all elements with collision in an array and i iterate through it and calculate distance this way: let dx = this._enemies[i].cords.x - this._players[y].cords.x; let dy = this._enemies[i].cords.y - this._players[y].cords.y; let distance = Math.sqrt(dx * dx + dy * dy); if(distance < 100) { //collision } This calculations make a sphere. We can do it this way to get a square or rectangle: if(Math.abs(sprite1.x - sprite2.x) < 100 && Math.abs(sprite1.y - sprite2.y) < 10) { //collison } I think this is not the best method, because lets imagine we have 1000 things with collision. We have to calculate their distance 1000x1000 = 1000000 times per frame. My second thought is a 2d array that pretends to be map. If object is on x=200 and y=200 we can assign it like this map[200][200] = 1. And then another object check is that place is free (there will be 0 then). Its good when the object is 1 pixel wide and high. For larger objects it could be harder to implement. How are you doing this?
2. Pixi Layers - request for an explanation

I dont use pixi-v5 because my game is cut and the app is smaller with the same code for pixi-v4 (you can see it in screenshots) pixi-v5: <script src="https://pixijs.download/v5.1.0/pixi.min.js"></script> pixi-v4: <script src="https://pixijs.download/v4.4.2/pixi.min.js"></script> I init my game with same code i posted in first post. My game just look better in pixi-v4. Do you now what cause that?
3. Pixi Layers - request for an explanation

Ok i did it with second container, thanks. I have trouble with understanding this because it feels for me incomprehensible why it cant be done with simple sprite.zIndex = 1, sprite.zIndex = 2 like in CSS It is quite complicated for me, but i believe its because canvas limit When i end making this game is it good idea to post link to it here (maybe with source code?) to get some code review, criticism and advice? Thank you for your help
4. Pixi Layers - request for an explanation

Ok, thank you. I used the fast script from https://github.com/pixijs/pixi-layers/wiki#how-to-not-use-pixi-display. Now players are above enemies, it works great. Next problem is: how can i move only one sprite to bottom? When enemy is killed he leaves a blood stain which cover other enemies which were added later than him. I want to move a single sprite from enemiesArray on their death moment to bottom. Also when i try to add image to my post on this forum i get error: /var/www/html/uploads/monthly_2019_07 could not be created. Please contact us for assistance. So you can see screen shot with my problem here: https://ibb.co/xShxJ1f
5. Pixi Layers - request for an explanation

Hello I have problem in understanding how pixi layers work. I want to make some layers like top one, mid and bottom. I want to add players to the top layer, enemies to mid and move dead enemies to bottom layer. I tried to do this, but my sprites are invisible now. Can you provide minimum working code for pixiv4 for my problem? I init player this way: this.player = new PIXI.Sprite(texture_hero); this.player.anchor.set(0.5, 0.7); this.player.x = cords.x; this.player.y = cords.y; this.player.visible = true; container.addChild(this.player); This is how i init pixi: var type = "WebGL" if (!PIXI.utils.isWebGLSupported()) { type = "canvas" } const app = new PIXI.Application(1000, 800, { transparent: false, backgroundColor: '0x000000' }); document.body.appendChild(app.view); //var layer = new PIXI.display.Layer(); //stage.addChild(layer); var container = new PIXI.Container(); app.stage.addChild(container); My game is quite big and its hard to select code to post it here to explain my problem. If something is unclear i can post more. Thank you for your time
6. javascript Pixi layers problem

Ah okay, stupid mistake I have no errors now. Its hard to me to understand how this work, and i dont know what am i doing lol So i have this code var type = "WebGL" if (!PIXI.utils.isWebGLSupported()) { type = "canvas" } const app=new PIXI.Application(1000,800,{ transparent:false, backgroundColor:'0x000000' }); document.body.appendChild(app.view); //var layer = new PIXI.display.Layer(); //stage.addChild(layer); var container = new PIXI.Container(); app.stage.addChild(container); /*var enemiesGroup = new PIXI.display.Group(0, true); enemiesGroup.on('sort', function(sprite) { sprite.zOrder = 1; });*/ var playersGroup = new PIXI.display.Group(1, function(sprite) { sprite.zOrder = 3; }); var enemiesGroup = new PIXI.display.Group(1, function(sprite) { sprite.zOrder = 2; }); app.stage = new PIXI.display.Stage(); app.stage.group.enableSort = true; //layers app.stage.addChild(new PIXI.display.Layer(enemiesGroup)); app.stage.addChild(new PIXI.display.Layer(playersGroup)); var enemyArr = []; var enemyController = function() { this.enemy = null; this.id = 0; this.init = function (cords, id) { this.enemy = new PIXI.Sprite(texture_zombie); this.enemy.anchor.set(0.5); this.enemy.x = cords.x; this.enemy.y = cords.y; this.enemy.visible = true; this.enemy.parentGroup = enemiesGroup; //group this.id = id; container.addChild(this.enemy); }; } Is it enough? I think not because now my sprites disappeared
7. javascript Pixi layers problem

http://fx-team.fulara.com/team/adam/zombie apocalypse.rar As you can see in my game when zombie is killed i am changing its texture to blood and its cover others sprites. Can you look at my code and do code review? Should i change something? Its my first multiplayer game so every tip will be appreciated
8. javascript Pixi layers problem

Hello i have some problems with pixi-layers.js. I want to move some sprites to top. I use pixi.v4 with this script: https://github.com/pixijs/pixi-layers/blob/layers/dist/pixi-layers.js Error message i get: pixi-layers.js:705 Uncaught TypeError: Cannot read property 'prototype' of undefined at pixi-layers.js:705 at pixi-layers.js:744 I add pixi layers in index.html this way: <script src="/socket.io/socket.io.js"></script> <script src="https://pixijs.download/v4.4.2/pixi.min.js"></script> <script src="src/pixi-layers.js"></script> <script src="src/keyboard.js"></script> <script src="src/client.js"></script> What did i do wrong? Thank you for your time.