divers

Members
  • Content Count

    26
  • Joined

  • Last visited


Reputation Activity

  1. Like
    divers got a reaction from GreenCloversGuy in Tweens timeline problem   
    So I figured it on my own, here's what I did to detect current tween:
    if (this.movement && this.movement.isPlaying()) { const progress = this.movement.elapsed; const currentTweenIndex = this.movement.data.findIndex(tween => { return (tween.calculatedOffset + tween.duration) > progress; }); const currentTween = this.movement.data[currentTweenIndex]; if (currentTween) { currentTween.setCallback('onComplete', () => { this.movement.destroy(); this.findPath(toX, toY); }, []); } } where this.movement is current timeline.
     
    Have a good day!
  2. Like
    divers got a reaction from Capitaine Herlock in Phaser + es6   
    Hello I am trying to write a game in phaser + es6 javascript.
    So far I have a game state in which I am making player.
    But in game state I have buttons to control my character. So is this correct?
    // gameState.js create() {           this.game.physics.startSystem(Phaser.Physics.P2JS); //activate physics         this.game.physics.p2.gravity.y = 1200; //realistic gravity         this.game.world.setBounds(0, 0, this.game.world.width, this.game.world.height);//(x, y, width, height)         this.game.physics.p2.setBoundsToWorld(true, true, false, true, false); //(left, right, top, bottom, setCollisionGroup)         this.game.physics.p2.friction = 5; // default friction between ground and player or fireballs           // setup our player         let player = new Player(this.game, this.game.world.width/2, this.game.world.height - 150, 'player');           // create our virtual game controller buttons         let buttonjump = this.game.add.button(400, 300, 'buttonjump', null, this, 0, 1, 0, 1); //game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame, upFrame         buttonjump.fixedToCamera = true; //our buttons should stay on the same place         buttonjump.events.onInputDown.add(function(){ player.skill_1=true; });         buttonjump.events.onInputUp.add(function(){ player.skill_1=false; });           let buttonfire = this.game.add.button(500, 300, 'buttonfire', null, this, 0, 1, 0, 1);         buttonfire.fixedToCamera = true;         buttonfire.events.onInputDown.add(function(){ player.fire=true; });         buttonfire.events.onInputUp.add(function(){ player.fire=false; });           let buttonleft = this.game.add.button(0, 300, 'buttonhorizontal', null, this, 0, 1, 0, 1);         buttonleft.fixedToCamera = true;         buttonleft.events.onInputDown.add(function(){ player.moveLeft=true; });         buttonleft.events.onInputUp.add(function(){ player.moveLeft=false; });           let buttonright = this.game.add.button(160, 300, 'buttonhorizontal', null, this, 0, 1, 0, 1);         buttonright.fixedToCamera = true;         buttonright.events.onInputDown.add(function(){ player.moveRight=true; });         buttonright.events.onInputUp.add(function(){ player.moveRight=false; });   }     //Player constructor     constructor(game, x, y, key) {   super(game, x, y, key);           this.game.physics.p2.enable(this);         this.body.setCircle(22); // collision circle         this.body.fixedRotation=true; // do not rotate on collision         this.body.mass = 4;           // add some animations         this.animations.add('idle', [0,1,2,3,4,3,2,1,0] , 10, true); // (key, framesarray, fps,repeat)         this.animations.add('walk', [11,12,13,14,15,16,17,18], 15, true); // (key, framesarray, fps,repeat)         this.anim = this.animations.add('skill_1', [5,6,7,8,9,10], 15, false); // (key, framesarray, fps,repeat)         this.anim.onComplete.add(this.shake, this);           this.game.stage.addChild(this);   this.skill = false; this.skill_1 = false; this.moveLeft = false; this.moveRight = false;   }
  3. Like
    divers reacted to samid737 in Tinting images   
    The color space that you use and coordinate system used in your interpolation function affects your interpolation result. There is not one unique way to linearly interpolate to your desired color, but there are many options (this answer show what's happening and this one to compare interpolation results). So when you want to go from red to blue, which path do you want to take? This might be the reason why the color interpolation does not look right. (try going from red to green in RGB vs in HSV). Some suggestions/ideas:
    -Maybe you can try to use a different color space to get better results. Here is an example of interpolating colors in HSV instead of RGB (the source code from here):
     
    -Try changing your colors in intermediate steps, so RED--->GREEN becomes RED---> YELLOW---> GREEN.
    -Try shifting the hue of your sprites using a custom shader (needs WEBGL). Example:
    This will require a custom function that multiplies the cosine and sine in the shader by some fixed increment(angle) everytime you reach some new score. This might also not be the ideal solution for you, but maybe you can hack something out of it (its what I do most of the time).
  4. Like
    divers reacted to Befive.Info in Object next to each other   
    Sorry if I understood incorrectly.  excerpt code from my game:
    can it     be a hint?
  5. Like
    divers reacted to samid737 in Object next to each other   
    EDIT:
    I misread the topic, I thought @Befive.Info was asking the question and replied to add his source code... Il just leave it in case someone ever needs it. 

    NEW ANSWER:

    Here is another way to do it using A nested for loop (might not be as efficient, though, but it works):
    boxGroup=game.add.group(); for(var i=0;i<13;i++){ for(var s=0;s<13;s++){ var object=makeBoxes(150,150,s,i); } } } function makeBoxes(x,y,s,i){ this.sprite=game.add.sprite(x+s*40,y+i*40,'boxes'); boxGroup.add(this.sprite); return this.sprite; } Applied to an example:
     


    OLD ANSWER(ALREADY ANSWERED BY @Befive.Info):
    You can make a custom sized grid by generalizing block building to a procedure with input arguments. Here is an example of what you could do:
     
    It is just A procedural approach to your box building. So you just do the exact same procedure for your other blocks, but you change the row size and keep a count of the row index. You could build the boxes as seperate groups (you have one parentgroup currently) via the procedure, so that you can customize the position of the group to your will.
    You could also just simply add an if statement that checks the element in the _keyNames:
    if(isAnumber(_keyNames[key])){ _each_row_has=4; }else{ _each_row_has=8; } function isAnumber(n){ //some function that checks if it is a number } But the indexing will fail in this case (positions relative to letters won't look nice).