• Content count

  • Joined

  • Last visited

  1. [HELP] My bullet no follow the good direction

    Hello! You need to set the "fireAngle" of the weapon object. For example: this.weapon.fireAngle = Phaser.ANGLE_RIGHT;
  2. phaser dynamically added sprite collsion not working

    Hello there! I think that you should use "this.collisionHandler" instead of "self.collisionHandler". Generally, the object "self" will point to window.self, and "this" will point to the context the function is in. Since you want to use the function "collisionHandler" in the context of the Game (or State) object, you should reference the function with "this". Hope it works
  3. Not exactly with Tern, but @speedo did a tutorial for Vim:
  4. button mute sound problem

    Hello espace! I think the issue is in the following line: this.button=game.add.button(this.posx,this.posy,this.image,this.anim_on_click,this,1); The sixth parameter defines which frame the button will be when you move the cursor over it. Since you are passing "1", Phaser will set the button's frame to 1 in a mouse over event. As of now, the result logic is: Player moves the cursor over the button; Button's frame is "1", as specified; Player clicks the button; Function "anim_on_click" is called, and since the frame was set to "1", it will always enter in the first condition. One simple solution would be to remove the last argument in your function call, I guess. Also, one other way to do it is to, inside your "anim_on_click" function, try to control the state of the button with a boolean variable instead of checking it's frame number, but that's just a suggestion. Hope it works!
  5. Hello! I think there are no right answers for these topics, but let me add my two cents: You could do that, of course, but you could also add a loop event that will run your custom logic that may call fireAtSprite(). The advantage would be that you may also call other functions, like animations and sound effects. Sure, you could also call that in your overridden function, but I think it would mix different concepts in your "fire()" function. I would go with option 2)! Although it will have the same effects as 3), you would have more control over the behavior of the collisions. For example, let's say that for some reason you don't want to collide the player with the enemy 1's bullets, but with 2's and 3's only, you could add logic inside the foreach loop to skip it. And, inside the collision callback function, you can call your bullet collision method that you declared in your extended bullet update. Like that you let the Game handle all collisions, but collision logic/action will be inside each class. It's really a gray area of which is the best way to go, I think.
  6. Great, glad it worked! I know the issue is done, but just one comment, if that's ok! I guess that you don't have to set up the "...onDown.add(..)" inside the event, since you already did it in "create" function. Since it's the function "add" instead of "addOnce" (as @rich mentioned), you wouldn't have to worry to set it up again after the first time (which would be the case if you are using addOnce). Just pointing it out because it could lead to some unpredictable behavior further down the road
  7. Hello! Just one question: on "create" you are setting the event for space bar only, but inside "tapStop", when the event is finished, you are setting the "tapStop" to any kind of input? Also I ran with some issues as well regarding timer after some action, and what worked for me was to define a separate Timer, and then clear all events with the timer.stop(), like so: create (){ //... this.doingAction = false; this.customTimer = this.game.time.create(false); this.jumpButton = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); this.jumpButton.onDown.add(this.action, this); //... } action(){ if (!this.doingAction){ this.doingAction = true; this.customTimer.stop(true); // clear all events this.waitingTimer = this.customTimer.add(Phaser.Timer.SECOND * 0.5, this.attack, this); this.customTimer.start(); // start timer again } } attack(){ // do stuff // ... this.doingAction = false; }
  8. Animation working when he want

    Hello! Can you check the contents of "_this.car" using "console.log(_this.car)", and see if it's a valid object? And, could you also post the code part where you initialize the "_this" variable? There may be some issue where it doesn't correctly point to the "this" object, so your code may not find the "car" object with the animations set up.
  9. left and right Jumping Problem in Phaser

    Hello! Can you confirm if the problem is so that your code never reaches inside the IFs with "jump" and "left/right" pressed? It could be a case of anti-ghosting with your keyboard. Does the behavior still occurs in another machine? I've attached a link of a similar scenario that you mentioned (there doesn't seem to be anything wrong with the code). And, regardless, would it be acceptable for the player to change the jump direction midair? If so, you could change your logic to check those buttons separately, and work around the issue. Oh, one more thing: if you are creating the "cursors" object, it already watches for both LEFT and RIGHT keys, so there would be no need to create the "left" and "right" variables, and just use them like so: if (cursors.left.isDown) { // do stuff } else if (cursors.right.isDown) { // do other stuff } (Also, are you defining the "jumpButton", "left" and "right" variables outside the functions? I noticed you are not using "this." for them.)
  10. Hello! You can try setting the scale as below: sprite.scale.x = 1.5; // Increases the X scale by 1.5x times. sprite.scale.y = 2; // Increases the X scale by 2x times. A similar use of this example is to "invert/mirror" the sprite, you just have to set the scale to -1.
  11. Stop sprite(velocity.x = 0) after some coordinate

    Hello! Perhaps you could insert a blank sprite where you want the sprite to stop, and check the collision between only the sprites you want. Then, in the collision callback you set the velocity to 0. Something like this. Assuming that your sprite is moving horizontally from left to right, and that he must stop regardless of it's Y position: create : function (){ //adds sprite at the position needed this.checkpoint = this.add.sprite(100, 2); //scale the height of the sprite to full height, so the user cannot miss it. this.checkpoint.scale.y = this.game.height; }, update : function (){ if (this.checkpoint != null && this.checkOverlap(this.player, this.checkpoint)) { //perform full stop this.player.body.velocity.y = 0; this.player.body.velocity.x = 0; //set the sprite to null so the collision callback occurs only once. this.checkpoint = null } }, //use a simple function to check the overlap so you won't have to initialize Physics in the collision sprite and save some processing checkOverlap : function (spriteA, spriteB) { var boundsA = spriteA.getBounds(); var boundsB = spriteB.getBounds(); return Phaser.Rectangle.intersects(boundsA, boundsB); } I am using a similar logic to trigger various events, I think it should work!
  12. Canvas size did not change after setUserScale

    Hi @davestephans, Just a quick question, what is the exact resolutions you are testing on? It's working on resolutions lower than the max one you specified, right? Because, going over this "if": if((GAME_MAX_WIDTH/windowWidth) > (GAME_MAX_HEIGHT/windowHeight)) { scaleFactor = (windowWidth / GAME_MAX_WIDTH); } else { scaleFactor = (windowHeight / GAME_MAX_HEIGHT); } If you are testing on resolution 1920x1080, then the "scaleFactor" will always be set to 1, and therefore you would be calling: mainGame.scale.setUserScale(1, 1); Which wouldn't actually resize the screen. Would that be the case?
  13. Sprite jitters if camera moves with it

    Hi guys, I've had help on this issue, and it's corrected now. Basically, what needed to be done was: this.game.renderer.renderSession.roundPixels = false; this.game.camera.roundPx = false; And, in the Phaser.Game constructor: antialias: false Thanks!
  14. Sprite jitters if camera moves with it

    Hello! I'm developing a simple 2D platformer with low res pixel art (canvas of size 144x81 pixels), and I noticed that when I move the sprite horizontally but enough to make the camera follow it, there's some jittering ocurring with the sprite. Here's the link (just pass the "main screen" clicking on START): https://danielklava.github.io/1-minute-left/ Could a kind soul give some assistance? I pay with internets. Thanks a lot!