Jump to content

Could use a hand...


deleteme
 Share

Recommended Posts

This is what i have so far related to all that, I'm a bit new to this as well so if you have any suggestions i'll take them! :)

 

function update() {

game.physics.arcade.overlap(bullets, demon, killDemon, null, this);

 

 //Enables bullets to hit demon
  game.physics.arcade.collide(demon, bullets);
  game.physics.arcade.collide(bullets, demon);

}

 

function killDemon (bullet, demon) {
  demon.kill();
  scoreText += 10;
}

Link to comment
Share on other sites

I've never used phaser for a project before but I just had a play with the sandbox, doesnt look like you need the `collide` function calls, the overlap would do it

function update() {  game.physics.arcade.overlap( bullets, demon, function( bullet, demon ) {    demon.kill()    bullet.kill()  }, null, this )}

This assumes that bullets are a `physicsGroup` that you've used `bullets.create(...)` in your firing code.

 

edit actually collide or overlap doesnt matter, use whichever, but you only need the one collision code. At a push I'd say that collide gets called when they touch (or slightly overlap if moving very fast) and that overlap waits a tick later to make sure those sprites are overlapping. So use whichever granularity you like (there may be perf benefits to one over the other).

Link to comment
Share on other sites

Yeah, no change in the results either way, and i have the bullets group defined as such under the create function

 

 //Bullets
  bullets = game.add.group();
  bullets.enableBody = true;
  bullets.createMultiple(1, "bullet");
  bullets.setAll("checkWorldBounds", true);
  bullets.setAll("outOfBoundsKill", true);
 
  //Bullet physics
  game.physics.arcade.enable(bullets);

 

Its kind of odd to, i have a seperate function to kill the player whenever the demon touches him, and that works just fine, I've tried to copy the basic format of this function as well but with no result

Link to comment
Share on other sites

I was just playing with the sandbox barebones platformer template

 

Could be a version thing possibly as some of the syntax looks slightly different, which version of Phaser are you using?

 

Are you getting any errors in the console?

 

Other than that maybe try setting a few breakpoints and inspecting the variables, the only thing the sandbox template doesnt do that your code will is create objects on the fly, maybe there is a call to register new objects when you create them? Although, having said that, if that was the case then the bullets and demon would not collide. The `killDemon` function is definitely being called though?

Link to comment
Share on other sites

Yep the killDemon (should) be running, and i'm using verson 2.4.4, i did notice i am using the min version of it, will that end up making a huge difference? Other than that, no errors in the console and i ran it through js hint, and there are no semi colons or anything too obvious missing, i'll keep hacking at it see if i can find something

Link to comment
Share on other sites

Hey man I think I may have a change that could work for you

 

Instead of your code like this

 

function update() {

game.physics.arcade.overlap(bullets, demon, killDemon, null, this);

 

 //Enables bullets to hit demon
  game.physics.arcade.collide(demon, bullets);
  game.physics.arcade.collide(bullets, demon);

}

 

function killDemon (bullet, demon) {
  demon.kill();
  scoreText += 10;
}

 

Try this

 

function update() {

 

 

 //Enables bullets to hit demon
  game.physics.arcade.collide(demon, bullets, killDemon, this); // Also you dont need both of these collisons
  game.physics.arcade.collide(bullets, demon, killDemon, this);

}

 

function killDemon (bullet, demon) {
  demon.kill();
  scoreText += 10;
}

 

 

Personally though I would write it like this to make sure it works

 

function update() {

 

 //Enables bullets to hit demon
  this.game.physics.arcade.collide(this.demon,this. bullets, this.killDemon, null, this);

 

if (this.demon && this.bullets.collide) {

       this.killDemon;

}
 

}

 

function: killDemon() {
  demon.kill();
  scoreText += 10;
}

 

 

This is all from memory since I am at work but hopefully it works for you. Hope this was helpful.

Link to comment
Share on other sites

The .min version of Phaser will make no difference, the purpose of a minifier is just to ensure a smaller file size, for Phaser is certainly wont make a difference.

 

Also, linting doesnt check your code for anything too interesting so its not a sure-fire method of ensuring good code, its more to ensure consistency. Stuff like semi-colons dont matter (I dont use them, using them creates more error situations than not, but thats a different discussion).

 

The best thing you can do (besides asking for advice) is learn to open the dev tools, at least read the console and get logging stuff but also get used to inserting breakpoints and stepping through the code execution. With JS and dev tools (Chrome are the best, although the others are now also excellent) this is easy and one of the strengths of JS.

Link to comment
Share on other sites

Hey all! Sorry for the radio silence, i figured it out, the overlap and collission handlers didn't want to play nice so i merged them into one line (  game.physics.arcade.collide(demon, bullets, killDemon, null, this); ) and that worked perfectly! Next up im going to be trying to make a loop that will spawn a new enemy every time i kill the one, and (provided i can find a way) have every additional enemy spawned be faster, and maybe have a random scale as compared to the last one spawned

 

But, thanks to everyone who posted and helped me out! Your all awesome!

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...