onlycape

Members
  • Content Count

    82
  • Joined

  • Last visited

About onlycape

  • Rank
    Advanced Member

Recent Profile Visitors

728 profile views
  1. onlycape

    Trigger an action on overlapping just one time

    Hi @Pau, Now it works, but is very strange for me . I don't know why, but with your code, the params of "entra1" and "entra2" are in other order (the car is the second parameter, not the first, thats the reason of the errors).The "if" of entraArea2 is the location to execute the crossing action. Here the tested code in https://labs.phaser.io/edit.html?src=src\physics\arcade\overlap zone.js : var config = { type: Phaser.AUTO, width: 800, height: 600, parent: 'phaser-example', physics: { default: 'arcade', arcade: { debug: true, gravity: { y: 200 } } }, scene: { preload: preload, create: create, update: update } }; var metaIn; var metaOut; var coches; new Phaser.Game(config); function preload () { this.load.image('space', 'assets/skies/space.jpg'); this.load.image('block', 'assets/sprites/bikkuriman.png'); } function create () { this.add.image(400, 300, 'space'); /* metaIn enable sprite to cross metaOut ("triggered" property is set to false)*/ metaIn = this.add.zone(300, 50).setSize(5, 500); metaOut = this.add.zone(370, 50).setSize(5, 500); this.physics.world.enable(metaIn); this.physics.world.enable(metaOut); metaIn.body.setAllowGravity(false); metaIn.body.moves = false; metaOut.body.setAllowGravity(false); metaOut.body.moves = false; /* GRUPO DE COCHES (2) */ var coches = this.physics.add.group(this); player1 = coches.create(50, 150,'block'); player2 = coches.create(50,300,'block'); Phaser.Actions.Call(coches.getChildren(), function(coche) { coche.body.setVelocity(100,0); coche.body.setAllowGravity(false); coche.parametros = {}; coche.love= 2; coche.entraEnArea1 = function (){ this.triggered=true; } coche.entraEnArea2 = function (){ if(this.triggered){ //// Aquí pones la acción que quieres ejecutar al cruzar la meta //// console.log('el coche con love '+ this.love + ' cruza por meta'); } this.triggered = false; } }); this.physics.add.overlap(coches, metaIn, entra1.bind(this)); this.physics.add.overlap(coches, metaOut, entra2.bind(this)); } function entra1(objectmetaIn,coche){ //console.log(objectmetaIn.love); coche.entraEnArea1(); } function entra2(objectmetaOut,coche){ //console.log(objectmetaOut); coche.entraEnArea2(); } function update () { metaIn.body.debugBodyColor = metaIn.body.touching.none ? 0x00ffff : 0xffff00; metaOut.body.debugBodyColor = metaOut.body.touching.none ? 0x00ffff : 0xffff00; } Good luck!!
  2. onlycape

    Trigger an action on overlapping just one time

    Hi again @Pau, I think you can use something like this (I'm sure you can improve this code 😁 , I usually use Phaser CE) : var config = { type: Phaser.AUTO, width: 800, height: 600, parent: 'phaser-example', physics: { default: 'arcade', arcade: { debug: true, gravity: { y: 200 } } }, scene: { preload: preload, create: create, update: update } }; var zone1; var zone2; var group; new Phaser.Game(config); function preload () { this.load.image('space', 'assets/skies/space.jpg'); this.load.image('block', 'assets/sprites/bikkuriman.png'); } function create () { this.add.image(400, 300, 'space'); /* Creating group with 2 elements */ var group = this.add.group(this); /******************** Adding two cars to the group*/ /**************************** CAR1 */ var car = group.create(50,150,'block'); this.physics.world.enable(car); car.body.setVelocity(50,0); car.body.setAllowGravity(false); /* Custom properties for CAR1 */ car.name = 'car1'; car.triggered = false; car.overlapIn = function (){ this.triggered=true; } car.overlapOut = function (){ if(this.triggered){ console.log(this.name +' crossing goal'); } this.triggered=false; } /******************* CAR2 */ car = group.create(50,300,'block'); this.physics.world.enable(car); car.body.setVelocity(100,0); car.body.setAllowGravity(false); /* Custom properties for CAR2 */ car.name = 'car2'; car.triggered = false; car.overlapIn = function (){ this.triggered=true; } car.overlapOut = function (){ if(this.triggered){ console.log(this.name +' crossing goal'); } this.triggered=false; } /* zone1 enable sprite to cross zone2 ("triggered" property is set to false)*/ zone1 = this.add.zone(300, 50).setSize(5, 500); zone2 = this.add.zone(370, 50).setSize(5, 500); this.physics.world.enable(zone1); this.physics.world.enable(zone2); zone1.body.setAllowGravity(false); zone1.body.moves = false; zone2.body.setAllowGravity(false); zone2.body.moves = false; this.physics.add.overlap(group, zone1, overlapAction1.bind(this)); this.physics.add.overlap(group, zone2, overlapAction2.bind(this)); } function overlapAction1(objectCar,objectZone1){ objectCar.overlapIn(); } function overlapAction2(objectCar,objectZone2){ objectCar.overlapOut(); } function update () { zone1.body.debugBodyColor = zone1.body.touching.none ? 0x00ffff : 0xffff00; zone2.body.debugBodyColor = zone2.body.touching.none ? 0x00ffff : 0xffff00; } The two cars in the group have 2 custom properties ("name" and "triggered") and two custom methods ("overlapIn" and "overlapOut"). The goal line have 2 zones: When car overlaps zone1 "triggered is set to true (this enable the zone2 where is executed the goal action), and when car overlaps zone2 "triggered" is set to false after execute an action, in this case print in console the car name and "crossing goal". The code can be tested editing the code in this example: https://labs.phaser.io/edit.html?src=src\physics\arcade\overlap zone.js . If you want to avoid cheats then you need place some check points in the track. Regards.
  3. onlycape

    Trigger an action on overlapping just one time

    Hi Pau, This is a way to do that (tested on phaser 3 sandbox): var overlapCollider; var overlapTriggered = false; /* ...... */ function create(){ /* ..... */ overlapCollider = this.physics.add.overlap(players, overlappingArea, goal.bind(this)); }; function goal(){ if(overlapTriggered){ this.physics.world.removeCollider(overlapCollider); return; }; console.log('overlap'); overlapTriggered=true; }; Without using the variable overlapTriggered, goal() would be executed 2 times. Regards.
  4. Hi @espace, I think that directly is not possible. But you can make your own wrapper function for "game.add.tween". Here a simple wrapper ( http://phaser.io/sandbox/BFoPWrWT ) : // Function to wrap game.add.tween function tweenWrapper(obj){ game.add.tween(obj.target).to(obj.properties,obj.duration,obj.ease,obj.autoStart,obj.delay,obj.repeat,obj.yoyo); } function create() { var sprite = game.add.sprite(0, 0, 'phaser'); var config={ target: sprite, properties : { y:150, x:100, }, duration : 1000, ease : Phaser.Linear, autoStart : true, delay:10, repeat : 0, yoyo:false }; tweenWrapper(config); } Regards.
  5. onlycape

    best way to measure time with collision

    Hi @espace, When the object collide "in the air" : var timeStamp1 = performance.now() When the object collides with ground : var timeStamp2 = performance.now() The time the object take to fall to the ground in miliseconds is ----> parseInt ( timeStamp2 - timeStamp1 ) Regards.
  6. @BdR , No. If you load sound assets in a state with the option "autodecode" (example: this.game.load.audio('blaster', 'audio/SoundEffects/blaster.mp3', true)), then the decoded sounds will be stored in cache and available for other states. You can use a state to load the common assets only one time (like in the typical loading screen with progress bar). Regards.
  7. Hi @BdR, That DOMException is resolved with this (mygame.MyGameState was undefined): mygame.MyGameState = function(game){}; mygame.MyGameState.prototype = { preload: function() { ............... more code ............... Phase Sandbox can use the StateManager. Here a simple example: http://phaser.io/sandbox/UUWjHaIA Each state must contain at least a one of the required functions: preload, create, update or render (check your "mygame.MyState ") To change the game size use the size selector in the "Play" tab. Declaring a new Phaser.game adds other canvas, and seems game.destroy() can't be used. Regards.
  8. onlycape

    Gaps between scrolling background objects

    Hi @Phaser911, Instead of using 2 sprites for the background, you could use a single tilesprite and its autoscroll method ( https://photonstorm.github.io/phaser-ce/Phaser.TileSprite.html#autoScroll ). // in create function bgSpeed = 6; background = game.add.tileSprite(0,0,screenWidth,screenHeight,'imageKey'); background.autoScroll(bgSpeed,0); // bgSpeed in pixels per second // in buttonClick() function buttonClick() { bgSpeed = 9; background.autoScroll(bgSpeed,0); } Regards.
  9. onlycape

    problem with a callback

    Hi again @espace, The onComplete property of the Tween class is an object of the Signal class, which in this case calls its add method. This is the documentation of "Signal.add" method: https://photonstorm.github.io/phaser-ce/Phaser.Signal.html#add I am using Phaser CE, but in this case it does not change with respect to your version. Yes, is an optional argument. This code still works changing "this" with "null". Regards.
  10. onlycape

    problem with a callback

    Hi @espace, I think you probably have not passed the argument to the callback. Look at this code made in Phaser Sandbox (try the code here: http://phaser.io/sandbox/obVXEuZb/play ) : function create() { var sprite = game.add.sprite(0, 0, 'phaser'); var appears = function (obj,callback){ var tw = game.add.tween(obj).to( { x: 100 }, 2000, "Linear", true); // Here is the trick: add(callback, context, priority, args) tw.onComplete.add(callback,this,null,obj); }; var anim_obj = function(obj){ game.add.tween(obj).to( { y: 100 }, 2000, "Linear", true); }; appears(sprite,anim_obj); } Regards.
  11. onlycape

    Developing a game for desktop and mobile browsers

    Hi @johann_dev, In first place, If you are using the renderer Phaser.WEBGL or AUTO then try changing it to Phaser.CANVAS. Some browsers have support for webgl but with very poor performance (especially on mobile). If you are using multiple text objects with webgl. Instead of system fonts it's much better for performance to use bitmap fonts (bitmapText object). Regards.
  12. onlycape

    [Phaser] Color Hit

    Hi @zelcard, Nice game. I liked the game mechanics and the excellent visual effects. There are 3 points that I think could improve the game: Because the time of the game is limited, replay value is low. Some type of endless mode could improve this aspect. Some type of help / tutorial to know what to do at least in the first game. The music of the game could be coordinated with the different states of the game (for example, lower the volume at the beginning of the game, change to another music, ...). Here my best result 😁 : Regards.
  13. onlycape

    AudioContext Error

    Hi @MackeyK24 , The latest Chrome update causes this problem. Now you need the first sound to be caused by the user (click, touch ...), only then you can play sounds without user intervention. In my case, I added a sound (with 0 volume) on the play button. And here other solution: http://www.html5gamedevs.com/topic/37384-no-sound-or-music-on-chrome-desktop-windows-10/ Regards.
  14. onlycape

    how to call a function as argument ?

    Hi @espace, There is a scope problem. You don't need to put the argument inside an anonymous function. The argument is already a function. This code works: var wait = function(callback,duration){ setTimeout(callback, duration); }; var f = function(){ console.log('executed'); }; wait(f,500); Regards.
  15. onlycape

    Why use "this " keyword in Phaser states

    In this link they explain in detail the use of the "this" keyword in javascript: https://codeburst.io/javascript-the-keyword-this-for-beginners-fb5238d99f85 In my humble opinion (I'm a newbie in javascript and Phaser), your question is more related to javascript than to Phaser framework. Using more time in javascript learning at the end will save you a lot of time when developing in Phaser, and will provide you with other resources that in some cases the framework will not be able to offer. Regards.