cykod / Quintus

HTML5 Game Engine
http://html5quintus.com
GNU General Public License v2.0
1.41k stars 401 forks source link

Collision isn't working in Breakout example #125

Closed Stumpftopf closed 10 years ago

Stumpftopf commented 10 years ago

Hi, i'm working on a litte game. The player just catches some symbols who are falling down from the top to to bottom with a paddle. Now the problem is, the collision will detect only the first time, then I delete the object with this.destroy(); after that i add a new symbol object with this.stage.insert(new Q.Icon()); this works fine, but if the player now tries to catch that new object, the collision won't be triggered.

I am using Chrome: Version 35.0.1916.153 and also tried to use firefox, but same problem.

The breakout example, has the same problem: http://html5quintus.com/quintus/examples/breakout/

cykod commented 10 years ago

Looks like the defaults types and masks aren't resulting in collision (http://html5quintus.com/quintus/examples/collision/ is broken too) - I'll what changed

ghost commented 10 years ago

Breakout example doesn't work but the collision example does.

Stumpftopf commented 10 years ago

"http://html5quintus.com/quintus/examples/collision/ is broken too" Seems to work for me.... @cykod If i can help in anyway, you can send me a message, maybe the source from my game or something else.

derpepe commented 10 years ago

+1 would be great if we can have this fixed asap ;)

cykod commented 10 years ago

Looking into the fix - this seems to just be a recently introduced problem when using a parent container with a scale - most games shouldn't be affected.

derpepe commented 10 years ago

But the canvas is a parent container, so most games should be affected. Or am I wrong? Not sure...

cykod commented 10 years ago

No, canvas isn't a container - only if you explicitly use Q.insert with a parent. Running a git-bisect this weekend to figure out where the problem started.

Stumpftopf commented 10 years ago

Sorry, dude. It's still broken... Only works correct with: .setup({ maximize: true }) but not if i set it like this: .setup({width: 800, // Set the default width to 800 pixels height: 600, // Set the default height to 600 pixels scaleToFit: false // Scale the game to fit the screen of the player's device })

viki53 commented 10 years ago

What if you delete the scaleToFit option?

[EDIT] My bad, it's false so it shouldn't be a problem anyway…

cykod commented 10 years ago

@Stumpftopf - ?

Just changed "breakout.js" line 6 in the latest master to read:

  .setup({ width:800, height: 600, scaleToFit: false })

And it works just fine - the background doesn't match the game but all the collisions are correct. Can you set Q.debug=true and take a screen shot of what you're seeing?

viki53 commented 10 years ago

If have the same bug on the breakout demo: the balls goes through the bricks without deviating nor colliding.

Maybe it's a simple matter of collisionLayer ?

Stumpftopf commented 10 years ago

@cykod @viki53 I think the problem isn't the collisionLayer, cause the first time, the icon hits the paddle (x: 0 ) the collision works:

bildschirmfoto 2014-07-16 um 08 01 20

But if x is bigger then the width of the paddle, collision don't work: bildschirmfoto 2014-07-16 um 08 02 23

The collision points looks good to me, i think the problem is maybe a wrong scale of the "world" or matrix.

Here is the source of my little game: https://bitbucket.org/benjamin_schneider/dropgame-js

I hope it can help to fix that.

cykod commented 10 years ago

@Stumpftopf - No, you're just colliding with the background on each frame so it's not colliding with the player. Set the type of the background to 0 and you should be fine. The fact that there's a collision on each frame should have been a tip off.

Q.Sprite.extend("Background",{
    init: function(p) {
      this._super(p, {
           x: Q.width/2,
           y: Q.height/2,
           type: 0, // if you don't set the type to zero the icon will collide with it on each frame.
           asset: "background.png"
      });
    }
});
Stumpftopf commented 10 years ago

@cykod Now it works! Thx.

ghost commented 10 years ago

the breakout example in the quintus website has to be updated.

NikunjShah commented 9 years ago

I think I have a similar issue with collision detection. My Player sprite and enemy sprite does collide initially and then both just pass through without any collision. I also tried setting the Background sprite to type 0, but still the issue persists.

Note :- Earlier this issue was occuring on my desktop as well, but now it occurs on mobile devices only.