Search the Community

Showing results for tags 'javascript'.



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 509 results

  1. How can I create start menu in Phaser? I found nothing on that.
  2. Can someone tell me, please, why collision does not take place during animation? Here is a game : https://oobarbazanoo.github.io/JumperKisame/.
  3. How can I change background of the game in Phaser? I am using tileSprite for the bacground and when I destroy current sprite and add new the new one goes at the top of all my game.
  4. I wrote: background = me.game.add.tileSprite(0, 0, me.game.width, me.game.height, 'back'); How can I change the spritesheet shown at the back? I already have "back2" preloaded.
  5. Let us suppose I added tileSprite to the window like this : background = me.game.add.tileSprite(0, 0, me.game.width, me.game.height, 'back'); After that I added a lot of different things above the tileSprite. And now I want to change background without showing it over everything else. How can I do that?
  6. Here is my code: var Main = function(game){ }; var velocityOfTileMoving = 10, speedOfTileGenerating = 15000, speedOfPlayerMovingRightLeft = 150, facing = 'left', sizeOfPlayer = 0.5, me, spaceBar, jumpTimer = 0; Main.prototype = { create: function() { me = this; spaceBar = me.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); //The spacing for the initial platforms me.spacing = 200; //Set the initial score me.score = 0; //Get the dimensions of the tile we are using me.tileWidth = me.game.cache.getImage('tile').width; me.tileHeight = me.game.cache.getImage('tile').height; //Set the background colour to blue me.game.stage.backgroundColor = '479cde'; me.game.add.tileSprite(0, 0, me.game.width, me.game.height, 'back'); //Enable the Arcade physics system me.game.physics.startSystem(Phaser.Physics.ARCADE); //Add a platforms group to hold all of our tiles, and create a bunch of them me.platforms = me.game.add.group(); me.platforms.enableBody = true; me.platforms.createMultiple(100, 'tile'); //Create the inital on screen platforms me.initPlatforms(); //Add the player to the screen me.createPlayer(); //Create the score label me.createScore(); //Add a platform every speedOfTileGenerating seconds me.timer = game.time.events.loop(speedOfTileGenerating, me.addPlatform, me); //Enable cursor keys so we can create some controls me.cursors = me.game.input.keyboard.createCursorKeys(); }, update: function() { //Make the sprite collide with the ground layer me.game.physics.arcade.collide(me.player, me.platforms); //region delteMaybe //Make the sprite jump when the up key is pushed // if(me.cursors.up.isDown && me.player.body.wasTouching.down) { // me.player.body.velocity.y = -1400; // } // //Make the player go left // if(me.cursors.left.isDown){ // me.player.body.velocity.x = -150; // } // //Make the player go right // if(me.cursors.right.isDown){ // me.player.body.velocity.x = 150; // } //endregion //Check if the player is touching the bottom if(me.player.body.position.y >= me.game.world.height - me.player.body.height){ me.gameOver(); } me.game.input.keyboard.onDownCallback = somethingWasPressed; me.player.body.velocity.x = 0; if(me.cursors.left.isDown) { animateRunLeft(); } else if(me.cursors.right.isDown) { animateRunRight(); } else { if(facing != 'idle') { me.player.animations.play('idle'); if(facing == 'left') { me.player.frame = 5; } else { me.player.frame = 5; } facing = 'idle'; } } if(jumpHasToOccur()) { me.player.body.velocity.y = -250; me.player.animations.play('jump'); me.game.time.events.add(Phaser.Timer.SECOND * 1.450, function(){me.player.animations.play('idle');}, this); jumpTimer = me.game.time.now + 750; } }, gameOver: function(){ this.game.state.start('Main'); }, addTile: function(x, y) { //Get a tile that is not currently on screen var tile = me.platforms.getFirstDead(); //Reset it to the specified coordinates tile.reset(x, y); tile.body.velocity.y = velocityOfTileMoving; tile.body.immovable = true; //When the tile leaves the screen, kill it tile.checkWorldBounds = true; tile.outOfBoundsKill = true; }, addPlatform: function(y) { //If no y position is supplied, render it just outside of the screen if(typeof(y) == "undefined"){ y = -me.tileHeight; //Increase the players score me.incrementScore(); } //Work out how many tiles we need to fit across the whole screen var tilesNeeded = Math.ceil(me.game.world.width / me.tileWidth); //Add a hole randomly somewhere var hole = Math.floor(Math.random() * (tilesNeeded - 3)) + 1; //Keep creating tiles next to each other until we have an entire row //Don't add tiles where the random hole is for (var i = 0; i < tilesNeeded; i++){ if (i != hole && i != hole + 1){ this.addTile(i * me.tileWidth, y); } } }, initPlatforms: function() { var bottom = me.game.world.height - me.tileHeight, top = me.tileHeight; //Keep creating platforms until they reach (near) the top of the screen for(var y = bottom; y > top - me.tileHeight; y = y - me.spacing){ me.addPlatform(y); } }, createPlayer: function() { //Add the player to the game by creating a new sprite me.player = me.game.add.sprite(me.game.world.centerX, me.game.world.height - (me.spacing * 2 + (3 * me.tileHeight)), 'kisameSprite', 'stance/0.png'); me.player.scale.setTo(sizeOfPlayer); //Set the players anchor point to be in the middle horizontally me.player.anchor.setTo(0.5, 1.0); //Enable physics on the player me.game.physics.arcade.enable(me.player); //Make the player fall by applying gravity me.player.body.gravity.y = 2000; //Make the player collide with the game boundaries me.player.body.collideWorldBounds = true; //Make the player bounce a little me.player.body.bounce.y = 0.1; me.player.animations.add('attackMagic', Phaser.Animation.generateFrameNames('attackMagic/', 0, 24, '.png', 1), 7, false, true); me.player.animations.add('attack', Phaser.Animation.generateFrameNames('attack/', 0, 5, '.png', 1), 10, false, true); me.player.animations.add('left', Phaser.Animation.generateFrameNames('run/', 0, 4, '.png', 1), 10, true, true); me.player.animations.add('idle', Phaser.Animation.generateFrameNames('stance/', 0, 3, '.png', 1), 10, true, true); me.player.animations.add('right', Phaser.Animation.generateFrameNames('run/', 0, 4, '.png', 1), 10, true, true); me.player.animations.add('jump', Phaser.Animation.generateFrameNames('jump/', 0, 3, '.png', 1), 10, false, true); }, createScore: function(){ var scoreFont = "100px Arial"; me.scoreLabel = me.game.add.text((me.game.world.centerX), 100, "0", {font: scoreFont, fill: "#fff"}); me.scoreLabel.anchor.setTo(0.5, 0.5); me.scoreLabel.align = 'center'; }, incrementScore: function(){ me.score += 1; me.scoreLabel.text = me.score; }, }; function animateRunRight() { me.player.body.velocity.x = speedOfPlayerMovingRightLeft; if(facing != 'right') { me.player.scale.setTo(sizeOfPlayer, sizeOfPlayer); me.player.animations.play('right'); facing = 'right'; } } function animateRunLeft() { me.player.body.velocity.x = -speedOfPlayerMovingRightLeft; if(facing != 'left') { me.player.scale.setTo(-sizeOfPlayer, sizeOfPlayer); me.player.animations.play('left'); facing = 'left'; } } function jumpHasToOccur() { var jumButtonClicked = me.cursors.up.isDown || spaceBar.isDown; console.log("jumpButtonClicked == " + jumButtonClicked ); var alreadyOnFloor = me.player.body.onFloor() && me.game.time.now > jumpTimer; console.log("alreadyOnFloor == " + alreadyOnFloor); return jumButtonClicked && alreadyOnFloor; } function somethingWasPressed(keyCode) { if(keyEqualTo(keyCode, "a")) {animateAttack();} if(keyEqualTo(keyCode, "m")) {animateAttackMagic();} } function keyEqualTo(keyCode, key) { var equalKey = (keyCode.key == key); return equalKey; } function beIdle() { me.player.animations.play('idle'); if(facing == 'left') { me.player.frame = 5; } else { me.player.frame = 5; } facing = 'idle'; } function animateAttack() { me.player.animations.play('attack', 10, false, false); me.player.animations.currentAnim.onComplete.add(beIdle,this); } function animateAttackMagic() { me.player.animations.play('attackMagic', 3, false, false); me.player.animations.currentAnim.onComplete.add(beIdle,this); } I want player to collide with dynamically generated tiles, but it does not happen. The player just falls down after any animation. For example, is I run left or right the player runs, but falls down simultaneously. To make player and tiles collide I use that in update() function: me.game.physics.arcade.collide(me.player, me.platforms); So, help me, please to figure out what am I doing wrong, why collision between player and tiles does not occur when animation takes plays?
  7. Hello, I'm very new to Javascript (and coding). I just finished my first game, a clone of Pong. I have it controlled via the mouse movement, now I'd like to add code that will let the user swipe up or down on a touchscreen and have that relate the to controls for the mouse. Any Help would be appreciated. Thanks in advance. Here is what I have for my mouse controls. window.onload = function() { canvas = document.getElementById('gameCanvas'); canvasContext = canvas.getContext('2d'); var framesPerSecond = 30; setInterval(function() { moveEverything (); drawEverything(); }, 1000/framesPerSecond); canvas.addEventListener('mousedown', handleMouseClick); canvas.addEventListener('mousemove', function(evt) { var mousePos = calculateMousePos(evt); paddle1Y = mousePos.y - (PADDLE_HEIGHT/2); }); } code help.tiff
  8. I keep getting this Error: 'Phaser was used before it was defined' from running this Code: Please see attached all code and errors
  9. First of all, sorry for my english Hello! I'm trying to make a Arkanoid game on android Phaser. When the ball hits a brick, the brick disappears and the ball bounces well. Now I have two types of bricks, a normal brick, brick and TNT brick. I've implemented that when the ball touches a TNT brick, kill adjacent bricks too, but when one of those adjacent bricks is a TNT brick, it must call the same function recursively, but something does not work ... any idea? here is my function:
  10. I have developed so many games in Phaser but it is lagging and performance is too bad. I am really having no way to improve the performance. http://slopho.southindia.cloudapp.azure.com/static/games/homerun/index.html Thanks, Awadh
  11. Our game is a runner, which has portals that sends you to a different time period and place when you run into them. I've made it so when you get in a portal, the code goes from one state to the other and create the world over again with different textures. But I have this issue that the player gets super speed after the portal. Like, I can run 10000px in the matter of 2 seconds speed. I have not been able to find out why so far, but with a couple of console logs I've notice both the old state and then new state updates are both running. So thought removing the run function in the new world state would work, but didn't make a difference This is the PlayState that the game starts in after you click play. var cursors; var playState = { create: function() { console.log("Play kjørte"); var mapLen = 10000; // Velg lengden av banen (i pixler) var posX = 0; // Make game here game.physics.startSystem(Phaser.Physics.ARCADE); game.world.setBounds(0, 0, mapLen, 600); bg = game.add.sprite(mapLen/2, 300, "sky"); bg.scale.setTo(1,1); bg.anchor.setTo(0.5,0.5); platforms = game.add.group(); platforms.enableBody = true; while (true) { var ground = platforms.create(posX, 535,"ground"); ground.scale.setTo(1,1); ground.anchor.setTo(0,0) ground.body.immovable = true; posX += 150; if (posX > mapLen) { console.log("posX mer enn mapLen, avbryt laging av ground"); break; } } player = game.add.sprite(100, 500, "character"); player.anchor.setTo(0.5, 0.5); player.scale.setTo(1,1); game.camera.follow(player); game.physics.arcade.enable(player); player.body.gravity.y = 800; player.body.collideWorldBounds = true; player.animations.add("right",[0,1,2,3,4,5], 16, true); player.animations.add("jumpRight",[2], 1, true); player.animations.add("jumpLeft",[0], 1, true); player.animations.add("left",[0], 20, true); enemies = game.add.group(); enemy = game.add.sprite(8000, 505, "umbrellaGirl"); enemy.anchor.setTo(0.5, 0.5); game.physics.arcade.enable(enemy); portal = game.add.sprite(600, 500, "portal"); portal.anchor.setTo(0.5,0.5); portal.scale.setTo(0.8,0.8); game.physics.arcade.enable(portal); tBuilding = game.add.sprite(9700, 535, "targetBuilding"); tBuilding.anchor.setTo(0, 1); tBuilding.scale.setTo(0.8,0.8); game.physics.arcade.enable(tBuilding); var timer; timer = setInterval(this.run, 10); cursors = game.input.keyboard.createCursorKeys(); }, run: function() { //console.log("run kjørte"); player.body.velocity.x = 520; }, //Function to make camera follow character lockonFollow: function() { game.camera.follow(player, Phaser.Camera.FOLLOW_LOCKON); style = 'STYLE_LOCKON'; }, update: function() { // code to for example, kill, move player and jump game.physics.arcade.collide(player,platforms); game.physics.arcade.overlap(tBuilding, player, this.win, null); player.body.velocity.x = 0; if (game.physics.arcade.collide(enemy, player)) { player.kill(); game.state.start("lose"); } if (game.physics.arcade.collide(portal, player)) { this.game = null; this.state.start("ancientGreece",true, false); } //if (cursors.right.isDown) { if (player.body.touching.down){ player.animations.play("right"); } //} else if (cursors.left.isDown) { player.body.velocity.x = -400; if (player.body.touching.down){ player.animations.play("left"); } } else { player.animations.stop(); player.frame = 12; } // Jump if (cursors.up.isDown && player.body.touching.down) { player.body.velocity.y = -400; player.animations.play("jumpRight"); if (cursors.up.isDown && cursors.left.isDown) { player.animations.play("jumpLeft"); } } }, win: function() { game.state.start("win"); //"win" was an invisible sprite the player collided with to trigger the jump to win.js }, } And this is the state where the world textures become Ancient Greece textures (after you hit the portal). var cursors; var greeceState = { create: function() { console.log("Greece kjørte"); var mapLen = 10000; // Velg lengden av banen (i pixler) var posX = 0; var timer; //game.physics.startSystem(Phaser.Physics.ARCADE); //game.world.setBounds(0, 0, mapLen, 600); bg = game.add.sprite(mapLen/2, 300, "sky"); bg.scale.setTo(1,1); bg.anchor.setTo(0.5,0.5); platforms = game.add.group(); platforms.enableBody = true; while (true) { var ground = platforms.create(posX, 535,"groundSand"); ground.scale.setTo(1,1); ground.anchor.setTo(0,0) ground.body.immovable = true; posX += 150; if (posX > mapLen) { console.log("posX mer enn mapLen, avbryt laging av ground"); break; } } player = game.add.sprite(100, 500, "character"); player.anchor.setTo(0.5, 0.5); player.scale.setTo(1,1); game.camera.follow(player); game.physics.arcade.enable(player); player.body.gravity.y = 800; player.body.collideWorldBounds = true; player.animations.add("right",[0,1,2,3,4,5], 16, true); //timer = setInterval(this.run, 0.10); cursors = game.input.keyboard.createCursorKeys(); }, /* run: function() { console.log("run kjørte"); //player.body.velocity.x = 520; },*/ update: function() { //console.log("update Greece"); // code to for example, kill, move player and jump game.physics.arcade.collide(player,platforms); game.physics.arcade.overlap(tBuilding, player, this.win, null); //player.body.velocity.x = 0; if (player.body.touching.down){ player.animations.play("right"); } /* if (player.body.position.x > 9000) { game.state.start("play"); }*/ } } My apologies if I could snip the code down a little, I wasn't sure what would be relevant to show or not with the issue I have. The game looks like this before and after portal: DemolitionDavid.rar
  12. PearFiction Studios is looking for an experienced HTML5 Game Developer to work with our highly talented Montreal team. Develop the next generation of online casino games in our cool loft style office in the trendy Plateau Mont-Royal district. If you have a personality to handle responsibility and collaborate in a small team environment, we'd love to have you join PearFiction Studio's dev team. Candidates should have an interest in online, mobile, and social casino games. You will be responsible for: Participating in designing the front-end aspects of a game design including entertainment, pacing, features, and UI functionality. Designing, developing, and maintaining games in HTML5. Developing new front-end game development tools, features, or extending current ones. Creating and owning all design documentation and deliverables for our HTML5 game development toolset. Developing new casino games with our HTML5 game development toolset. Integrating the game graphics and visual effects. Integrating the game business requirements and features. Ensuring entertainment value to end users. Maintain and test HTML5 games and tools to ensure stability. Essential Experience: Technical degree or higher in computer science Minimum of three years of HTML5 (Canvas and JavaScript/Typescript) game development for mobile and desktop platforms. Experience with Pixi.js or Phaser.io JavaScript/CSS frameworks. Solid knowledge of Object Oriented Programming, MVC and other design principles. Experience working in agile and iterative environments. Familiarity with project tracking tools such as JIRA or Trello. Familiarity with Git and feature branching approach. Understanding web browser game development, with focus on mobile. A flair for game graphics programming, animations, effects, and optimization for best performance for online and mobile use. Desirable Experience: Experience developing slot machine front ends. Good understanding of casino games and real money gaming mathematics. Experience working with graphically performance-heavy web applications. Experience with client-server integrations and serialization techniques. Open to challenges of learning new languages, technologies, frameworks and approaches to development. Experience in game development projects (hobby or professional). Experience with other programming languages (C#, Java, / PHP / Python / C++, etc) is an asset. Genuinely wants to do a good job as a matter of pride in one’s work. Keen to learn and demonstrate ability. Self-motivated. Bilingual (French and English) is an asset. You can apply on our website here -> http://pearfiction.com/careers/ or via LinkedIn here -> https://www.linkedin.com/jobs/cap/view/271185313/?pathWildcard=271185313&trk=job_capjs
  13. Twitter - Subreddit - Dev Blog - Discord Hello my name is Sam, I'm also the lead artist for Super Combat Squadron. We're a small indie dev team trying to put out a lightweight browser RTS. It's been just myself and one other programmer been developing the game for about a year now but, due to unforeseen circumstances, the lead programmer has had to take a step away from the project for personal reasons. I'm still in contact with him for help in the transitionary period but I'm looking to replace him on the team with some new programmers. Currently we just completed our first internal playtest and got some good feedback from that, and the roadmap for the future was to push towards the first public demo, and then if the feedback looks good and things work out, were considering running a Kickstarter or other crowdfunding attempt to get the funding to take the game further. The ideal skill set we're looking for would include: Phaser and JavaScript (goes without saying). A previous title or some example of your work with Phaser. Possessing a strong focus on: Networking Pathfinding AI Loves and plays RTS or MOBA games a bonus. Your position in all this would be helping tackle some bugs and featured we identified and fixing some issues blocking a public demo release. We're trying to cut the fat and make it purely a bee-line to public demo release. As previously mentioned, I'd love for it to transition into a longstanding paying role through crowdfunding, worst case scenario we stop at public demo release if the interest just isn't there. If you are interested, you can contact me here, or at our email address: laxvikinggames@gmail.com
  14. https://drive.google.com/folderview?id=0Bwl58NPLObeIWEQ3YlNlTV9KNWs Here's a sharable link to the directory where my files are located. There's no node_modules, so it's necessary to install before express and socket.io. The problem is I can't create and render the balls which need to bounce all the time. The server is responsible for creating my players and balls. I did successfully the creation and movement of my players with the arrow keys and that's synchronised to all the clients. But I can't do the part with bouncing balls. It seems simple game but as far as I am new to this stuff, I can't figure it out. I provide a link to the directory of my files. The command to start the game is: node server.js. If anyone could help me, I would be very happy. Thanks in advance guys.
  15. So to get right to the point. I am having issues with my ship image/sprite and my drawn objects on screen disappearing as soon as I try and addEventListener to code. why does my code essentially break when i add the EventListener? is it not possible to add controls to image or sprite within Html canvas? Ship game code = https://codepen.io/BlaineP16/pen/VpQBZV
  16. Hey. I'm quite new to the forum and to html5 development. I have been able to link the NodeJS server to the html5 canvas and get designated numbers (atm, it will be player avatars later) But my problem is at the moment is that i can not seem to find any documentation on how to make it so that the player can click anywhere on the canvas to move to that spot. I was able to find WASD or up,down,left,right. But it is not what i want for this project. Just wondering if anyone has any experience in this, and if possible able to link over a documentation of some sort ? Thankyou in advance
  17. Hi, I'm trying to make a version of the Guess Who guessing game. I'm struggling with how to write the code so that the computer and human take alternate turns. Is there anyone that would be prepared to have a look at my code and help me. Im a student and only been coding a few years. This is my first post so apologies for any etiquette mistakes in the context of the forum.
  18. So more than a year ago, I started learning javascript and had to build something using vanilla javascript. I thought it would be cool and fun to build a game and decided to build a Mario clone. But you know, only the Mario gameplay wouldn't be enough for the project. So I decided to add a level editor where you could save your levels that you can create yourself. Found the sprites and images from google, forgot the exact source . Also I had no idea "Mario Maker" already existed. Only found out after this project was completed. Anyways, this fun little project was completed a year ago, with the help from html5gamedevs of course, and i hadn't actually shown to anybody outside my circle. So here it is, do give it a look. It's not much but it's something I am very proud of. Link to the game: http://pratishshr.github.io/mario-maker/ Link to Repo: https://github.com/pratishshr/mario-maker
  19. down votefavorite I have previous experience with Unity, but I don't like the fact that Unity compiles your game directly into APK (or IOS equivalent). It's because I want to modify the game to provide chat interface (and some other stuff) for multiplayer mode etc. So, I thot of doing it the other way - 'create an app and embed a multiplayer game within it'. Now, again this approach meant that I had to develop for android and ios seperately. But, then I came across React-Native library (mobile extension of popular React framework). Now, I have decided to create an app using React-Native (cross-platform), but now I am confused as to which game engine should I use and I think since React-Native is javascript, game engine needs to be in javascript for seamless integration. I am planning to use to embed the game in my react-native app. Can anyone suggest me any good javascript game engines that can be used along with react-native? I have done some research on Phaser and Pixi but they use WebGL for rendering and I read somewhere that doesn't have great support for WébGL or Canvas(Am I wrong?). Any help is highly appreciated
  20. I thought this would be a simple fix, but so far can't figure it out at all. I have something I call trapledges that is going to fall in the y direction when colliding with player. However, I can not get them to stop moving in the x direction if the player touch the side of them. In my code I have a commented out if test in the update function. I've tried it out both there and in the else if test where the trapledges get made. also tried out different things in the test as changing velocity.x = 0; to for example gravity = 0; or trapLedge.immovable.x = true; and so on. Still won't stop floating to the side if the player touch the sides of the ledge, instead of landing ontop of it. Added two jpgs of the game, with an arrow showing how the ledge move. A cross to show which way I want the ledge to stop move. var playState = { create: function() { for (i = 0; i < 100; i++) { var trapRandomizer = (Math.random() * 0.6) + 0.3; var randomYPos = (Math.random() * 200) + 290; var randomXSize = (Math.random() * 0.6) + 0.3; var randomYSize =(Math.random() * 0.8) + 0.6; //console.log("x: " + randomXSize + "Ran" + trapRandomizer) if (trapRandomizer > 0.4) { var ledge = platforms.create(ledgeXPos, randomYPos, "ground"); ledge.scale.setTo(randomXSize, randomYSize); ledge.body.immovable = true; } else if (trapRandomizer <= 0.4) { console.log("Trapledge"); var trapLedge = trapPlatforms.create(ledgeXPos, randomYPos, "ground"); trapLedge.scale.setTo(randomXSize, randomYSize); trapLedge.body.immovable = false; } } update: function() { /* if (game.physics.arcade.collide(trapPlatforms, player)) { trapPlatforms.body.velocity.x = 0; trapPlatforms.body.velocity.y = 300; }*/ },
  21. Hello, I have trouble finding out how to make the start menu work together with the game. in the create() function I have this: function create() { var bg = game.add.sprite(game.world.centerX, game.world.centerY, "startBg"); var image = game.add.sprite(600, 300, "startButton"); bg.anchor.set(0.5); image.anchor.set(0.5); image.inputEnabled = true text = game.add.text(250, 16, "", {fill: "#ffffff"}); image.events.onInputDown.add(listener, this); game.world.setBounds(0, 0, 1400, 600); game.stage.backgroundColor = '#182d3b'; game.physics.startSystem(Phaser.Physics.ARCADE); //game.add.sprite(0,0) //Background platforms = game.add.group(); platforms.enableBody = true; var ground = platforms.create(0,game.world.height-64,"ground"); ground.scale.setTo(1,1); ground.body.immovable = true; var ledge = platforms.create(300, 80, "ground"); ledge.body.immovable = true; var ledge2 = platforms.create(-100, 250, "ground"); ledge2.body.immovable = true; player = game.add.sprite(64, 64, "character"); ai = game.add.image(100,100, "ghost"); player.anchor.setTo(0.5, 0.5); game.camera.follow(player); game.physics.arcade.enable(player); player.body.gravity.y = 400; player.body.collideWorldBounds = true; //player.body.bounce.y = 0.2; player.animations.add("right",[11,12,13,14,15,16,17,18,20], 20, true); player.animations.add("left",[0,1,2,3,4,5,6,7,8,9], 20, true); cursors = game.input.keyboard.createCursorKeys(); } I made a large gap so it's easier to see what's the start menu and what's the game, start menu is on top. The thing is I need this image.events.onInputDown.add(listener, this); to make what's on the bottom. I made a function named listener that created the game when i clicked on the button. That worked, but only issue then was that the Update function that makes me able to move the character stopped working. as the update won't run over and over when I don't have the game code in the create function, it just run once and stops. How do I get these two to be more cooperative with each other ? so far I've only been able to either have one or the other.
  22. down votefavorite I keep having a problem with animations in my code. I try playing an animation and i always get the same message: "Uncaught TypeError: Cannot read property 'index' of undefined" and it always points to the same line of my code which is: this.player.animations.play('left'); Im not sure what is going wrong with it Heres my player sprite part of my create function: this.cursors = this.game.input.keyboard.createCursorKeys(); this.player = this.game.add.sprite(10, 10, 'player'); this.game.physics.arcade.enable(this.player); this.player.scale.setTo(.4,.4); //the camera will follow the player in the world this.game.camera.follow(this.player); this.player.animations.add('left', [0, 1, 2, 3, 4, 5, 6], 10, true, false); this.player.animations.add('right', [11, 12, 13, 14, 15, 16, 17], 10, true, false); My temporary update function: update: function() { if (this.cursors.left.isDown) { // Move to the left this.player.body.velocity.x = -150; this.player.animations.play('left'); } else if (this.cursors.right.isDown) { // Move to the right this.player.body.velocity.x = 150; this.player.animations.play('right'); } else { // Stand still this.player.animations.stop(); this.player.frame = 4; } // Allow the player to jump if they are touching the ground. if (this.cursors.up.isDown && player.body.touching.down) { this.player.body.velocity.y = -350; } }
  23. Hi, About my project: It is intended to be an up to 2 player street-fighter/tekken type of game. For a game dev class I have to create and deploy a javascript game. I would like to add the feature that the user can use their phone as a (wireless ideally) gamepad/controller and their desktop would be the monitor to show the game (this would all have to happen in real time). I don't have any back end development skills, nor do I really have the time to pick them up, so something like Websocket would be impractical (I know there is Kaazing, but I followed their documentation step by step and this caused issues very early). My question is can I do something like this in real time with Ajax? I do not know how to use Ajax just yet, but I figure I can pick this up much faster than learning backend. If not is their something where I can just copy the code entirely include it within my project (ofcourse giving the proper credit where its due) and edit the front end to apply to my game & gamepad.
  24. Hi, I'm currently in the middle of setting up the base of my game with the use of Phaser game engine but I'm having issue with the sprite colliding with the world bounds. I've used Tiling to create the backdrop and the ground etc. But I need help understanding how to define what the sprite should be colliding with. How do I collide with the ground, which is part of the whole tile. Please see the attached 2 images, the sprite falls through the game as expected. this.world.setBounds(0,0, 400,300); console.log("in Game screen"); //sprite width - 180px, height 247.5px map = this.add.tilemap('level'); map.addTilesetImage('MyTile', 'tiles'); layer = map.createLayer('Tile Layer 1'); console.log("Json and sprite loaded"); sprite = this.add.sprite(this.world.centerX, this.world.centerY, 'character'); sprite.anchor.setTo(0.5,0.5); sprite.scale.setTo(0.2, 0.2); console.log("Character Loaded"); this.physics.startSystem(Phaser.Physics.ARCADE); this.physics.enable(sprite, Phaser.Physics.ARCADE); sprite.body.gravity.y = 500; console.log("Physics added to sprite"); The above code is in the create function, I am using state management, as you can see I've added set world bounds, when adding this the sprite dissapears, I've tried numerous different dimension but I've still not come to a solution. Any help would be much appreciated. Thanks
  25. Hello! I am very excited to present you my recent game. I am sure you've already played this type of game, but I just wanted to build it myself. Basically, you have to pick two cards. If they are identical, both of them are removed from the board. The goal is to clear the board as quick as possible. Please, give it a try and leave a feedback! Play it here . Check out the source code . Have fun!