Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


Reputation Activity

  1. Like
    espace got a reaction from Hamza Wasim in Box Tower - An Addictive Game   
    Cool concept but the graphics could be better, more attractive...
    The speed could be also faster.
    Have a good day.
  2. Like
    espace reacted to b10b in how to make a perpetual movement with random   
    @espace use onLoop instead of onComplete
    You won't need to reset the x, because the tween state will do that.
    Math.random(0,800) is incorrect, use Math.random() * 800 instead.
    Use a regular function (not an arrow) for the signal listener, and use sprite as the context (instead of this).  Sorry, couldn't figure out why this scenario didn't fit as expected with arrows?
    function create() { var sprite=[] var tw=[]; for (var i = 0; i < 5; i++) { sprite[i]=game.add.sprite(400+i*10, i*100, 'phaser'); } var move=()=>{ for (var i = 0; i < 5; i++) { tw[i]=game.add.tween(sprite[i]).to({x:-400},1000,Phaser.Easing.Linear.none,true,i*200,-1); tw[i].onLoop.add(function(){ this.y = Math.random() * 800; },sprite[i]) } } move(); }  
  3. Like
    espace reacted to Milton in cordova android ubuntu fail to install need really help   
    defaultBuildToolsVersion="27.0.1" //String
    Installed packages:=====================] 100% Computing updates...
    Path | Version | Description | Location ------- | ------- | ------- | -------
    build-tools;19.1.0 | 19.1.0 | Android SDK Build-Tools 19.1 | build-tools/19.1.0/
    build-tools;20.0.0 | 20.0.0 | Android SDK Build-Tools 20 | build-tools/20.0.0/
    build-tools;26.0.2 | 26.0.2 | Android SDK Build-Tools 26.0.2 | build-tools/26.0.2/
    build-tools;28.0.3 | 28.0.3 | Android SDK Build-Tools 28.0.3 | build-tools/28.0.3/
    See the problem  ?
  4. Thanks
    espace reacted to Yehuda Katz in is group better ?   
    Espace, you cannot see the difference if you use a group from CPU point of view. However the difference exist simply because lets say your both sprites are in game.world, if you use wrapper group it means they are inside game.world.warp_group so it means when Phaser will need to calculate where to draw sprites, it should first get local bounds of group and apply them sprite's x/y. Those calculation are so simple that I would prefer use group which makes code simpler and easier to understand. Therefor there is a less chance to make more important, logical mistake in future when games gets bigger 😃
  5. Thanks
    espace reacted to mattstyles in listener in javascript   
    You're doing this very naively, so you'd need the flag.
    The alternative is to implement an actual event pub/sub system (ala addEventListener, or, any pub/sub implementation out there) on your object i.e.
    import EventEmitter from 'eventemitter3' export const onChange = 'sprite:onChange' export class Sprite extends EventEmitter { scale = { x: 1, y: 1 } setScale (x, y) { this.scale = { x, y } this.emit(onChange, { type: 'scale', payload: this.scale }) } } import { Sprite, onChange } from 'sprite' function doSomething () { console.log('doing something arguments:', ...arguments) } const sprite = new Sprite() sprite.once(onChange, doSomething) Note I'm using ES6 syntax (inc. module syntax) and I haven't tested any of this (I rarely use classes so might have mixed up context or some other stupid error) but hopefully it's easy enough to follow.
    eventEmitter3 is a really simple pub/sub module and is a really standard implementation. `on` and `off` functions are analogous to DOM `addEventListener` and `removeEventListener`, the `once` method used here is just sugar around removing the handler/callback after the first time it is triggered.
    This actually functionally gets you to the same place you're already at, albeit without some implicit state hanging around. Depending on your exact use-case this might be more or less useful to you.
    What this is doing:
    * Attach a function to list of functions, key it against a string identifier (this is the event)
    * On another function call (emit) check the list of functions for the string which was emitted
    * Fire the function when the string is matched
    * Remove the function from the list of functions to check i.e. the next time that string is used it won't match that function again
    What you are doing:
    * Inspecting an object for changes by polling
    * Reacting to any detected changes by invoking a function
    * Deciding a course of action from within the function
    In different scenarios both of these approaches have merit so it's up to you which you prefer. Probably the 'most popular' way of solving this sort of problem is with pub/sub.
  6. Thanks
    espace reacted to b10b in prompt how to loop to be sure to have the correct value ?   
    window.prompt() is convenient but may create some weird traps.  My tip would be to separate the UI from the logic.  Take a few steps back and define what the data validation function looks like, implement that first.  Then call the prompt (whether window.prompt or an alternative UI) "while" the validation function returns a falsy.  Then it'll neatly repeat until a valid name is supplied.  No recursion should be needed - ideally each function should do a single thing, and return as soon as that thing is done.
  7. Thanks
    espace reacted to gafami in best way to convert ES6 syntax to ES5 ?   
    I believe that you should convert whole your ES6 scripts to ES5 right now. It's not just  for export to cocoon, to make sure your game works well on Safari iOS (8, 9), iOS HomeScreen Web App you need to build based on ES5 syntax (almost browser supported).  No worries if you have spent hard-work for ES6. Just go to this page: https://babeljs.io/repl
    Tick ES2015 and paste your ES6 script into the left side box, they will help you convert it to ES5. My game https://www.iomgame.com/wariom/ also facing the problem like you. Hope it can help you.
    I attach an example file from my game you can try it again on babeljs with these options: linewrap + es2015 + stage-2 
    Don't rewrite the script because it's wasting time. Your logic code and animation way you choose  will decide performance on mobile games not ES6 or ES5.
  8. Like
    espace reacted to onlycape in Is it possible to use tween with an object parameter to be more readable ?   
    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.
  9. Like
    espace reacted to khleug35 in how to do this effect ?   
    I just add this scale code, but I not sure that  is it the best way to do it.........sorry
  10. Like
    espace got a reaction from khleug35 in how to do this effect ?   
    waouw thanks
    i don't really understand for time how you do but i will read the docs.
  11. Like
    espace reacted to khleug35 in how to do this effect ?   
    like this???
    function create() { game.stage.backgroundColor = '#000'; arrow = game.add.image(90, 36, 'arrow'); widtharrow = new Phaser.Rectangle(0, 0,arrow.width, arrow.height); arrow.cropEnabled = true; arrow.crop(widtharrow); arrow.fixedToCamera = true; widtharrow.width = 0; game.time.events.loop(800, function() { game.add.tween(widtharrow).to( { width: (widtharrow.width + 60) }, 200, Phaser.Easing.Linear.None, true); }, this); } function update() { arrow.updateCrop(); //loop animations if(widtharrow.width >= 300){ game.add.tween(widtharrow).to( { width: (widtharrow.width - arrow.width) }, 200, Phaser.Easing.Linear.None, true); } } I use crop method to do it .
  12. Like
    espace reacted to losthope in how to increment this function ?   
    a loop in a loop maybe? i have no idea what your code tries to achieve, nor am i a professional programmer. here is pseudo code that roughly shows how i would try to automate it
    for(let j = 0; j < o.opponent_actions.length; ++j) { let summed_actions = 0; for(let i = 0; i < j; ++i) summed_actions += o.opponent_actions[i]; wait(() => { o.paper[0].body.moves = false; }, summed_actions); wait(() => { o.paper[0].body.moves = true; }, 100 + j*100 + summed_actions); } or maybe for(let j = 0; j < o.opponent_actions.length*2; ++j) { let summed_actions = 0; for(let i = 0; i < j/2; ++i) summed_actions += o.opponent_actions[i]; if(j % 2 == 1) summed_actions += 50 + j*50; wait(() => { o.paper[0].body.moves = j % 2 == 1; }, summed_actions); }  
  13. Like
    espace reacted to onlycape in 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 )
  14. Like
    espace reacted to losthope in why this snippet don't work ?problem with parameter   
    flag is passed by value, flag = true is useless
    pass obj and check/assign to obj.flag
  15. Like
    espace got a reaction from TheBoneJarmer in Tap Tap Plane   
    It's just an flappy bird copy !
  16. Like
    espace got a reaction from bluecake in Effect of a torch on fire ?   
    you have this example but it's phaser 3...:
    and also this for the halo effect :
  17. Haha
    espace reacted to onlycape in 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.
  18. Like
    espace reacted to mattstyles in how to call a function as argument ?   
    Nah, its not even a scope problem, whatever `myFunction` is in the original post, it wasn't a function.
    However, I do agree that you don't need to wrap the callback function again, but, you don't even need the `wait` function as it has just become a marginally slower alias. I'm assuming this is all simplified for the purposes of illustration though and that you're actually planning to do more with your wait function (like make it a little easier to cancel it, or extend it, or whatever).
    Functions in JS can be passed around as first-class citizens, which is an extremely useful language feature.
    function add (a, b) { return a + b } You can think of the `add` variable as a pointer to a block of code (rather than a pointer to a memory allocation), using newer syntax makes this even more obvious:
    const add = (a, b) => a + b Where you actually assign the anonymous (lambda) function to the constant variable (ha ha, that proper sounds odd!) `add`.
    Note: there are subtle differences between the two code snippets above, but you're extremely unlikely to need to worry about it, particularly for pure functions like the ones above.
    Either way you can pass the `add` function around, including using it as a parameter for other functions.
    Consider the following:
    const add = (a, b) => a + b const subtract = (a, b) => a - b const d2 = () => Math.random() < 0.5 const tweak2 = (a, b) => d2() ? add(a, b) : subtract(a, b) Calling the `tweak2` function has a 50/50 chance of either adding or subtracting those numbers, but, imagine we wanted to add other operations:
    const add = (a, b) => a + b const subtract = (a, b) => a - b const multiply = (a, b) => a * b const divide = (a, b) => a / b const d2 = () => Math.random() < 0.5 const tweak2addsubtract = (a, b) => d2() ? add(a, b) : subtract(a, b) const tweak2addmultiply = (a, b) => d2() ? add(a, b) : multiply(a, b) This is a pretty terse example but you can imagine how this is going to grow. Now imagine you end up changing some of the implementation, would be pretty error-prone. Imagine trying to test all combos, again, a little annoying.
    However, you could refactor this slightly and use another helper function:
    const add = (a, b) => a + b const subtract = (a, b) => a - b const multiply = (a, b) => a * b const divide = (a, b) => a / b const d2 = () => Math.random() < 0.5 const tweak2 = (fnA, fnB) => (a, b) => d2() ? fnA(a, b) : fnB(a, b) const addSubtract = tweak2(add, subtract) console.log(addSubtract(10, 2)) // 8 or 12 Now the tweak function can be 'pre-loaded' with functions it uses to operate, which we've passed through.
    If you're not comfortable with arrow functions then its a little confusing to follow as it uses closure and explicit return to work, but, have a look as this pattern can be generalised to be useful in a wide variety of situations.
    When you get really good you can do stuff like the following:
    const isNumber = _ => typeof _ === 'number' const add = (a, b) => a + b const total = compose( reduce(add, 0), filter(isNumber) ) total([1, 2, 'a', 3]) // 6 All functions used here a low-level pieces and trivial to test and re-compose.
    Unless you're comfortable with passing functions around it's probably a little tricky to see exactly what is going on (there are lots of good places to read up on it though) but you should be able to see that the `total` function can take an array, filter out only the numbers, and then add them all up.
  19. Like
    espace got a reaction from mattstyles in access a link works on web and not on mobile   
    solved :
    //install plugin :inappbrowser in cocoon.io // this.testlink=function(){ var link="https://www.google.com" game.time.events.add(4000,function(){cordova.InAppBrowser.open(link, '_blank', 'location=yes')}) }; is_mobile && this.testlink();  
  20. Thanks
    espace reacted to mkardas91 in while on array unexpected behavior   
    var e=[0,2,1,-1] console.log(e.indexOf(-1)); // 3 https://developer.mozilla.org/pl/docs/Web/JavaScript/Referencje/Obiekty/Array/indexOf
  21. Like
    espace reacted to samme in stop music when leave application on phone with the home button?   
    Probably you would use Phaser.Game#onBlur or Phaser.Game#onPause, if the browser isn't handling this already.
  22. Like
    espace got a reaction from speedo in is it someone who success to implement tern-phaser with vim ?   
    hi, speedo sorry for this time but i try different solutions.
    your soluce don't works all the time. In fact put tern globally plus vim_for_tern don't work together.
    by reading your comments (i would know how do you do for learn all you have posted ? :)) my  better solutions is this bash script :
    #!/bin/bash # echo "COPY PASTE THESE 2 INSTRUCTIONS ON ANOTHER TERMINAL" echo "curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \ " echo "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" read -p "push on a key to go on... " -n 1 -s cd mkdir ~/.config/nvim curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - sudo apt-get install -y nodejs sudo add-apt-repository -y ppa:neovim-ppa/stable && sudo apt-get update && sudo apt-get install neovim sudo apt-get install -y python-dev python-pip python3-dev python3-pip sudo -H pip3 install --upgrade neovim sudo -H pip2 install --upgrade neovim sudo npm install -g neovim cp ~/dotfiles/.tern-project ~/ cp ~/dotfiles/nvim/init.vim ~/.config/nvim/ mkdir ~/.config/nvim/colors cp ~/dotfiles/nvim/colors/onedark.vim ~/.config/nvim/colors cp ~/dotfiles/nvim/init.vim ~/.config/nvim/ nvim +PlugInstall cd && cd ~/.vim/plugged/tern_for_vim/ && sudo npm install tern cd && cd ~/.vim/plugged/tern_for_vim/node_modules/tern/plugin && wget "http://redchilligame.com/tutorials/vim_phaser/js/phaser.js" # sans tern server global ctrl x ctrl o fonctionne #cd && sudo npm install -g tern my init.vim:
    set encoding=utf8 set number set mouse=a set autoindent set clipboard=unnamedplus " recherche incrementielle set incsearch set cursorline " insensible à la casse dans les recherches set ignorecase " insensible à la casse dans les chemins set wildignorecase "" true color " relative number set relativenumber " vertical line to show position set cursorcolumn " COLORS set background=dark colorscheme onedark set termguicolors " PERSONAL COMMAND " open snippets for phaser in a vertical split command Pref vsplit ~/.vim/plugged/vim-snippets/snippets/javascript/javascript-phaser.snippets " CUSTOM KEYBINDING "NORMAL MODE nnoremap <C-Up> VDkPk <CR> nnoremap <C-Down> VDjPj <CR> nnoremap <C-a> ggVG <CR> nnoremap <C-=> G=gg <CR> map <F2> :TernDoc<CR> "INSERT MODE inoremap <C-Space> <C-x><C-o> " Plugins will be downloaded under the specified directory. call plug#begin('$HOME/.vim/plugged') if has('nvim') Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } else Plug 'Shougo/deoplete.nvim' Plug 'roxma/nvim-yarp' Plug 'roxma/vim-hug-neovim-rpc' endif " DECLARE THE LIST OF PLUGINS. Plug 'ternjs/tern_for_vim' Plug 'scrooloose/nerdtree' Plug 'Raimondi/delimitMate' Plug 'rhysd/github-complete.vim' Plug 'easymotion/vim-easymotion' Plug 'terryma/vim-multiple-cursors' Plug 'vim-syntastic/syntastic' Plug 'kien/ctrlp.vim' Plug 'pangloss/vim-javascript' Plug 'vim-scripts/indenthtml.vim' Plug 'walm/jshint.vim' Plug 'heavenshell/vim-jsdoc' Plug 'ervandew/supertab' Plug 'SirVer/ultisnips' Plug 'honza/vim-snippets' "Plug 'majutsushi/tagbar' " COLORS THEMES "Plug 'joshdick/onedark.vim' " List ends here. Plugins become visible to Vim after this call. call plug#end() " SUPERTAB "scroll from top to bottom let g:SuperTabDefaultCompletionType = "<c-n>" let g:python_host_prog = '/usr/bin/python2.7' let g:python3_host_prog = '/usr/bin/python3.5' "peut etre à supprimer noautocmd "" start deoplete at startup let g:deoplete#enable_at_startup = 1 set statusline+=%#warningmsg# set statusline+=%* "COMMANDES POUR SYNTASTIC "let g:syntastic_always_populate_loc_list = 1 "let g:syntastic_auto_loc_list = 1 "let g:syntastic_check_on_open = 1 "let g:syntastic_check_on_wq = 0 in fact i do ctrl x ctrl o (with ctrl +space => see my init.vim)  to have tern definition. Your previous solution don't work all the time it seems that tern server is broken....because it use tern_for_vim and at the same time tern...
  23. Thanks
    espace reacted to speedo in is it someone who success to implement tern-phaser with vim ?   
    for NEOVIM auto-completion for phaser::
    neocomplete doesn't work in neovim  so, switch to deoplete.nvim (its awesome).
    to use auto-completion with-out the "ctrl x + ctrl o" see following steps::
    1] deoplete.nvim (note  it requires python3 :checkhealth)
    For vim-plug ::
    --> init.vim::
    if has('nvim') Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } else Plug 'Shougo/deoplete.nvim' Plug 'roxma/nvim-yarp' Plug 'roxma/vim-hug-neovim-rpc' endif " Use deoplete. let g:deoplete#enable_at_startup = 1 2] deoplete-ternjs (bridge for linking tern plugs)
    --> init.vim::
    Plug 'carlitux/deoplete-ternjs', { 'do': 'npm install -g tern' } 3] tern_for_vim  (it is bread and butter)
    --> init.vim::
    Plug 'marijnh/tern_for_vim' then, put phaser auto completion api  to  ...tern_for_vim>node_modules>tern>plugin
    ***for detail follow point no  [3] from  http://redchilligame.com/how_to_use_phaser_with_vim
    3] Now the most important  step ::
    install tern globally
    sudo npm install -g tern
    and put another phaser auto completion api  to  ...node_modules>tern>plugin  this time globally also
    eg:: /usr/lib/node_modules/tern/plugin/....
    And BOOM !! there you have it all set
    Now all the phaser auto-completion is shown as you type .
    to use tern hints  --->  :TernType and :TernDoc  (in vim  the :TernType and :TernDoc  is automatically displayed when matched , no need to type for neocomplete)
    and if the auto-completion list is not shown  then only use "ctrl x + ctrl o" 
    and if you use VIM :: do not toggle off neocomplete by default make a swith key to toggle off/on and use "CTRL X + CTRL O"  for unknown listing of phaser auto-completion and switch back if satisfied . for NEOVIM no need to worry about this. (since neocomplete is not needed)
    --vim/neovim  + phaser Rocks!!!
  24. Haha
    espace got a reaction from speedo in is it someone who success to implement tern-phaser with vim ?   
    yes !
    finally i success with you big thanks
    i have followed these steps:
    install nodejs 8 and not 9
    :set ft=javascript
    :set omnifunc
    disable neocomplete and press ctrl+x and ctrl+o after and tadam the same screen than you.
    big big thanks !!!!!!!
  25. Thanks
    espace reacted to speedo in is it someone who success to implement tern-phaser with vim ?   
    Just to be sure,
    I have tested in all platform as described in http://redchilligame.com/how_to_use_phaser_with_vim
     and it works very well (100/100 %).
    -> python(2,3) ?
    -> in home dir::
               ->node_modules .../plugin/
    --> give it a try with vundle plugin manager
    --> re-check your vimrc file(path/calling..) and folder location once.
    --> install all the requirement plugins for associative plugins see doc.
    --> if all is set it will work (100/100 %)
    keep trying (VIM + PHASER ROCKS!!)
    Test result with tern plug both in gvim/vim::
    phaser with vim in ubuntu [linux]::
    phaser with vim in fedora [linux]::
    phaser with vim in windows 10::

  • Create New...