Jump to content

Search the Community

Showing results for tags 'phaser help scrolling sprites'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • 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

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. Hi Phaser forum members! Since this is my first post I'll make a quick introduction. I'm well versed in javascript and now I'm working on tackling my first game project with phaser and cocoon js. I've just set up phaser and have started prototyping my first game, an autorunner. My problem is this: I'm trying to add two boards right next to each other as they scroll across the screen. I start by adding a board offscreen. When that board has fully come on screen, I want to add another board right next to it off screen. My code looks like this //Add any global vars here.var targetBoard;var board;var timer = 0;FenceManager = function (game) { this.addBoard = true; this.game = game; Phaser.Sprite.call(this, game, 0, 0); console.log("running"); game.add.existing(this); board = new Board(game, game.width, game.height/2); game.add.existing(board); targetBoard = board; this.addBoard = function(prevBoard){ board1 = new Board(game, prevBoard, game.height/2); game.add.existing(board1); }};FenceManager.prototype = Object.create(Phaser.Sprite.prototype);FenceManager.prototype.constructor = FenceManager;FenceManager.prototype.update = function() { if(targetBoard.x + targetBoard.width <= game.width) { board1 = new Board(game, targetBoard.x+targetBoard.width, game.height/2); game.add.existing(board1); targetBoard = board1; }};var timer = 0;The Board object I'm adding is a sprite object that I extended here, all it does is set the velocity of the board // Here is a custom game objectBoard = function (game, x, y) { Phaser.Sprite.call(this, game, x, y, 'fenceCenter'); game.physics.enable(this,Phaser.Physics.ARCADE) this.body.velocity.x = -200; this.hasBeenAdded = false;};Board.prototype = Object.create(Phaser.Sprite.prototype);Board.prototype.constructor = Board;Board.prototype.update = function() { /* if(this.x <= game.width - this.width && !this.hasBeenAdded) { this.hasBeenAdded = true; this.fenceManager.addBoard = true; } */};The boards almost line up but are usually always off a pixel or two depending on the velocity. Attached below is a screenshot of what it looks like If anyone could help it would be greatly appreciated! I banged my head against the wall trying to get the boards to line up but I couldn't get it working.
×
×
  • Create New...