Collision borders
krumza

Perhaps this question has been asked time and again but I'll repeat it again

I not using a physics plugin to make a clear definition of the boundaries of the object for hitting him and you see result:

Here live example.

 

I use this for my bullets:

var collidingObjects = this.getOverlappingObjects();                    
for (var i=0; i<collidingObjects.length; i++)
{
  if (collidingObjects[i].type == 'stone'){
     var pos = collidingObjects[i].getPosition();
     wade.removeSceneObject(collidingObjects[i]);
      wade.removeSceneObject(this);
     wade.playAudio('bah.mp3');
     wade.app.preShake();
     wade.app.createsplash(pos.x,pos.y);
     break;
  } 
}        

But as you see the collision occurs at the boundaries of the rectangle.

Please say me how i must to solve this problem.

Connect is a physical plug-in? wouldn't it reduce the performance?

Anticipating your answer "use myObject.overlapsObject(otherObject, 'pixel');" It strongly reduce performance

 I will answer that already wrote about this bug, and additionally sometimes editor WADE crashes because of this feature, deleting an object in which it was written

do otherwise raise the issue I wanted to make a system of many layers and graphic view to leave on one layer and the procedural sprites for attacks on another to use use myObject.overlapsObject(otherObject, 'oriented'); - but rested in the fact that after the 8th layer starts to slow down wildly don't understand why. is there a limit to 2D layers?

Moreover I don't understand what the delay occurs if these objects if there all in one screen

i add 

        planet1sprite.alwaysDraw(false);
        planet1sprite.cache();

to all planets sprites and violation  disappear

do not understand anything...

1 Comment
Gio

Hi

Checking for pixel-perfect overlaps is indeed very expensive. It depends on the size of the images that you are using: with a larger size we need to test more pixels. Even if the image was small, it'd be a bit expensive, so I would avoid it.

Using the physics system wouldn't be so bad in terms of performance, and it would allow you to define absolutely any shape, not just rectangles for collisions. It's probably quicker than you would think.

However if you want to keep it simpler with no physics and only using rectangles, you could add an invisible (smaller) sprite to your ship, that only covers part of the body. Then you could check for overlaps with that sprite, instead of looking for overlaps with the whole ship object.

A similar idea would be that of splitting the ship into multiple sprites, for example 1 sprite for the body, 2 sprites for the wings. This would also work.

To answer your question about layers - yes, currently having many layers can slow things down considerably, especially if they are all WebGL layers. If you have a static background layer, it's much better to set it as a canvas layer.

The problem with the current layer system, is that each layer is a separate WebGL context - so having many of them creates a lot of contexts, and a lot of context switching is required to render each frame. In short, this is slow.

But...

With WADE 3.7 we have rewritten the layer system, so WADE detects contiguous WebGL layers and groups them into one single context (with separate frame buffers). This makes it much, much faster.

WADE 3.7 is only a few weeks away, so if you can wait for that it will speed your game up for sure.

Post a reply
Add Attachment
Submit Reply
Login to Reply