DanielKlava

Members
  • Content count

    17
  • Joined

  • Last visited

About DanielKlava

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. DanielKlava

    Como usar a função moveToPointer() com corpo P2JS?

    Hello @Salomão Neto! If you are using P2 physics (or any other system other than P2), you have to explicitly activate it before using. The default Physics system is ARCADE, so that's why you didn't have to start it when you were using it. Please, try updating the line: game.physics.enable(this.player, Phaser.Physics.P2JS) // Error To: this.game.physics.startSystem(Phaser.Physics.P2JS); //You do it only once, and then use it at will. Not necessary with ARCADE physics. this.game.physics.p2.enable(this.player); Also, regarding the "moveToPointer()" function, it's not available in P2 Physics. You will have to calculate the mouse pointer location on screen, and the angle and positions relatives to your player object and move it accordingly. Take a look at this topic, where a function "moveBullets" was posted with a simple calculation: Let me know if it works for you!
  2. DanielKlava

    Attacking with a sword like older Zelda games

    Hi, @v33dub! You can use a Timer object to control the duration of the attack movement, and to control which animation to play: 1. Player presses the attack button which calls the "attack" function; 2. Set the animation to "attacking", and trigger the Phaser.Timer object to last 1 second or so (depends on how fast is the attack movement); 3. You set the "idle" animation again in the function that is called when the timer ends. The code would be something like this: attack(){ //We use a boolean var to check if the player is currently attacking to prevent a new attack mid animation. //(May not be necessary in your game.) if (!this.isAttacking){ //Play the "attack" animation this.animations.play('attack'); this.isAttacking = true; //Start the Timer object that will wait for 1 second and then will triger the inner function. this.game.time.events.add(Phaser.Timer.SECOND * 1, function(){ this.animations.play('idle');//Returns the animation to "idle" this.isAttacking = false;//Returns the boolean var to "false" }, this); } } Let me know if it works for you!
  3. DanielKlava

    Black Screen, No Console-Errors

    Hello @Jirash! Could post the link to which Hello World Example you are following? In Phaser 3.1 you should use a "config" JSON structure for initializing the Phaser.Game object, like so: var config = { type: Phaser.AUTO,//renderer type width: 215, height: 270, scene: { // here you set up which functions you are using for each step in the game loop init: init, preload: preload, create: create } }; //you finally instantiate the "game" object using the "config" one var game = new Phaser.Game(config); I've attached a example below with "Init", "Create" and "Preload" functions, to illustrate. Let me know if it helps you.
  4. DanielKlava

    [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;
  5. DanielKlava

    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
  6. Not exactly with Tern, but @speedo did a tutorial for Vim:
  7. DanielKlava

    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!
  8. 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.
  9. 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
  10. 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; }
  11. DanielKlava

    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.
  12. DanielKlava

    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.)
  13. 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.
  14. DanielKlava

    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!
  15. DanielKlava

    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?