Search the Community

Showing results for tags 'game'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Coding and Game Design
  • Frameworks
    • Phaser
    • Pixi.js
    • Babylon.js
    • Panda.js
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered

Found 632 results

  1. SVG and audio [SOLVED]

    Hi there, I'm looking for a way to display audio with an SVG file withe a web browser. And I don't know how to do so. I found a thread on StackOverflow but I can't comment it, so I started a new thread. So, this webpage seems to be working with this code: <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:html="http://www.w3.org/1999/xhtml" viewBox="0 0 1600 1000"> <defs> <style> :root { background: black } text { fill: white; font: 60px sans-serif; font-weight: 900; text-anchor: middle; pointer-events: none } #about { pointer-events: visiblePainted; } a { fill: #4096EE; } a:hover { text-decoration: underline; } .button:hover { filter: url(#huerot80) } .button:active { filter: url(#huerot50) } #about { font-size: 12px } </style> <filter id="ds"> <feGaussianBlur in="SourceAlpha" stdDeviation="3"/> <feOffset dx="2" dy="2"/> <feComposite in="SourceGraphic" operator="over"/> </filter> <filter id="huerot80" x="0" y="0" width="1" height="1"> <feColorMatrix type="hueRotate" values="80"/> </filter> <filter id="huerot50" x="0" y="0" width="1" height="1"> <feColorMatrix type="hueRotate" values="50"/> </filter> <linearGradient id="stops"> <stop style="stop-color:#4096EE;stop-opacity:1" offset="0"/> <stop style="stop-color:#4096EE;stop-opacity:0" offset="1"/> </linearGradient> <linearGradient x1="0" y1="0" x2="0" y2="-1.5" id="fill" xlink:href="#stops" spreadMethod="reflect"/> <linearGradient x1="0" y1="0" x2="0" y2="-1.5" id="stroke" xlink:href="#stops" spreadMethod="reflect" gradientTransform="scale(1 -1)"/> <script> function $(sel) { return document.querySelector(sel); } </script> <audio xmlns="http://www.w3.org/1999/xhtml"> <source src="media/bubbles.ogg" type="audio/ogg"/> <source src="media/bubbles.mp3" type="audio/mpeg"/> <source src="media/bubbles.wav" type="audio/x-wav"/> </audio> </defs> <g class="button" transform="translate(600, 200)"> <rect width="400" height="86" rx="16" fill="url(#fill)" stroke="url(#stroke)" onclick="try { $('audio').currentTime=0; } catch(e) {} $('audio').play()"/> <text x="200" y="65" filter="url(#ds)">Click me</text> </g> <g class="button" transform="translate(600, 300)"> <rect width="400" height="86" rx="16" fill="url(#fill)" stroke="url(#stroke)" onmouseover="$('audio').play(); $('audio').loop=true;" onmouseout="$('audio').pause(); try { $('audio').currentTime=0; } catch(e) {} $('audio').loop=false;"/> <text x="200" y="65" filter="url(#ds)">Hover me</text> </g> <text id="about" x="50%" y="50%">This example uses HTML5 audio together with SVG. <a xlink:href="http://soundbible.com/1137-Bubbles.html">Bubbles sound effect</a> recorded by Mike Koenig (<a xlink:href="http://creativecommons.org/licenses/by/3.0/">CC-By</a>). </text> </svg> And when I try to copy/paste it and try it to understand how it works and how to modify it, i get a problem: When I try to trigger the audio (with the click or the hover): TypeError: $(...).play is not a function[En savoir plus] test.html:1:1 TypeError: $(...).pause is not a function[En savoir plus] I tried several things but I couldn't solve this problem and display audio with my web browser (firefox and chromium). Thank's for your help ^^ If you know an other light way to play audio with an SVG file I'm also ready to hear it ^^ Cheers
  2. Hello Game Publisher and Game Studio, I want to sell premium quality of my HTML5 games source code. I try to clone the game mechanics of some great HTML5 games in the market, and i did make it 100 % perfect. Now i want to sell my HTML5 games source codes. Here is the list of games clone that i want to sell http://storage.id.net/y8-studio/html5/akeemywka/hunterwillie/index.html http://media2.y8.com/y8-studio/Html5/playtomax/dino_rage/ http://media2.y8.com/y8-studio/Html5/tomb_of_the_universe/ http://files.cdn.spilcloud.com/webgl/TR-13-01/index.html http://www8.agame.com/a10/play/c/cheapskates/ http://media2.y8.com/touchscreen/knight_treasure/ http://media2.y8.com/y8-studio/Html5/barbarian_hunter_html5_v2/ http://cdn-factory.marketjs.com/en/street-fight/index.html http://storage.id.net/y8-studio/html5/akeemywka/farm_frenzy_2/index.html http://storage.id.net/y8-studio/html5/akeemywka/battle_robot_wolf_age/index.html *Terms and Conditions: -I just sell the game mechanics, the artwork and graphic inside the game is only for sample, to show the game mechanic run perfectly. -You can not use the artwork and graphic inside the game, that is copyright content. You must use your own graphic when you publish the game to public. -You can hire me and my team to design the artwork, with additional cost. or you can find some digital graphic artist by yourself. -The price is high and expensive. because i clone the game mechanics took many years and work hours. -I can show you the game source codes running local on my computer using Teamviewer, just to make sure that i do really have the game source codes. -I will add more terms and conditions later, if needed. I hope we can work together. Thank you. Best Regards, Cherry Romandiaz
  3. Hello everyone, I want to present you my game, "Flappy Wings". Gameplay preview on youtube: https://www.youtube.com/watch?v=3Di1YM7_iZM Play the game online now: http://games.odiusfly.com/flappywings Available on google play store: https://play.google.com/store/apps/details?id=com.odiusflystudio.flappywings More games available on my website: http://odiusfly.com This game is available for licensing.. If you are interested, please contact me via email! ; -) Best regards, Kyriakos
  4. [Phaser] Infinitris.io

    Hi, Infinitris.io - A massively multiplayer online falling block puzzle game, created using the Phaser game engine. Controls: Arrow keys and spacebar. Current Features: Instant join - only specify your nickname and you're ready to play. Multiplayer. No player limit. Dynamically sized grid with horizontal wrapping. Mistake detection. Sabotage other players by dropping on them. Phase shift into gaps directly below you (hold the down key while your block is being placed). Ingame chat [Enter]. Scoreboard. Facebook: https://www.facebook.com/infinitris Twitter: https://twitter.com/infinitris_io Blog: https://infinitrisblog.wordpress.com/ Please give it a try and let me know what you think! Pyre
  5. Hello everyone, Dot Snap return with new mission: The Battle Gameplay preview on youtube: https://www.youtube.com/watch?v=C4zc0cjBFWg Play the game online now: http://games.odiusfly.com/dotsnapbattle/full Available on google play store: https://play.google.com/store/apps/details?id=com.odiusflystudio.dotsnapbattle More games available on my website: http://odiusfly.com This game is available for licensing.. If you are interested, please contact me via email! ; -) Best regards, Kyriakos
  6. Flappy Rock, My first game in phaser:)

    Play the game
  7. How to restart a Game.

    Hello Everyone, I am trying to develop a breakout type game. But can't restart the game. Is there any easy way to do that? Thanks in advance.
  8. Wedding Run (open source)

    Hi All! Intro As a front-end developer it was a MUST to create an online HTML5 game for our wedding website I've recently discovered Phaser and I was amazed by the things you can achive with it. The Phaser community is just awesome, I've got a lot of help from forums, examples and tutorials I've found during the development. I would like to give something back to the community. That's one of the reasons I've published the source code of the game. The game Wedding Run is an endless 2D platform game. You can play either with the groom or with the bride. The long as you will survive the more points you can achieve. Killing bunnies and collecting coins can raise your score! Have phun! Try it Try it online at http://www.zsondre.hu/wd/ Check out the source code at https://github.com/aendre/wedding-run
  9. Hello everyone, I want to present you my game, "Dot Snap". Gameplay preview on youtube: https://www.youtube.com/watch?v=x0J8J3DvVgg Play the game online now: http://games.odiusfly.com/dotsnap/full Available on google play store: https://play.google.com/store/apps/details?id=com.odiusflystudio.dotsnap More games available on my website: http://odiusfly.com This game is available for licensing.. If you are interested, please contact me via email! ; -) Best regards, Kyriakos
  10. Hi, My name is Bilge Kaan. I've been making HTML5 Games since 2013. You can check my portfolio here: http://td2tl.com Thank you, Bilge Kaan
  11. haha, I'm a old developer I started to make game from 2008 1. 2008-2017, flash game 2. 2015-2017, h5 game This game is used these engine and tools 1. H5 engine, LayaAir, this engine is very wonderful, I just used safari to play it, this game will have 55~60fps 2. UI IDE, FairyGUI, I can't find other UI EDIT IDE is good than it, I can use it do anything, and it's very very easy, it has timeline like flash, and it has more useful components. I can use it make UI on diffrient size of mobile, yeah, just use IDE, not source. 3. Spine, 3D animation tools LayaAir and FairyGUI are from chinese company, but it has english language. layaair -> http://www.layabox.com/en/ fairyGUI -> http://www.fairygui.com/en/ I hope you like my game, I hope I can find a good h5 game job, i can teach your team how to use LayaAir and FairyGUI, my email is bingqimao@qq.com Sorry, my english is not good. ^-^ first photo prove that I used h5 engine to make this game
  12. Phaser simple Game lags on mobile

    Hi, I am new to phaser as well as game designing. I created my first game as hobby using phaser. it is working fine in desktop but lags very bad on mobile devices. Images I am using for game is very small. game is smaller that 2mb. I am attaching my main.js file hope someone can help me. thanks var buttetSpwanSpeed; var bulletSpeed; var enemySpwanSpeed; var enemySpeed; var golis; var enemies; var enemyLoop; var scoreText; var powers; var bulletSize; setStart(); //game phaser var game=new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.WebGL,""); var BootState={ //loding accets preload: function(){ this.load.image('LodingScreen', 'assets/desimulga.png'); this.load.image('background', 'assets/blue.png'); }, create: function(){ game.state.start("LoadingState"); }, }; var LoadingState={ //loding acc preload: function(){ bg=this.game.add.tileSprite(0,0,600,300,'background'); bg.height = game.height; bg.width = game.width; LodingScreen=this.game.add.sprite(this.game.world.centerX,this.game.world.centerY,'LodingScreen'); LodingScreen.anchor.setTo(0.5); LodingScreen.scale.setTo(0.5,0.5); this.load.image('spaceship', 'assets/player.png'); this.load.image('goli', 'assets/bullet.png'); //load ememies this.load.image('enemy1', 'assets/enemies/enemy1.png'); this.load.image('enemy2', 'assets/enemies/enemy2.png'); this.load.image('enemy3', 'assets/enemies/enemy3.png'); this.load.image('enemy4', 'assets/enemies/enemy4.png'); this.load.image('enemy5', 'assets/enemies/enemy5.png'); this.load.spritesheet('power1', 'assets/power/bulletUp.png',34,33,4); this.load.image('restart', 'assets/restart.png'); this.load.spritesheet('blast', 'assets/explosion.png',400,400,8); game.load.audio('fire', 'assets/music/bullet.mp3'); game.load.audio('killed', 'assets/music/killed.mp3'); //game.load.audio('bg_music', 'assets/music/background.mp3'); game.load.audio('death_music', 'assets/music/death.mp3'); game.load.audio('start_music', 'assets/music/start.mp3'); }, create: function(){ game.time.events.add(Phaser.Timer.SECOND * 2, function(){ bg.kill(); LodingScreen.kill(); game.state.start("PreGameState"); },this); }, }; var PreGameState={ //loding accets create: function(){ game.scale.refresh(); bg=this.game.add.tileSprite(0,0,600,300,'background'); bg.height = game.height; bg.width = game.width; Startb=this.game.add.text(this.game.world.centerX,this.game.world.centerY, 'TAP TO START' , { fontSize: '32px', fill: 'yellow' }); Startb.anchor.setTo(0.5); Startb.scale.setTo(0.5,0.5); ship=this.game.add.sprite(this.game.world.centerX,this.game.world.height*0.4,'spaceship'); ship.scale.setTo(0.4); ship.anchor.setTo(0.5); game.physics.arcade.enable(ship); bg.inputEnabled=true; start_music = game.add.audio('start_music'); start_music.allowMultiple = true; start_music.addMarker('start_music', 0, 30); bg.events.onInputDown.add(function(){ bg.inputEnabled=false; Startb.kill(); start_music.play("start_music"); // game.physics.arcade.moveToXY(ship, this.game.world.centerX, this.game.world.height*0.8, 300, 3000); // game.add.tween(ship).to( { y: game.world.height*0.8 }, 3000, Phaser.Easing.Sinusoidal.InOut, true); var tween = game.add.tween(ship).to({ x: [this.game.world.centerX, this.game.world.width*0, this.game.world.width, this.game.world.centerX], y: [this.game.world.height*0.4, this.game.world.height*0.5, this.game.world.height*0.6, this.game.world.height*0.8], }, 2000,Phaser.Easing.Quadratic.Out, true).interpolation(function(v, k){ return Phaser.Math.bezierInterpolation(v, k); }); game.time.events.add(Phaser.Timer.SECOND * 2, function() { bg.kill(); ship.kill(); game.state.start("GameState"); } ,this); }, this); }, }; var GameState={ //loding accets preload: function(){ }, create: function(){ //background this.background=this.game.add.tileSprite(0,0,600,300,'background'); this.background.height = game.height; this.background.width = game.width; this.background.inputEnabled=true; this.background.input.enableDrag(true); this.background.input.startDrag = function(pointer) { pointer.shipStart = new Phaser.Point(GameState.ship.x, GameState.ship.y); Phaser.InputHandler.prototype.startDrag.call(this, pointer); }; this.background.input.updateDrag = function(pointer) { GameState.ship.x = pointer.shipStart.x - pointer.positionDown.x + pointer.x; GameState.ship.y = pointer.shipStart.y - pointer.positionDown.y + pointer.y; GameState.background.x=0; GameState.background.y=0; }; //ship this.ship=this.game.add.sprite(this.game.world.centerX,this.game.world.height*0.8,'spaceship'); this.ship.scale.setTo(0.4); this.ship.anchor.setTo(0.5); game.physics.arcade.enable(this.ship); // this.ship.inputEnabled=true; // this.ship.input.enableDrag(true); //score this.scoreText = this.game.add.text(16, 16, 'Kills: 0', { fontSize: '32px', fill: '#fff' }); //background Music // music = game.add.audio('bg_music'); //music.play('', 0, 1, true); //bullet sound bullet_sound = game.add.audio('fire'); bullet_sound.allowMultiple = true; bullet_sound.volume=0.5; bullet_sound.addMarker('fire', 0, 0.5); //Killed sound killed_sound = game.add.audio('killed'); killed_sound.allowMultiple = true; killed_sound.addMarker('killed', 0, 0.5); //death music death_music = game.add.audio('death_music'); death_music.allowMultiple = true; death_music.addMarker('death_music', 0, 10); //groups of bullets and enemies golis=game.add.group(); enemies=game.add.group(); powers=game.add.group(); //fire bullet loop fireLoop=game.time.events.loop(Phaser.Timer.SECOND*1/buttetSpwanSpeed, fireBullet, this); //this.game.input.onTap.add(fireBullet, this); //create ememy loop enemyLoop=game.time.events.loop(Phaser.Timer.SECOND*1/enemySpwanSpeed, createEnemy, this); //change ememy speed and enemy spwan speed loop enemySpeedLoop=game.time.events.loop(Phaser.Timer.SECOND*1.5, changeEnemySpeed, this); //give powerup powerUp=game.time.events.loop(Phaser.Timer.SECOND*20, powerFun, this); }, update: function(){ //scrolling background this.background.tilePosition.y+=2; //keybord control if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { this.ship.y-=2; } if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { this.ship.y+=2; } if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { this.ship.x+=2; } if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { this.ship.x-=2; } //dont go out if(this.ship.y<0+this.ship.height/2) { this.ship.y=0+this.ship.height/2; } if(this.ship.y>this.game.world.height-this.ship.height/2) { this.ship.y=this.game.world.height-this.ship.height/2; } if(this.ship.x<0+this.ship.width/2) { this.ship.x=0+this.ship.width/2; } if(this.ship.x>this.game.world.width-this.ship.width/2) { this.ship.x=this.game.world.width-this.ship.width/2; } //check for collisions game.physics.arcade.overlap(golis,enemies,b_e_collide,null,this); game.physics.arcade.overlap(this.ship,enemies,s_e_collide,null,this); game.physics.arcade.overlap(this.ship,powers,s_power1_collide,null,this); }, }; //setting start game conditions function setStart(){ buttetSpwanSpeed=2; bulletSpeed=2000; enemySpwanSpeed=1; enemySpeed=300; score=0; bulletSize=1.2 } //fire bullet function function fireBullet(){ goli=this.game.add.sprite(this.ship.x,this.ship.y-this.ship.height/2,'goli'); goli.anchor.setTo(0.5); goli.scale.setTo(bulletSize,1); goli.checkWorldBounds = true; goli.outOfBoundsKill = true; //adding to group golis.add(goli); game.world.moveDown(goli); game.physics.arcade.enable(goli); goli.body.collisonWorldBounds=true; goli.body.velocity.y=-bulletSpeed; bullet_sound.play("fire"); } //create enemy function function createEnemy(){ enemyNo=game.rnd.integerInRange(1, 5); x1=game.rnd.integerInRange(0,this.game.world.width); x2=game.rnd.integerInRange(0,this.game.world.width); enemy=this.game.add.sprite(x1,10,'enemy'+enemyNo); enemy.anchor.setTo(0.5); enemy.scale.setTo(0.4); enemy.checkWorldBounds = true; enemies.add(enemy); enemy.outOfBoundsKill = true; game.physics.arcade.enable(enemy); enemy.body.collisonWorldBounds=true; enemy.angle=90; enemy.no=enemyNo; //moving enemy angleRedian=game.physics.arcade.moveToXY(enemy, x2, this.game.world.height+enemy.height, enemySpeed,0); angleDegree=angleRedian*57.2958; enemy.angle=90+angleDegree; } //runs when bullet collide to enemy function b_e_collide(goli,enemy){ //blast blast=this.game.add.sprite(enemy.x,enemy.y,'blast'); blast.anchor.setTo(0.5); blast.scale.setTo(0.5); var explosion=blast.animations.add('explosion'); blast.animations.play('explosion',30,false,true); //killing goli.kill(); enemy.kill(); //update scores if(enemy.no<4) { score+=1; killed_sound.play('killed'); } this.scoreText.text = 'Kills: ' + score; } //runs when ship collide to enemy function s_e_collide(ship,enemy){ blast=this.game.add.sprite(enemy.x,enemy.y,'blast'); blast.anchor.setTo(0.5); blast.scale.setTo(0.5); var explosion=blast.animations.add('explosion'); blast.animations.play('explosion',10,false,true); ship.kill(); enemy.kill(); //music.stop(); this.scoreText.kill(); death_music.play("death_music"); game.time.events.remove(fireLoop); game.time.events.add(Phaser.Timer.SECOND * 2, function() { fianlScore = this.game.add.text(this.game.world.centerX,this.game.world.centerY, 'KILL: '+score, { fontSize: '32px', fill: 'yellow' }); fianlScore.anchor.setTo(0.5); gameOverText = this.game.add.text(this.game.world.centerX,this.game.world.centerY - fianlScore.height, 'GAME OVER', { fontSize: '32px', fill: 'red' }); gameOverText.anchor.setTo(0.5); //restart button restart=this.game.add.sprite(this.game.world.centerX,this.game.world.centerY + fianlScore.height+10,'restart'); restart.anchor.setTo(0.5); restart.scale.setTo(0.05,0.05); restart.inputEnabled = true; restart.events.onInputDown.add(restartGame, this); game.time.events.stop(); }, this); } //runs when ship collide power1 function s_power1_collide(ship,power){ power.kill(); game.time.events.remove(fireLoop); fireLoop=game.time.events.loop(Phaser.Timer.SECOND*1/10, fireBullet, this); game.time.events.add(Phaser.Timer.SECOND * 10, function(){ game.time.events.remove(fireLoop); fireLoop=game.time.events.loop(Phaser.Timer.SECOND*1/buttetSpwanSpeed, fireBullet, this); },this); } function changeEnemySpeed() { if(enemySpeed<=900) { enemySpeed+=5; } if(enemySpwanSpeed<=3) { enemySpwanSpeed+=0.025; } enemyLoop.delay=Phaser.Timer.SECOND*1/enemySpwanSpeed; } //send power up function powerFun() { x1=game.rnd.integerInRange(0,this.game.world.width); x2=game.rnd.integerInRange(0,this.game.world.width); power=this.game.add.sprite(x1,10,'power1'); power.anchor.setTo(0.5); var shine=power.animations.add('shine'); power.animations.play('shine',5,true,true); power.checkWorldBounds = true; power.outOfBoundsKill = true; powers.add(power); game.physics.arcade.enable(power); power.body.collisonWorldBounds=true; game.physics.arcade.moveToXY(power, x2, this.game.world.height+power.height, 400,0); powerDelay=game.rnd.integerInRange(20,35); powerUp.delay=Phaser.Timer.SECOND*powerDelay; } function restartGame(){ setStart(); game.time.events.start(); game.state.start("PreGameState"); } game.state.add("GameState",GameState); game.state.add("BootState",BootState); game.state.add("LoadingState",LoadingState); game.state.add("PreGameState",PreGameState); game.state.start("BootState"); main.js
  13. I'm developing a simple game application using BabylonJS engine where I want to move the body parts of a human 3D avatar by using UI controllers. The application runs smoothly on the computer. Then I created an IOS application using phonegap and tried to run it on an Ipad. But it is really slow when it run on the mobile environment. Is there any mechanism to optimize the game to support the mobile environment other than reducing the quality of the 3D model.
  14. Phaser Game Lag In Mobile

    Hi, I am new to phaser as well as game designing. I created my first game as hobby using phaser. it is working fine in desktop but lags very bad on mobile devices. Images I am using for game is very small. game is smaller that 2mb. I am attaching my main.js file hope someone can help me. thanks var buttetSpwanSpeed; var bulletSpeed; var enemySpwanSpeed; var enemySpeed; var golis; var enemies; var enemyLoop; var scoreText; var powers; var bulletSize; setStart(); //game phaser var game=new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.CANVAS,"gamearea"); var BootState={ //loding accets preload: function(){ this.load.image('LodingScreen', 'assets/desimulga.png'); this.load.image('background', 'assets/blue.png'); }, create: function(){ game.state.start("LoadingState"); }, }; var LoadingState={ //loding acc preload: function(){ bg=this.game.add.tileSprite(0,0,600,300,'background'); bg.height = game.height; bg.width = game.width; LodingScreen=this.game.add.sprite(this.game.world.centerX,this.game.world.centerY,'LodingScreen'); LodingScreen.anchor.setTo(0.5); LodingScreen.scale.setTo(0.5,0.5); this.load.image('spaceship', 'assets/player.png'); this.load.image('goli', 'assets/bullet.png'); //load ememies this.load.image('enemy1', 'assets/enemies/enemy1.png'); this.load.image('enemy2', 'assets/enemies/enemy2.png'); this.load.image('enemy3', 'assets/enemies/enemy3.png'); this.load.image('enemy4', 'assets/enemies/enemy4.png'); this.load.image('enemy5', 'assets/enemies/enemy5.png'); this.load.spritesheet('power1', 'assets/power/bulletUp.png',34,33,4); this.load.image('restart', 'assets/restart.png'); this.load.spritesheet('blast', 'assets/explosion.png',400,400,8); game.load.audio('fire', 'assets/music/bullet.mp3'); game.load.audio('killed', 'assets/music/killed.mp3'); //game.load.audio('bg_music', 'assets/music/background.mp3'); game.load.audio('death_music', 'assets/music/death.mp3'); game.load.audio('start_music', 'assets/music/start.mp3'); }, create: function(){ game.time.events.add(Phaser.Timer.SECOND * 2, function(){ bg.kill(); LodingScreen.kill(); game.state.start("PreGameState"); },this); }, }; var PreGameState={ //loding accets create: function(){ game.scale.refresh(); bg=this.game.add.tileSprite(0,0,600,300,'background'); bg.height = game.height; bg.width = game.width; Startb=this.game.add.text(this.game.world.centerX,this.game.world.centerY, 'TAP TO START' , { fontSize: '32px', fill: 'yellow' }); Startb.anchor.setTo(0.5); Startb.scale.setTo(0.5,0.5); ship=this.game.add.sprite(this.game.world.centerX,this.game.world.height*0.4,'spaceship'); ship.scale.setTo(0.4); ship.anchor.setTo(0.5); game.physics.arcade.enable(ship); bg.inputEnabled=true; start_music = game.add.audio('start_music'); start_music.allowMultiple = true; start_music.addMarker('start_music', 0, 30); bg.events.onInputDown.add(function(){ bg.inputEnabled=false; Startb.kill(); start_music.play("start_music"); // game.physics.arcade.moveToXY(ship, this.game.world.centerX, this.game.world.height*0.8, 300, 3000); // game.add.tween(ship).to( { y: game.world.height*0.8 }, 3000, Phaser.Easing.Sinusoidal.InOut, true); var tween = game.add.tween(ship).to({ x: [this.game.world.centerX, this.game.world.width*0, this.game.world.width, this.game.world.centerX], y: [this.game.world.height*0.4, this.game.world.height*0.5, this.game.world.height*0.6, this.game.world.height*0.8], }, 2000,Phaser.Easing.Quadratic.Out, true).interpolation(function(v, k){ return Phaser.Math.bezierInterpolation(v, k); }); game.time.events.add(Phaser.Timer.SECOND * 2, function() { bg.kill(); ship.kill(); game.state.start("GameState"); } ,this); }, this); }, }; var GameState={ //loding accets preload: function(){ }, create: function(){ //background this.background=this.game.add.tileSprite(0,0,600,300,'background'); this.background.height = game.height; this.background.width = game.width; this.background.inputEnabled=true; this.background.input.enableDrag(true); this.background.input.startDrag = function(pointer) { pointer.shipStart = new Phaser.Point(GameState.ship.x, GameState.ship.y); Phaser.InputHandler.prototype.startDrag.call(this, pointer); }; this.background.input.updateDrag = function(pointer) { GameState.ship.x = pointer.shipStart.x - pointer.positionDown.x + pointer.x; GameState.ship.y = pointer.shipStart.y - pointer.positionDown.y + pointer.y; GameState.background.x=0; GameState.background.y=0; }; //ship this.ship=this.game.add.sprite(this.game.world.centerX,this.game.world.height*0.8,'spaceship'); this.ship.scale.setTo(0.4); this.ship.anchor.setTo(0.5); game.physics.arcade.enable(this.ship); // this.ship.inputEnabled=true; // this.ship.input.enableDrag(true); //score this.scoreText = this.game.add.text(16, 16, 'Kills: 0', { fontSize: '32px', fill: '#fff' }); //background Music // music = game.add.audio('bg_music'); //music.play('', 0, 1, true); //bullet sound bullet_sound = game.add.audio('fire'); bullet_sound.allowMultiple = true; bullet_sound.volume=0.5; bullet_sound.addMarker('fire', 0, 0.5); //Killed sound killed_sound = game.add.audio('killed'); killed_sound.allowMultiple = true; killed_sound.addMarker('killed', 0, 0.5); //death music death_music = game.add.audio('death_music'); death_music.allowMultiple = true; death_music.addMarker('death_music', 0, 10); //groups of bullets and enemies golis=game.add.group(); enemies=game.add.group(); powers=game.add.group(); //fire bullet loop fireLoop=game.time.events.loop(Phaser.Timer.SECOND*1/buttetSpwanSpeed, fireBullet, this); //this.game.input.onTap.add(fireBullet, this); //create ememy loop enemyLoop=game.time.events.loop(Phaser.Timer.SECOND*1/enemySpwanSpeed, createEnemy, this); //change ememy speed and enemy spwan speed loop enemySpeedLoop=game.time.events.loop(Phaser.Timer.SECOND*1.5, changeEnemySpeed, this); //give powerup powerUp=game.time.events.loop(Phaser.Timer.SECOND*20, powerFun, this); }, update: function(){ //scrolling background this.background.tilePosition.y+=2; //keybord control if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { this.ship.y-=2; } if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { this.ship.y+=2; } if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { this.ship.x+=2; } if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { this.ship.x-=2; } //dont go out if(this.ship.y<0+this.ship.height/2) { this.ship.y=0+this.ship.height/2; } if(this.ship.y>this.game.world.height-this.ship.height/2) { this.ship.y=this.game.world.height-this.ship.height/2; } if(this.ship.x<0+this.ship.width/2) { this.ship.x=0+this.ship.width/2; } if(this.ship.x>this.game.world.width-this.ship.width/2) { this.ship.x=this.game.world.width-this.ship.width/2; } //check for collisions game.physics.arcade.overlap(golis,enemies,b_e_collide,null,this); game.physics.arcade.overlap(this.ship,enemies,s_e_collide,null,this); game.physics.arcade.overlap(this.ship,powers,s_power1_collide,null,this); }, }; //setting start game conditions function setStart(){ buttetSpwanSpeed=2; bulletSpeed=2000; enemySpwanSpeed=1; enemySpeed=300; score=0; bulletSize=1.2 } //fire bullet function function fireBullet(){ goli=this.game.add.sprite(this.ship.x,this.ship.y-this.ship.height/2,'goli'); goli.anchor.setTo(0.5); goli.scale.setTo(bulletSize,1); goli.checkWorldBounds = true; goli.outOfBoundsKill = true; //adding to group golis.add(goli); game.world.moveDown(goli); game.physics.arcade.enable(goli); goli.body.collisonWorldBounds=true; goli.body.velocity.y=-bulletSpeed; bullet_sound.play("fire"); } //create enemy function function createEnemy(){ enemyNo=game.rnd.integerInRange(1, 5); x1=game.rnd.integerInRange(0,this.game.world.width); x2=game.rnd.integerInRange(0,this.game.world.width); enemy=this.game.add.sprite(x1,10,'enemy'+enemyNo); enemy.anchor.setTo(0.5); enemy.scale.setTo(0.4); enemy.checkWorldBounds = true; enemies.add(enemy); enemy.outOfBoundsKill = true; game.physics.arcade.enable(enemy); enemy.body.collisonWorldBounds=true; enemy.angle=90; enemy.no=enemyNo; //moving enemy angleRedian=game.physics.arcade.moveToXY(enemy, x2, this.game.world.height+enemy.height, enemySpeed,0); angleDegree=angleRedian*57.2958; enemy.angle=90+angleDegree; } //runs when bullet collide to enemy function b_e_collide(goli,enemy){ //blast blast=this.game.add.sprite(enemy.x,enemy.y,'blast'); blast.anchor.setTo(0.5); blast.scale.setTo(0.5); var explosion=blast.animations.add('explosion'); blast.animations.play('explosion',30,false,true); //killing goli.kill(); enemy.kill(); //update scores if(enemy.no<4) { score+=1; killed_sound.play('killed'); } this.scoreText.text = 'Kills: ' + score; } //runs when ship collide to enemy function s_e_collide(ship,enemy){ blast=this.game.add.sprite(enemy.x,enemy.y,'blast'); blast.anchor.setTo(0.5); blast.scale.setTo(0.5); var explosion=blast.animations.add('explosion'); blast.animations.play('explosion',10,false,true); ship.kill(); enemy.kill(); //music.stop(); this.scoreText.kill(); death_music.play("death_music"); game.time.events.remove(fireLoop); game.time.events.add(Phaser.Timer.SECOND * 2, function() { fianlScore = this.game.add.text(this.game.world.centerX,this.game.world.centerY, 'KILL: '+score, { fontSize: '32px', fill: 'yellow' }); fianlScore.anchor.setTo(0.5); gameOverText = this.game.add.text(this.game.world.centerX,this.game.world.centerY - fianlScore.height, 'GAME OVER', { fontSize: '32px', fill: 'red' }); gameOverText.anchor.setTo(0.5); //restart button restart=this.game.add.sprite(this.game.world.centerX,this.game.world.centerY + fianlScore.height+10,'restart'); restart.anchor.setTo(0.5); restart.scale.setTo(0.05,0.05); restart.inputEnabled = true; restart.events.onInputDown.add(restartGame, this); game.time.events.stop(); }, this); } //runs when ship collide power1 function s_power1_collide(ship,power){ power.kill(); game.time.events.remove(fireLoop); fireLoop=game.time.events.loop(Phaser.Timer.SECOND*1/10, fireBullet, this); game.time.events.add(Phaser.Timer.SECOND * 10, function(){ game.time.events.remove(fireLoop); fireLoop=game.time.events.loop(Phaser.Timer.SECOND*1/buttetSpwanSpeed, fireBullet, this); },this); } function changeEnemySpeed() { if(enemySpeed<=900) { enemySpeed+=5; } if(enemySpwanSpeed<=3) { enemySpwanSpeed+=0.025; } enemyLoop.delay=Phaser.Timer.SECOND*1/enemySpwanSpeed; } //send power up function powerFun() { x1=game.rnd.integerInRange(0,this.game.world.width); x2=game.rnd.integerInRange(0,this.game.world.width); power=this.game.add.sprite(x1,10,'power1'); power.anchor.setTo(0.5); var shine=power.animations.add('shine'); power.animations.play('shine',5,true,true); power.checkWorldBounds = true; power.outOfBoundsKill = true; powers.add(power); game.physics.arcade.enable(power); power.body.collisonWorldBounds=true; game.physics.arcade.moveToXY(power, x2, this.game.world.height+power.height, 400,0); powerDelay=game.rnd.integerInRange(20,35); powerUp.delay=Phaser.Timer.SECOND*powerDelay; } function restartGame(){ setStart(); game.time.events.start(); game.state.start("PreGameState"); } game.state.add("GameState",GameState); game.state.add("BootState",BootState); game.state.add("LoadingState",LoadingState); game.state.add("PreGameState",PreGameState); game.state.start("BootState"); main.js
  15. I am making a rpg that will have skills with complex movement like if I use my A skill my player will jump and then dash diagonally back to the ground. My problem is not knowing how to achieve this. I tried with making it move to the sky first and then coming back down but they combine and make him only move diagonally. My guess is using timers for it but I don't know where to start. Any help would be appreciates, even if it's not code, just a step by step on how can I accomplish this, I can figure something out later.
  16. Alien Invasion

    Hello everyone I'm creating a new game and I have the basics working. It would be really nice to hear what you think. The game is still under construction but you should be able to play the first level of each mission I am working on the next levels. It is still under construction but i hope to be able to create a fully working version. here is the link: https://sharesoft.nl/phaser/alienInvasion.php?language=en
  17. Hi Guys, Recently I was working on a tanks' battle simulator. It is strongly inspired by Robocode. In short, you program artificial intelligence of your tank and test it during the battle. Of course, you will need JavaScript skills to do that Please give it a try and let me know what do you think. All feedback is welcome http://jsbattle.jamro.net/
  18. Hello comrades, I'm new to phaser and I can't seem to create new objects to the group "capetinhas", even though I can load the sprite through game.add.sprite. Here's the code: var game = new Phaser.Game(448, 448, Phaser.AUTO, '', { preload: preload, create: create, update: update }); function preload () { game.load.image('tabuleiro','assets/tabuleiro.png') game.load.spritesheet('devil','assets/devil.png',32,32); var capetinhas; } function create (){ capetinhas = game.add.group(); game.add.sprite(window.width,0,'tabuleiro');//loading the background game.add.sprite(128,128,'devil'); // this works capetinhas.create(32,32,'devil'); // this doesnt } function update (){ } Any helpe would be really apreciated. Thanks in advance.
  19. Scaling an image down

    How do I scale, or resize, an image in javascript with phaser's framework? I have tried a few different things but they do not seem to be working. I am using a weapon method to throw a pokeball, this is just a test using some code from phaser.io, so the other images aren't mine, I am just testing to try and get the pokeball to be thrown, but it is freaking huge right now! Please help me, I need the pokeball to be about 10x10 px because my character is 64x64. var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.image('bullet', 'Pokeball.png', .01, .01); game.load.image('ship', 'tiles1.png'); } var sprite; var weapon; var cursors; var fireButton; function create() { // Creates 1 single bullet, using the 'bullet' graphic weapon = game.add.weapon(1, 'bullet'); weapon.scale.setTo(.5, .5); // The bullet will be automatically killed when it leaves the world bounds weapon.bulletKillType = Phaser.Weapon.KILL_WORLD_BOUNDS; // Because our bullet is drawn facing up, we need to offset its rotation: weapon.bulletAngleOffset = 90; // The speed at which the bullet is fired weapon.bulletSpeed = 400; sprite = this.add.sprite(320, 500, 'ship'); game.physics.arcade.enable(sprite); // Tell the Weapon to track the 'player' Sprite, offset by 14px horizontally, 0 vertically weapon.trackSprite(sprite, 14, 0); cursors = this.input.keyboard.createCursorKeys(); fireButton = this.input.keyboard.addKey(Phaser.KeyCode.SPACEBAR); } function update() { sprite.body.velocity.x = 0; if (cursors.left.isDown) { sprite.body.velocity.x = -200; } else if (cursors.right.isDown) { sprite.body.velocity.x = 200; } if (fireButton.isDown) { weapon.fire(); } } function render() { weapon.debug(); }
  20. I am trying to make a gate that opens when you click on it, and rotate it 90 degrees. I have accomplished this much, but how do I make it go back to it's original position once I click on it again? For instance: *clicks on gate, gate opens, 90 degrees.* *clicks on gate again, gate closes, -90 degrees from the 90 degrees that it went on previous click* Any help would be appreciated! html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Canvas Game</title> <style> html { background: black } canvas { margin: auto; } </style> </head> <body> <script src="phaser.js"></script> <script src="game.js"></script> </body> </html> game.js var game = new Phaser.Game(550, 540, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); function preload() { game.load.crossOrigin = 'anonymous'; game.load.image('gateopen', 'fenceleft.png'); } var sprite function clickSprite() { console.log("clickSprite"); sprite.angle += 90; } function clickGame() { console.log("clickGame"); } function create() { sprite = game.add.sprite(100, 100, 'gateopen'); sprite.anchor = {x: 1, y: 1} game.inputEnabled = true; sprite.inputEnabled = true; sprite.events.onInputDown.add(clickSprite) game.input.onDown.add(clickGame); } function update() { } function render() { game.debug.bodyInfo(sprite, 32, 32); game.debug.body(sprite); }
  21. Hi, I am trying to make a simple game and have been running into many problems. The problem I am facing now is that I cannot fix this error in my javascript. It says that it cannot read the 'setSize' property on my 'player' sprite, but it works perfectly fine on my other sprites. Next it says that it cannot read the 'velocity' property of the 'player' sprite, but when I comment out the 'setSize' property it works. I just cannot figure out what is wrong, have I misspelled something? I cannot seem to find the problem, so any help would be appreciated. Btw, it worked yesterday, but when I loaded it up today it was no longer working... Html: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Canvas Game</title> <link href="https://fonts.googleapis.com/css?family=Syncopate:700" rel="stylesheet"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> html { background: black } canvas { margin: auto; } h1 { font-family: 'Syncopate', sans-serif; color: rgb(194, 68, 91); text-align: center; margin: 0 auto; font-size: 25px; } h2 { color: white; font-size: 8px; font-family: 'Syncopate', sans-serif; } </style> </head> <body> <header> <h1>Crafty Heroes</h1> </header> <footer> <h2>&copy; SoulesteDesigns 2017</h2> </footer> <script src="phaser.js"></script> <script src="game.js"></script> </body> </html> game.js: // VARIABLES // variables for static objects var walls; var house; var gate; var gate2; // variables for character var cursors; var player; var left; var right; var up; var down; var game = new Phaser.Game(550, 540, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); // ADD HOUSES function addHouse(image) { house = game.add.physicsGroup(); house.create(-250, -240, 'greenhouse'); house.setAll('body.immovable', true); } // ADD FENCES OR WALLS function addWalls(image) { walls = game.add.physicsGroup(); // fences up top walls.create(-90, -200, 'fencefront'); walls.create(5, -200, 'fencefront'); walls.create(100, -200, 'fencefront'); walls.create(195, -200, 'fencefront'); // fences to right walls.create(288, -200, 'fenceright'); walls.create(288, -135, 'fenceright'); walls.create(288, -70, 'fenceright'); walls.create(288, -5, 'fenceright'); // fences at bottom walls.create(5, 59, 'fencefront'); walls.create(100, 59, 'fencefront'); walls.create(195, 59, 'fencefront'); // fences to left walls.create(-91, -200, 'fenceleft'); walls.create(-91, -135, 'fenceleft'); // set the walls to be static walls.setAll('body.immovable', true); } // PRELOAD IMAGES FOR ITEMS, PLAYERS, ETC. function preload() { // preload player game.load.spritesheet('player', 'hero.png', 64, 64); // preload houses game.load.image('greenhouse', 'greenhouse.png'); // preload fences game.load.image('fencefront', 'fencefront.png'); game.load.image('fenceleft', 'fenceleft.png'); game.load.image('fenceright', 'fenceright.png'); // fence that has adjusted hit boundary game.load.image('gate', 'fenceleft.png'); game.load.image('gate2', 'fencefront.png'); // preload ground game.load.image('ground', 'tiles2.png'); } // ADD THINGS TO GAME function create() { // set area that the player may travel to game.world.setBounds(-250, -250, 550, 550); // set background color game.stage.backgroundColor = ('#3c6f42'); gate = game.add.physicsGroup(); game.physics.startSystem(Phaser.Physics.ARCADE); gate = game.add.sprite(-91, -70, 'gate'); gate.name = 'gate'; game.physics.enable([gate], Phaser.Physics.ARCADE); // This adjusts the collision body size to be a 100x50 box. // 50, 25 is the X and Y offset of the newly sized box. gate.body.setSize(15, 90, -2, 3); gate.body.immovable = true; gate2 = game.add.physicsGroup(); game.physics.startSystem(Phaser.Physics.ARCADE); gate2 = game.add.sprite(-90, 59, 'gate2'); gate2.name = 'gate2'; game.physics.enable([gate2], Phaser.Physics.ARCADE); // This adjusts the collision body size to be a 100x50 box. // 50, 25 is the X and Y offset of the newly sized box. gate2.body.setSize(90, 15, 3, 3); gate2.body.immovable = true; // adding the ground var ground = game.add.sprite(-224, -100, 'ground', 1); var ground = game.add.sprite(-224, -60, 'ground', 1); var ground = game.add.sprite(-224, -20, 'ground', 1); var ground = game.add.sprite(-224, 20, 'ground', 1); var ground = game.add.sprite(-184, 20, 'ground', 1); var ground = game.add.sprite(-144, 20, 'ground', 1); // add player image and place in screen player = game.add.sprite(-232, -100, 'player'); player.smoothed = true; player.scale.set(.9); player.body.setSize(30, 40, 16, 16); player.body.immovable = false; // player will "collide" with certain images like walls and houses player.collideWorldBounds = true; // ANIMATION FOR PLAYER CONTROLS down = player.animations.add('down', [0,1,2,3], 10, true); left = player.animations.add('left', [4,5,6,7], 10, true); right = player.animations.add('right', [8,9,10,11], 10, true); up = player.animations.add('up', [12,13,14,15], 10, true); // enable physics in the game (can't go through walls, gravity, etc.) game.physics.enable([player, house, walls, gate], Phaser.Physics.ARCADE); game.physics.startSystem(Phaser.Physics.P2JS); game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.p2.enable(player); // make sure to add this code to add items/walls/buildings addHouse(); addWalls(); // enable keyboard arrows for controls cursors = game.input.keyboard.createCursorKeys(); // camera will follow the character game.camera.follow(player); } // what happens when player does something function update() { // player will now collide with these images rather than pass over them game.physics.arcade.collide(player, house); game.physics.arcade.collide(player, walls); // PLAYER CONTROLS player.body.velocity.set(0); // player presses left key if (cursors.left.isDown) { player.body.velocity.x = -100; player.play('left'); } // player presses right key else if (cursors.right.isDown) { player.body.velocity.x = 100; player.play('right'); } // player presses up key else if (cursors.up.isDown) { player.body.velocity.y = -100; player.play('up'); } // player presses down key else if (cursors.down.isDown) { player.body.velocity.y = 100; player.play('down'); } // player does not press anything else { player.animations.stop(); } } function render() { game.debug.bodyInfo(gate2, 32, 32); game.debug.body(gate2); game.debug.bodyInfo(player, 32, 32); game.debug.body(player); }
  22. Need help with rotation

    I'm new to phaser and doing a course. I'm a noob so dont make fun of me too much. anyways, i need to rotate this image of a cupcake when clicking it counter clockwise 10 degrees. how would i do this? here is my code right now. import 'phaser' var game = new Phaser.Game(500, 300, Phaser.AUTO, 'game', { preload: preload, create: create }) function preload() { game.load.image('cupcake', '/api/asset/png/!vault/phaserData.cupcake') } // Declare a global variable which we can access in any function in the file var cupcake function create() { cupcake = game.add.sprite(80, 120, 'cupcake') // The default sprite anchor point is at the // top-left (anchor.x=0, anchor.y=0) of the image // We change the anchor point to be the center of the image // so that scaling doesn't look weird // TODO: Try other anchor points... cupcake.anchor.x = 0.5 cupcake.anchor.y = 0.5 // By default, clicking on a sprite will have no effect. // We have to enable this feature as follows: cupcake.inputEnabled = true // sprite has different events. More http://phaser.io/docs/2.4.7/Phaser.Events.html#members // we pass a function which is executed when trigger event occurs cupcake.events.onInputDown.add(clickCupcake) // event triggers when we click anywhere on the game screen game.input.onDown.add(clickGame) } function clickCupcake(){ cupcake.scale.x += 0.1 cupcake.scale.y += 0.1 } this currently makes it grow everytime it is clicked but how would i change it to rotate it instead 10 degrees counter clockwise? thanks
  23. How to set hitbox?

    I cannot figure out how to change the hitbox size of my player, the character doesn't fit through a hole in a fence so I want to change the hit box sizes. I already tried this https://phaser.io/examples/v2/arcade-physics/offset-bounding-box but this did not work for me, my screen went black when i did this. // variables for items, walls, etc. var walls; var house; var game = new Phaser.Game(550, 540, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); //add house to game function addHouse(image) { house = game.add.physicsGroup(); house.create(-250, -240, 'greenhouse'); house.setAll('body.immovable', true); } // add fences/walls to the game function addWalls(image) { walls = game.add.physicsGroup(); // fences up top walls.create(-90, -200, 'fencefront'); walls.create(5, -200, 'fencefront'); walls.create(100, -200, 'fencefront'); walls.create(195, -200, 'fencefront'); // fences to right walls.create(288, -200, 'fenceright'); walls.create(288, -135, 'fenceright'); walls.create(288, -70, 'fenceright'); walls.create(288, -5, 'fenceright'); // fences at bottom walls.create(-90, 59, 'fencefront'); walls.create(5, 59, 'fencefront'); walls.create(100, 59, 'fencefront'); walls.create(195, 59, 'fencefront'); // fences to left walls.create(-91, -200, 'fenceright'); walls.create(-91, -135, 'fenceright'); walls.create(-91, -70, 'fenceright'); // set the walls to be static walls.setAll('body.immovable', true); } // preload items, walls, players, etc. function preload() { // preload player game.load.spritesheet('player', 'hero.png', 64, 64); // preload houses game.load.image('greenhouse', 'greenhouse.png'); // preload fences game.load.image('fencefront', 'fencefront.png'); game.load.image('fenceleft', 'fenceleft.png'); game.load.image('fenceright', 'fenceright.png'); } // variables for character var cursors; var player; var left; var right; var up; var down; // add what will be in game function create() { game.world.setBounds(-250, -250, 550, 550); // set background color game.stage.backgroundColor = ('#3c6f42'); // add player image and place in screen player = game.add.sprite(-232, -100, 'player', 1); player.smoothed = false; player.scale.set(1); // player will "collide" with certain images like walls and houses player.collideWorldBounds = true; // ANIMATION FOR PLAYER CONTROLS down = player.animations.add('down', [0,1,2,3], 10, true); left = player.animations.add('left', [4,5,6,7], 10, true); right = player.animations.add('right', [8,9,10,11], 10, true); up = player.animations.add('up', [12,13,14,15], 10, true); // enable physics in the game (can't go through walls, gravity, etc.) game.physics.enable(player, Phaser.Physics.ARCADE); game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.enable(player); // make sure to add this code to add items/walls/buildings addHouse(); addWalls(); // enable keyboard arrows for controls cursors = game.input.keyboard.createCursorKeys(); // camera will follow the character game.camera.follow(player); } // what happens when player does something function update() { // player will now collide with these images rather than pass over them game.physics.arcade.collide(player, house); game.physics.arcade.collide(player, walls); // PLAYER CONTROLS player.body.velocity.set(0); // player presses left key if (cursors.left.isDown) { player.body.velocity.x = -100; player.play('left'); } // player presses right key else if (cursors.right.isDown) { player.body.velocity.x = 100; player.play('right'); } // player presses up key else if (cursors.up.isDown) { player.body.velocity.y = -100; player.play('up'); } // player presses down key else if (cursors.down.isDown) { player.body.velocity.y = 100; player.play('down'); } // player does not press anything else { player.animations.stop(); } } function render() { }
  24. Player and Colliding Objects

    Hi, I need some help with my code, I am trying to create a fenced in area for my character to go in, but he cannot fit through because of the objects that he collides with. How do I change the area that the character collides with? can I reduce the size of the collidable area? The hole in the fence seems quite large enough, but he just won't go through. My game.js // variables for items, walls, etc. var walls; var house; var game = new Phaser.Game(550, 540, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update, render: render }); //add house to game function addHouse(image) { house = game.add.physicsGroup(); house.create(-250, -240, 'greenhouse'); house.setAll('body.immovable', true); } // add fences/walls to the game function addWalls(image) { walls = game.add.physicsGroup(); // fences up top walls.create(-90, -200, 'fencefront'); walls.create(5, -200, 'fencefront'); walls.create(100, -200, 'fencefront'); walls.create(195, -200, 'fencefront'); // fences to right walls.create(288, -200, 'fenceright'); walls.create(288, -135, 'fenceright'); walls.create(288, -70, 'fenceright'); walls.create(288, -5, 'fenceright'); // fences at bottom walls.create(-90, 59, 'fencefront'); walls.create(5, 59, 'fencefront'); walls.create(100, 59, 'fencefront'); walls.create(195, 59, 'fencefront'); // fences to left walls.create(-91, -200, 'fenceright'); walls.create(-91, -135, 'fenceright'); walls.create(-91, -70, 'fenceright'); // set the walls to be static walls.setAll('body.immovable', true); } // preload items, walls, players, etc. function preload() { // preload player game.load.spritesheet('player', 'hero.png', 64, 64); // preload houses game.load.image('greenhouse', 'greenhouse.png'); // preload fences game.load.image('fencefront', 'fencefront.png'); game.load.image('fenceleft', 'fenceleft.png'); game.load.image('fenceright', 'fenceright.png'); } // variables for character var cursors; var player; var left; var right; var up; var down; // add what will be in game function create() { game.world.setBounds(-250, -250, 550, 550); // set background color game.stage.backgroundColor = ('#3c6f42'); // add player image and place in screen player = game.add.sprite(-232, -100, 'player', 1); player.smoothed = false; player.scale.set(1); // player will "collide" with certain images like walls and houses player.collideWorldBounds = true; // ANIMATION FOR PLAYER CONTROLS down = player.animations.add('down', [0,1,2,3], 10, true); left = player.animations.add('left', [4,5,6,7], 10, true); right = player.animations.add('right', [8,9,10,11], 10, true); up = player.animations.add('up', [12,13,14,15], 10, true); // enable physics in the game (can't go through walls, gravity, etc.) game.physics.enable(player, Phaser.Physics.ARCADE); game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.enable(player); // make sure to add this code to add items/walls/buildings addHouse(); addWalls(); // enable keyboard arrows for controls cursors = game.input.keyboard.createCursorKeys(); // camera will follow the character game.camera.follow(player); } // what happens when player does something function update() { // player will now collide with these images rather than pass over them game.physics.arcade.collide(player, house); game.physics.arcade.collide(player, walls); // PLAYER CONTROLS player.body.velocity.set(0); // player presses left key if (cursors.left.isDown) { player.body.velocity.x = -100; player.play('left'); } // player presses right key else if (cursors.right.isDown) { player.body.velocity.x = 100; player.play('right'); } // player presses up key else if (cursors.up.isDown) { player.body.velocity.y = -100; player.play('up'); } // player presses down key else if (cursors.down.isDown) { player.body.velocity.y = 100; player.play('down'); } // player does not press anything else { player.animations.stop(); } } function render() { } The HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Simple Canvas Game</title> <link href="https://fonts.googleapis.com/css?family=Syncopate:700" rel="stylesheet"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> html { background: black } canvas { margin: auto; } h1 { font-family: 'Syncopate', sans-serif; color: rgb(194, 68, 91); text-align: center; margin: 0 auto; font-size: 25px; } </style> </head> <body> <header> <h1>Crafty Heroes</h1> </header> <script src="phaser.js"></script> <script src="game.js"></script> </body> </html>
  25. Jigsaw Palace

    We have recently developed a simplistic puzzle game, Jigsaw Palace using Phaser engine. With the power of Phonegap/Cordova we've put together an Android version, which is available to download on Google Play. https://play.google.com/store/apps/details?id=net.arcticarcade.jigsawpalacefree&hl=en_GB We created a free version which used Revmob advertisements, but also created a paid for version, which comes without the ads. It would be much appreciated if you could help out by downloading the game and giving it a play, and if you like it, maybe leave a rating (we're not expecting 5 stars, just an honest review). Thanks again for your time, and hopefully you will have some fun playing.