Jump to content

Search the Community

Showing results for tags 'code'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Website URL





  1. Hello everyone, firstly I am new to Phaser, but I would really like to create a typing/educational game ! (like moon-type : http://www.wordgames.com/moon-type-2.html) I have already created a background and a caracter (the simplest stuff), but I have no idea how to create moving text blocks containing a dictionnary (although I have a .txt file with a list of all existing words), progressive difficulty and a scoring system.. I know, I'm asking a lot, but i really need help, I'm more on the actual look of the game. Please help me ! Thank you in advance.
  2. There is a CHANGE PICTURE game at https://html5pcode.com/a1ychangep.htm that was designed to teach the art of coding. It uses structured programming, so it is easy to follow the logic of the design. The game is divided into small self contained pieces. It has a main program and a subprogram. The subprogram has routines that perform specific tasks when they are called by the main program. The game has links to YouTube videos that describe the operation of the main program and the subprogram routines. Once you learn how to design games like this one, you can go on to design your own games in JavaScript and/or a JS framework. This p-code lends itself to teaching coding because the source and object code are the same. The engine that created the code (source-code) is the same engine that executes the code (object code). This makes it possible to do the following options. A DATA OPTION allows you to view the game's data, while the game is running. A TRAIL OPTION allows you to execute a few instructions at a time, so you can see what each routine is doing. A REAL TIME (RT) OPTION allows you to change instruction values, while the game is running. The YouTube videos show how these options are used in the designing of the game. There are many other games written in this p-code at https://html5pcode.com
  3. As some have already pointed out in this forum there is a problem with scenes stretching ahead with a sudden cut-off at a horizon. Objects just beyond the horizon suddenly pop completely into view on the slightest forward movement. I have addressed this in my program The Forest ( https://www.myforest.uk ) by making the scene hazy (or foggy) towards the horizon, if the user switches this effect on via a check box on the page. A couple of example scenes are attached here. I have written a detailed description of how I programmed it ( https://www.grelf.net/forestdesign.html#fog ). My code is plain HTML5/JavaScript using no framework and only the standard 2D graphics context because I want my program to run on as many platforms as possible. So my documentation explains how to process images in that environment and indeed how to copy an object of type Image complete with its pixel data, which is not entirely obvious or straightforward. I hope this may be useful to others.
  4. Hi all, I have made a game where once the player reaches the end of it a new level should start but I'm not sure how to do this? I have set up multiple states such as a boot, load, game, main menu and the actual game. Is it possible to set up a state so that will switch to level 2 once the goal is reached? Here is my code for reference, any help is appreciated : (the win state takes the player to a menu that congratulates them, this is where I want the player to press a key and the next level can be loaded) //this game will have only 1 state var music; var score = 0; var scoreString = ''; var scoreText; var playState = { //initiate game settings init: function () { //adapt to screen size, fit all the game this.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL; this.scale.pageAlignHorizontally = true; this.scale.pageAlignVertically = true; this.game.physics.startSystem(Phaser.Physics.ARCADE); this.game.physics.arcade.gravity.y = 1000; this.cursors = this.game.input.keyboard.createCursorKeys(); this.game.world.setBounds(0, 0, 360, 700); this.RUNNING_SPEED = 180; this.JUMPING_SPEED = 550; }, //executed after everything is loaded create: function () { this.sfx ={ jump : this.add.audio('jump'), coin: this.game.add.audio('coin') }; music = game.add.audio('lvl1'); music.play(); //Score scoreString = 'Score : '; scoreText = game.add.text(175, 55, scoreString + score, { font: '34px Arial', fill: '#fff' }); scoreText.fixedToCamera = true; this.ground = this.add.sprite(0, 638, 'ground'); this.game.physics.arcade.enable(this.ground); this.ground.body.allowGravity = false; this.ground.body.immovable = true; //Parse the file this.levelData = JSON.parse(this.game.cache.getText('level1')); this.platforms = this.add.group(); this.platforms.enableBody = true; this.levelData.platformData.forEach(function (element) { this.platforms.create(element.x, element.y, 'platform') }, this); this.platforms.setAll('body.immovable', true); this.platforms.setAll('body.allowGravity', false); //fires this.fires = this.add.group(); this.fires.enableBody = true; var fire; this.levelData.fireData.forEach(function (element) { fire = this.fires.create(element.x, element.y, 'fire'); fire.animations.add('fire', [0, 1], 4, true); fire.play('fire'); }, this); this.fires.setAll('body.allowGravity', false); //coins this.coins = this.add.group(); this.coins.enableBody = true; var coin; this.levelData.coinData.forEach(function (element) { coin = this.coins.create(element.x, element.y, 'coin'); coin.animations.add('coin', [0, 1, 2, 3], 8, true); coin.play('coin'); }, this); this.coins.setAll('body.allowGravity', false); //goal this.goal = this.add.sprite(this.levelData.goal.x, this.levelData.goal.y, 'goal'); this.game.physics.arcade.enable(this.goal); this.goal.body.allowGravity = false; //create player this.player = this.add.sprite(10, 545, 'player', 3); this.player.anchor.setTo(0.5); this.player.animations.add('walking', [0, 1, 2, 1], 6, true); this.game.physics.arcade.enable(this.player); this.player.body.collideWorldBounds = true; this.game.camera.follow(this.player); this.barrels = this.add.group(); this.barrels.enableBody = true; this.createBarrel(); this.barrelCreator = this.game.time.events.loop(Phaser.Timer.SECOND * this.levelData.barrelFrequency, this.createBarrel, this); }, update: function () { scoreText.bringToTop(); this.game.physics.arcade.collide(this.player, this.ground); this.game.physics.arcade.collide(this.player, this.platforms); this.game.physics.arcade.collide(this.barrels, this.ground); this.game.physics.arcade.collide(this.barrels, this.platforms); this.game.physics.arcade.overlap(this.player, this.coins, this.collectCoin,null,this); this.game.physics.arcade.overlap(this.player, this.fires, this.killPlayer); this.game.physics.arcade.overlap(this.player, this.barrels, this.killPlayer); this.game.physics.arcade.overlap(this.player, this.goal, this.win); this.player.body.velocity.x = 0; if (this.cursors.left.isDown) { this.player.body.velocity.x = -this.RUNNING_SPEED; this.player.scale.setTo(1, 1); this.player.play('walking'); } else if (this.cursors.right.isDown) { this.player.body.velocity.x = this.RUNNING_SPEED; this.player.scale.setTo(-1, 1); this.player.play('walking') } else { this.player.animations.stop(); this.player.frame = 3; } if (this.cursors.up.isDown && this.player.body.touching.down) { this.sfx.jump.play(); this.player.body.velocity.y = -this.JUMPING_SPEED; } this.barrels.forEach(function (element) { if (element.x < 10 && element.y > 600) { element.kill(); } }) }, collectCoin:function(player, coin){ // Increase the score score += 20; scoreText.text = scoreString + score; this.sfx.coin.play(); coin.kill(); }, killPlayer: function (player, fire) { score = 0; music.stop(); game.state.start('die'); }, win: function (player, goal) { game.state.start('won'); music.stop(); }, createBarrel: function () { //Give me the first dead sprite var barrel = this.barrels.getFirstExists(false); if (!barrel) { barrel = this.barrels.create(0, 0, 'barrel'); } barrel.body.collideWorldBounds = true; barrel.body.bounce.set(1, 0); barrel.reset(this.levelData.goal.x, this.levelData.goal.y); barrel.body.velocity.x = this.levelData.barrelSpeed; } };
  5. Hi all, I am trying to create a platformer which allows the player to wall jump however I'm struggling to figure it out. I am using the player movement code from the example here: https://phaser.io/examples/v2/games/starstruck. I done some looking around and only found this example which moves the player automatically which I don't want and the code is more suited to that type of mechanic: https://www.emanueleferonato.com/2018/04/28/super-mario-who-html5-platformer-prototype-inspired-by-ios-hit-yeah-bunny-thanks-to-phaser-and-arcade-physics-updated-to-phaser-3-6-0/ Any suggestions on how I could tackle the issue of finding a wall, attaching the player to it and jump to another wall while using the controls of the first example would be appreciated, Thanks
  6. i have issue in 3d analog clock i have export 3d watch from blender everything done just need to work on clock function my also fucntion is also done but its not working like clock please check the video and help me out and i have this code for clock function all Object piviot point is center but clock function not working perfectly please Check and help me out please scene.registerBeforeRender(function () { var date = new Date(); var hour = date.getHours() % 12; var minute = date.getMinutes() ; var second = date.getSeconds() ; hand_sec.rotation.y = (second/60.)*minute.*Math.PI/180.; hand_min.rotation.y = (minute/60.)*360.*Math.PI/180.; hand_hour.rotation.y = (hour/12.)*360.*Math.PI/180.; }); // this is code i have add but not working 0125.webm
  7. Hi friends, I don't understand the following code . please help me this.bullets = []; this.nextShotAt = 0; this.shotDelay = 100; fire: function() { if (this.nextShotAt > this.time.now) { return; } this.nextShotAt = this.time.now + this.shotDelay; var bullet = this.add.sprite(this.player.x, this.player.y - 20, 'bullet'); bullet.anchor.setTo(0.5, 0.5) ; this.physics.enable(bullet, Phaser.Physics.ARCADE); bullet.body.velocity.y = -500; this.bullets.push(bullet); }
  8. This is something I put together this afternoon for my students to play with. Live demo.
  9. Hi! can anyone tell me how to put some value on my "score" i already use if (playState.score <= 3){ game.add.text(20, 20, "practice more",{font: '50px Sports World', fill: '#b7e2fe'}); but it doenst work var winState = { create: function () { game.add.tileSprite( 0, 0, 1000, 490, "background3") if (playState.score >= loadState.hiscore) { loadState.hiscore = playState.score; } var hiscoreLabel = game.add.text(473, 155, loadState.hiscore, {font: '50px Sports World', fill: '#fdf59e'}); var scoreLabel = game.add.text(473, 243, playState.score, {font: '50px Sports World', fill: '#b7e2fe'});; var spaceKey = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); spaceKey.onDown.addOnce (this.restart, this); var escKey = game.input.keyboard.addKey(Phaser.Keyboard.ESC) escKey.onDown.addOnce (this.menus, this); }, restart: function (){ game.state.start('play'); }, menus: function (){ game.state.start('menu'); }, } thats my code pls help me thank you!
  10. Posted 2 hours ago Is there a way to create sprite from multiple files ? Like creating a sprite : Knight in 'knight.js' and creating his movement in 'movement.js' is this possible : // knight.js import Phaser from 'phaser' import Movement from './movement' export default class extends Phaser.Sprite { constructor ({ game, x, y, asset }) { super(game, x, y, asset) } movement(){ // Here Ill call Movement } } // movement.js import Phaser from 'phaser' export default class extends Phaser.Sprite { // Here ill make a function that will move the sprite // and start the animation }
  11. Is there a way to create sprite from multiple files ? Like creating a sprite : Knight in 'knight.js' and creating his movement in 'movement.js' is this possible : // knight.js import Phaser from 'phaser' import Movement from './movement' export default class extends Phaser.Sprite { constructor ({ game, x, y, asset }) { super(game, x, y, asset) } movement(){ // Here Ill call Movement } } // movement.js import Phaser from 'phaser' export default class extends Phaser.Sprite { // Here ill make a function that will move the sprite // and start the animation }
  12. VGT

    bubble shooting

    Hi, Anybody here that can sell a bubble shooting game developed in phaser?
  13. stauzs


    Hello, It has been a while since our last post here! MyGameBuilder was formed through a creative joining between the first versions of MyGameBuilder and MightyEditor. The main purpose of MyGameBuilder is to teach users game development in a collaborative manner, where more experienced developers can help others. If you are completely new to the game development you can: Play games - we have some nice user made games! Play with the actormap engine, which doesn't require any coding experience to make a game. Fork game and alter it to make it your own. Start taking guided lessons to learn programming basics, and even create a Phaser based game on your own, If you get stuck doing any of these things, there is usually somebody online who will be glad to help. After finishing the basic tutorials, there are some game related challenges to start practicing with. Main parts of MyGameBuilder: Graphic Editor - easily create your own pixel art, or import graphics here Actor and ActorMap - are part of the ActorMap engine, which allows you to build game without coding. It's as simple as assigning graphics to an actor, defining the Actor's behavior, and placing Actors on the ActorMaps to interact. Also, if you have used an earlier version of MyGameBuilder, you can import your game into the new version. The Map Editor allows you to build maps for your games. It uses the TileMap format so you can convert your graphics into tiles, and put them on the map.You can also import TileMap in JSON format or load TileMap directly into a Phaser game. The Sound Editor allows users to quickly create sound effects, like a coin pickup or a melee hit. There is also a music editor, which you can use to create background music for your game. Currently you can generate metal or 8 bit music, or import your own mp3 file. With the Code Editor, there is no limit to what you can create. The Code editor has a beginner-friendly code mentor which will show information about keywords used in the programming. Also it has JSdoc support so users can describe functions with JSdoc comments, the code mentor will pick those up and show as help info. Code Editor supports full ES6 JavaScript syntax and will automatically pick-up imported modules and share their info with the code mentor. The latest addition is our Hour of Code project: this is a gaming tutorial used in a worldwide classroom project that has users of any experience level program a dwarf character to complete game goals with basic JavaScript commands. Check it out here: https://v2.mygamebuilder.com/hour-of-code And all of this is completely free! It would be really nice if you could share your game developing experience when you were a beginner: How did you begin? Where did you get all the necessary information to build a game?
  14. Hello World, I'm a pixel Artist and Game Designer sharing my work for the #gamedev sake. I just released a Free Public 2D Platform Pixel Art Pack for everyone. Check it out I even made an online Demo made with Phaser so you can see it in action: http://pixelgameart.org/demos/sunny-land/ Download this Pack at my site where I will be posting each month a Public Pixel Art Pack (code included): http://pixelgameart.org/web/portfolio/sunny-land/ Cheers and happy #gamedev
  15. 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() { }
  16. Hi i would like to share with you my last game i made with phaser framework it is cross platform mobile ready game the source code is available on codecanyon codecanyon : https://goo.gl/H2nvea play the game : https://goo.gl/MojVRz video : https://goo.gl/gnl2fq
  17. This is hastily thrown together code that I created as a solution for an idea that I have. I have texture gen data in objects and I wanted to merge various layers together. Reason being is if I create a number of various objects I wanted them to be placed on buttons later on. I plan on making a some code to replace various parts of the textures so that I can on the fly generate generated textures. This is handy for button and things of that nature which is why I created it. I decided to throw it out there in case anyone needed something like this or wanted to improve on the code. Also here is a working example of it on jsfiddle. Screenshot var game = new Phaser.Game(800, 600, Phaser.CANVAS, '', { create: create }); // taken from my code and striped out useless parts var gameScale = 2 var sprite = (function() { 'use strict'; var sprite = { creature: {}, misc: {}, object: {}, structure: {}, tile: {}, vehicle: {}, }; sprite.misc.buttonBackground = { size: [16, 16], data: [ '0000000000000000', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0999999999999990', '0000000000000000' ], }; sprite.object.table = { size: [6, 3], thumbOffset: [5, 8], data: [ '666666', '.6..6.', '.6..6.' ], thumbData: [ '666666', '.6..6.', '.6..6.' ], }; sprite.mergeData = function mergeData(bgData, fgData, xOffset, yOffset) { var bgDimensions = sprite.getDimensions(bgData); var fgDimensions = sprite.getDimensions(fgData); var size = sprite.getMaxDimensions(bgDimensions, fgDimensions); var newData = []; _.times(size[1], function(y) { var row = ''; _.times(size[0], function(x) { var s = '.'; if (yOffset || xOffset) { if (y >= yOffset || x >= xOffset) { if (fgData[y - yOffset] && fgData[y - yOffset][x - xOffset]) { s = fgData[y - yOffset][x - xOffset]; } } } else { if (fgData[y] && fgData[y][x]) { s = fgData[y][x]; } } if (s == '.' && bgData[y] && bgData[y][x]) { s = bgData[y][x]; } row += s; }); newData.push(row); }); return newData; }; sprite.makeTexture = function makeTexture(name, data) { console.info('Loading sprite `%s`.', name); return game.create.texture( name, data, gameScale, gameScale ); }; sprite.getDimensions = function getDimensions(spriteData) { if (_.isArray(spriteData)) { var y = spriteData.length; var x = 0; var count = 0; _.each(spriteData, function (row) { if (row.length > x) x = row.length; }); count = x * y; return [x, y, count]; } return false; }; sprite.getMaxDimensions = function getMaxDimensions(a, b) { if (!_.isArray(a) || !_.isArray(b)) return false; var x = Math.max(a[0], b[0]); var y = Math.max(a[1], b[1]); return [x, y]; }; return sprite; })(); function create() { game.stage.backgroundColor = '#2d2d2d'; // manually placed variables from itterated code; var groupKey = 'object'; var structKey = 'table'; var col = 0; var row = 0; var name = groupKey + '_' + structKey; var baseLeft = 100 + ((col * 16) * gameScale) + 2; var baseTop = 100 + ((row * 16) * gameScale) + 2; var bgData = sprite.misc.buttonBackground.data; var fg =sprite[groupKey][structKey]; var fgData = fg.thumbData; var newData; if (_.isUndefined(fg.thumbOffset)) { newData = sprite.mergeData(bgData, fgData); } else { newData = sprite.mergeData(bgData, fgData, fg.thumbOffset[0], fg.thumbOffset[1]); } var btnName = 'btn_' + name; var newTexture = sprite.makeTexture(btnName, newData); var objButton = game.add.sprite( baseLeft, baseTop, btnName); objButton.name = name; objButton.inputEnabled = true; objButton.input.useHandCursor = true; }
  18. Hello all, I'm looking to sell the source code to several of my GameMaker-studio based mobile-web HTML5 games. I won't be posting them publicly, but if you PM me I will answer promptly with the games, prices, and any other information you might need. Thank you
  19. Hello friends. I've a security question. I've done two mini-games for my company. I really enjoyed the chance of using Phaser in my work and not for fun, as I usally do. My boss liked it too, so good news. But he is concern because everybody are able to see the code with the elements inspector. My question is if there's some easy way to hide or protect the code from visitors, in order to avoid that our competititors steal the code for their own pages. Any advice? Thanks a lot!
  20. How would you go about adding physics int babylon.js? I followed a youtube series by Kris Occhipinti on babylon and got it working but what if you want it to work with imported objects? My code: <script> var canvas = document.getElementById("renderCanvas"); var engine = new BABYLON.Engine(canvas, true); var scene = new BABYLON.Scene(engine); //Physics!!! scene.enablePhysics(); scene.setGravity(new BABYLON.Vector3(0, -10, 0)); var assetsManager = new BABYLON.AssetsManager(scene); var meshTask = assetsManager.addMeshTask("skull task", "", "./", "models/untitled.babylon"); meshTask.setPhysicsState({ impostor: BABYLON.PhysicsEngine.BoxImpostor, mass: 0, friction: 0.5, restitution: 1 }); meshTask.onSuccess = function (task) { task.loadedMeshes[0].position = new BABYLON.Vector3(0, 0, 0); } var Camera = new BABYLON.ArcRotateCamera("Camera", 1, 1, 100, new BABYLON.Vector3(0, 0, 0), scene); scene.activeCamera.attachControl(canvas); assetsManager.onFinish = function (tasks) { engine.runRenderLoop(function () { scene.render(); }); }; assetsManager.load(); window.addEventListener("resize", function () { engine.resize(); }); </script>
  21. There is only one of the coins falling and I don't understand why that is. I looked at the code but I can't seem to figure it out.You will have to reload the page if you miss it ( it is the 5th coin from the left). http://phaser.io/examples/v2/tilemaps/create-from-objects
  22. Hi guys! I'm really pissed about my code. I reviewed so many times and I can't find the problem that is causing this bug. So, as you can see in these screenshots below, after a while running the game, the platforms starts acting strange. In the interval of platform 2 and 3, when the movement is from left to right, these platforms overlaps and when the movement is from right to left, the distance between then increase. The first screenshot is about the game start, so the problem didn't occured, yet. In the second screenshot, shows the bug in action and it get worse after a while running the game. well... the objective of these platforms is to do a cyclic movement from left to right and vice-versa, in an infinite loop, where the player will jumps on it catching items and killing enemies. So, I start my code creating the platforms in the Trail class, that holds 4 platforms per row. // trail group of platforms this._trail = this.game.add.group(); // fill the group with platforms for (var i = 0; i < total; i++) { var platform = new MovablePlatform(this.game, sprite, direction, speed); var initX; var finalX; switch (direction) { // move to left case 0: if (i === 0) { initX = this.game.width + platform.width; finalX = - platform.width * total - PLATFORM_GAP; } else { var lastPlatform = this._trail.getAt(i - 1); initX = lastPlatform.initPos.x + lastPlatform.width + PLATFORM_GAP; finalX = lastPlatform.finalPos.x + lastPlatform.width + PLATFORM_GAP; } break; // move to right case 1: if (i === 0) { initX = - platform.width; finalX = this.game.width + platform.width * total + PLATFORM_GAP; } else { var lastPlatform = this._trail.getAt(i - 1); initX = lastPlatform.initPos.x - lastPlatform.width - PLATFORM_GAP; finalX = lastPlatform.finalPos.x - lastPlatform.width - PLATFORM_GAP; } break; } platform.createPath(initX, posY, finalX, posY); this._trail.add(platform); } And in the class MovablePlatform I created the method "move", that starts the platform movement, applying the velocity in x-axis. The update method verify if the x position is equal or grater/lesser than the final position and reset the position, to start the movement again. MovablePlatform.prototype.update = function () { switch (this._direction) { // check negative bounds outside the screen case 0: if (this.x <= this.finalPos.x) { this.reset(); } break; // check positive bounds outside the screen case 1: if (this.x >= this.finalPos.x) { this.reset(); } break; } }; MovablePlatform.prototype.move = function () { switch (this._direction) { // move to left case 0: this.body.velocity.x = -this._speed; break; // move to right case 1: this.body.velocity.x = this._speed; break; } }; That is it! Does anybody know why it happen? And if anyone knows a better method to do cyclic movement, I would like to know and appreciate the sharing! Thanks!
  23. Hi. I have a problem with multiple levels (game states). What can I do when, I don't want to write the same piece of code in each level over and over? I've tried to create a function in separate js file which e.g. will set player sprite, gravity, animations or will create necessary variables etc. And I failed this. Everything what I have got are errors.
  24. Hello! I have started a sellfy in which I will post source code of project that is documented and a great way to learn Phaser, also a great way to support me too! https://sellfy.com/SiLD11 Thank you!
  25. Been coding some games in javascript for about 3 months. So far: an angry birds ugly clone (really crappy, using box2dWeb), a shooter like sonic wings (way smaller, though), and some simple games like pong, breakout and a simple endless runner with no sprites, just using rect and arc to draw. I've been experimenting with ways to plan the code, and realized that I output more and finish things quicker if I don't actually plan anything at all: just sit there and code, and deal with problems as they occur. Do you guys do that way too? I guess maybe because all games I did were small ones this works. Maybe for bigger ones it will be a mess, even though the code I write is usually clean. How do you guys go on about planning all the functions, objects and interactions amongst your games?
  • Create New...