deleteme Posted November 29, 2015 Share Posted November 29, 2015 So i managed to get my player to shoot, but every time i shoot my enemy the bullets just kind of bounce off him, and neither the kill or destroy functions are working for me. Any ideas on what i can do? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted December 1, 2015 Share Posted December 1, 2015 Ok, that isnt nearly enough information. Are those custom functions or you're using a library? Post some code snippets on your `kill`, `destroy` and collision code, or the parts that use those functions if you're using a library. Quote Link to comment Share on other sites More sharing options...
deleteme Posted December 1, 2015 Author Share Posted December 1, 2015 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;} Quote Link to comment Share on other sites More sharing options...
mattstyles Posted December 1, 2015 Share Posted December 1, 2015 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 itfunction 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). Quote Link to comment Share on other sites More sharing options...
deleteme Posted December 2, 2015 Author Share Posted December 2, 2015 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 Quote Link to comment Share on other sites More sharing options...
mattstyles Posted December 2, 2015 Share Posted December 2, 2015 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? Quote Link to comment Share on other sites More sharing options...
deleteme Posted December 2, 2015 Author Share Posted December 2, 2015 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 Quote Link to comment Share on other sites More sharing options...
Get_Bentley Posted December 5, 2015 Share Posted December 5, 2015 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. Quote Link to comment Share on other sites More sharing options...
mattstyles Posted December 5, 2015 Share Posted December 5, 2015 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. Quote Link to comment Share on other sites More sharing options...
deleteme Posted December 6, 2015 Author Share Posted December 6, 2015 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! Quote Link to comment Share on other sites More sharing options...
deleteme Posted December 9, 2015 Author Share Posted December 9, 2015 Hey another quick question, is there some kind of state i can call on when an enemy is killed that i could im plement later? For example, when the enemy is killed, is there something along the lines of an "enemy.dead" state i can use? 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.