Search the Community

Showing results for tags 'background'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


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

Found 45 results

  1. Background Selector

    Hi all I've been trying to make a scroll image finder Where the user would scroll through a set of images and choose one. I was wonder how i could do this in phaser
  2. I have this game with a salmon background color. I can set the background to the proper color into the create function with: game.stage.backgroundColor = '#f3cca3'; The problem is that it takes a little while preloading the images and sounds and so it stays black in the meantime. I tried: var game = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.CANVAS, 'meems_house', { preload: preload, create: create }); game.stage.backgroundColor = '#f3cca3'; But then it says 'Cannot set property 'backgroundColor' of null' indicating that it didn't find 'game' — however it doesn't make any sense because 'game' is NOT null as it was created one line above... PS: The only thing I can imagine is that although object 'game' was declared it was not properly instantiated yet because it's gonna happen into the create function — but this is still weird to me. Anyway I would like to know if there is a way to set the canvas background color before the create function... Thanks!
  3. Hi all, I was trying to optimize our mobile experience, so instead of including a big background image in on of my texture sheets, I've made it into a simple .jpg image and set that as a CSS background with the following properties : body { margin: 0; padding: 0; background: url('assets/images/bg.jpg') no-repeat center center fixed; background-position: 50% 100%; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover; height: 100%; overflow: hidden; } On iOS and desktop Chrome + Safari, the behaviour is as expected, but on Android Chrome, it seems to affect my Canvas size, as if the canvas was bigger than the whole screen. The weird thing is as I hit refresh multiple times, the behaviour changes from having correct canvas size to incorrect. If there is no way around that, I'm just going to go back to my background being part of my texture atlases. Thanks for any input! Edit: after playing around a bit with how I create Phaser's game object, I just realized that Android does not treat screen density like iOS does (ie. Retina vs xhdpi etc), so I basically added code so that on Android width and height are "100%" with a scale mode of RESIZE, and on iOS width and height are window.innerWidth * window.devicePixelRatio with a scale mode of SHOW_ALL and everything seems to behave correctly now. Let me know if you see any issues with my approach, thanks!
  4. sending to back not working?

    I have a background image that takes up my whole window. It renders in front of my text, even when all in a group, and using sendToBack isn't working. It renders behind my graphics, which is good, but why isn't my text coming forward as well? create: function(){ this.titles =; //background,0, 'bg'); this.titles.add(;; //logo this.logo =, -200, 'logo'); this.logo.anchor.setTo(0.5); this.titles.add(this.logo); //text for instructions = {font: "26px Arial", fill: '#fff'}; this.text1,, 'Instructions: blah de blah de blah.',, this.titles); this.text1.anchor.setTo(0.5); this.titles.add(this.text1); //start button,,'start',this.startGame,this,1,0,1); this.startbtn.anchor.set(0.5); this.titles.add(this.startbtn); }
  5. Help with scales?

    So I've been following along with a tutorial to make my first game in Phaser. I'm trying to understand everything the tutorial is saying, but I can't find an explanation for everything. For example, the background image being used in the game is 400x32. However, the tutorial says the following: // Scale it to fit the width of the game (the original sprite is 400x32 in size) ground.scale.setTo(2, 2); My question is this; if the original size is 400x32, then why does seting the ground scale to 2, 2 work out? The game made in the tutorial works, and the ground does fit the width, but wouldn't the ground have to be 400x2 or something like that to have the proper width? I'll attach the tutorial file to this post so you can see the whole thing. I attached the tutorial text itself, and "part9.html" is the completed code that came with the tutorial. I don't think my code is needed to answer my question because I'm just following along with the tutorial, and it's just a less completed version of part9.html. I also have one more question regarding the ground. The tutorial says this: // Here we create the ground. var ground = platforms.create(0, - 64, 'ground'); Again, if the size is 400x32, then why does -64 work to put the ground at the bottom? What does 64 do in this code? I guess I'm just looking for an explanation of why the code I posted works. I understand the rest of the code in the file, just these 2 lines are what confuse me the most. I'd greatly appreciate any help I can get, thanks! Edit: I realize now that in the first line of code I pasted here, the 400x32 is talking about the size of the platform itself, not the whole background. Still, how does the (2, 2) scale a 400x32 platform to fit the whole background? tutorial.html part9.html
  6. Hi all, for example we have 3 type of images(400x600px) for background. and we have the game size (400x600px too). how to better realize the progressively selecting 3 types (or more) of images with auto-scrolling? 1) create 2 images and move their Y-coordinate, then just switching the nameFrame. I think that this decision will slow down the performance of the game. to move so big images. 2) create via tileSprite object and move tilePosition.y, create the bitmap of back1 + back2, scroll them. then re-create the bitmap... and etc. any ideas?
  7. Hello, I'm new to the Phaser framework and I'm trying to have a single backgound and logo througout all the states in a phaser game. I add the background image in the very first state but when I start the next state using:"State2"); the background image disappears. Do I have to load the background image in every state? Thanks
  8. Adding gradient background

    Hi, I'm having issues trying to add a gradient to the background of my platformer game. I have worked out that, due to the WebGL renderer, the images used need to be either square or width = height x 2. My issue is that the stage is width = height x 4. I thought I could just add two image layers and align them next to each other with the "repeat" property set to "no-repeat" but this does not work. Even though the offset for my second level is correct the image is getting repeated over the first image. Is there a better solution. What I need is a gradient that goes from dark to light top to bottom but also changes from left to right so that it feels that night is falling as you walk through the level. I hope this makes sense, you help would be much appreciated. Thanks Dave
  9. Help with background image

    Hey I'm having a problem and I hope you guys can help me. I'm trying to put a background image for my stage. The stage is already done the way I want, but the background image is not showing up. This is the code: window.onload = function() { var game = new Phaser.Game(1200, 600, Phaser.AUTO, 'game-area', { preload: preload, create: create, update: update, render: render }); var manager = null; var emitter = null; var circle = null; function preload() { game.forceSingleUpdate = true; game.load.image('background', 'bg.jpg'); game.load.image('uni', 'uni2.png'); game.load.path = 'assets/particles/'; game.load.images(['red', 'blue', 'yellow', 'white']); } var uni; var background; function create() { manager =; background = game.add.tileSprite(0, 0, 1200, 600, 'background'); var data = { lifespan: 6000, image: ['red', 'blue', 'yellow', 'white'], vy: { min: 1, max: 2 }, blendMode: 'ADD', scale: { initial: 0, value: 0.3, control: [ { x: 0, y: 1 }, { x: 1, y: 0 } ] } }; manager.addData('basic', data); emitter = manager.createEmitter(); /*var well1 = emitter.createGravityWell(200, 100, -0.5);*/ var well2 = emitter.createGravityWell(900, 50, 10, 200); var well2 = emitter.createGravityWell(850, 400, 20, 200); circle = manager.createCircleZone(8); emitter.addToWorld(); emitter.emit('basic', 0, 0, { zone: circle, total: 6, repeat: -1, frequency: 20 }); // To make the sprite move we need to enable Arcade Physics game.physics.startSystem(Phaser.Physics.ARCADE); uni = game.add.sprite(,, 'uni'); uni.anchor.set(0.5); } function update() { circle.shape.x = game.input.x; circle.shape.y = game.input.y; uni.x = game.input.x-30; uni.y = game.input.y - 50; } }; I really do not know why this line of code "background = game.add.tileSprite (0, 0, 1200, 600, 'background') " is "breaking" the canvas. Not even the animation is running. Sorry for my bad english. Not my first language. Thanks
  10. Hello everyone! Is there a way to change canvas size to preloaded background image size? And only after that do the code at create function. Thanks.
  11. I am running my game as "transparent", directly in the body element, and setting a repeated tile background in the body through CSS. If I enter fullscreen mode through a button click that triggers, the background tiling disappears and there's just a black background. If I enter fullscreen mode "manually" (by physically pressing F11), the background remains. What am I missing about how to start fullscreen mode? How can I preserve the background?
  12. I am having trouble figuring out how to do a scrolling background using multiple background images. These images are not overlayed to create a parallax effect, but rather next to each other to create a changing background scene. My background is created using 20 different images who's order must be dynamically changed as the background scrolls. So I can start with A,B,C showing and as it moves I need to remove A and add D after C...and so forth. I tried using tweens, but it is almost impossible to to place the next image at the correct starting position without gaps forming between the images. I have tried using a tileSprite, but I can only figure out how to add a single texture to the tileSprite. I tried creating a texture dynamically using bitMapData and copying a image sequences to the texture and then scrolling the texture using a tileSprite, but that does not allow me to dynamically change the next image that should appear based on whatever is happening in the game. Also I have read that tileSprites have performance issues on mobile. In another post on this form Rich suggests doing the following: I have tried this by adding my stating ABC images next to each other in a group and then moving the group, but all that happens is that the group moves off the screen after a while. Could someone please explain to me how to implement what Rich suggests above? Or any other method to achieve my desired result?
  13. I'm developing point&click quest adventure (something like Machinarium) I have a background, for example, like on the bkg1.ipg I want to define some zone where the character can move. Example on bkg1-marked.jpg. Reaching the end of the red zone the character should stop. Also, it would be great to have ability to make it with some pathfinding like f.e. there are stairs on the background image and the character stays somewhere else on the "first floor". Player clicks on top of the stairs and the character goes there, according to the zone where he can walk Does Phaser have any tools for that?
  14. Hello, all. I'm wondering if anyone knows a way of placing a large image in the background of a game made using the Phaser Isometric Plugin. Is sorting within groups the only way of layering objects? Is it possible to place an object behind all others, regardless of position? This may be something of a silly newbie question. I've been using the plugin for about three days. Thank you very much for reading and considering. Any input is very much appreciated. -JStan
  15. Hi All, Is it possible to draw something after babylon clear canvas and right before it draws all the 3d components? If not, is it possible to prerender the image use for the code following, instead of start loading it when I call this script? var url = ""; var background = new BABYLON.Layer("back", url, scene); background.isBackground = true; Thanks.
  16. Hey, It seems using CACHESTRATEGY_CANVAS changes the background color of the canvas: without caching on the left:
  17. Button Background Color

    How to set background color and text for a button in Phaser? Or it is possible only using Sprites?
  18. How can I create a PIXI.Container with a transparent background which I can render on top of my main stage container? My goal is it to have 4 layers which contain PIXI.Sprites and PIXI.Texts: layer 1 should be rendered beneath the player layer 2 should be rendered above layer 1 layer 3 should be rendered above the player and above layer 1 and layer 2 layer 4 should be rendered above everything else for debug information In case I can cannot use multiple PIXI.Container then how else could I achieve this effect?
  19. Hi , I start a few weeks ago with Phaser and I have some problems that I couldn't find a solution yet so what I actually want to do is this: I want where a "load bar" is loaded to se a background image instead of solid color so my code is : /* BOOT SIDE */ var boot = function ( game ) { }; boot.prototype = { init : function () { } , preload : function () { = "#6cb2f3"; ( 'loader' , 'sprites/images/loader.png' ); } , create : function () { // Set background for our game ( "Preload" ); } }; /* PRELOAD SIDE */ var preload = function ( game ) { }; preload.prototype = { preload : function () { // the other assets ... ( 'background' , 'sprites/images/background.png' ); this.preloadBar = this.add.sprite( 150, 550, 'loader'); this.load.setPreloadSprite(this.preloadBar); } , create : function () { console.log ( "Load the preloader .." ); ( "GameStart" ); } }; The loader image is working same as background color but instead of a background color i want to load an a image . thanks .
  20. Hello, I've been trying to create a nice background with many dots flying around which if close enough to another dot then "links" to that dot. Roughly like the picture attached. I have been able to create some dots flying around but I can't get the line stuff to work. I tried with Phaser.Line and then updating it with line.fromSprite(point1,point2,false) but when doing it with multiple lines, I'm not sure how to keep track of all the lines. Does anyone have any ideas of how to do this?
  21. Hi There, I am trying to create a sandbox world with tile sprite, where as the player moves left to right and top to bottom, and they only ever see the image once and it doesn't actually tile. I've read that you can do this by setting the world bounds and tile sprite size to the actual size of the image. When I do this it seems to work okay, however the moment I position the player it causes the background to offset in a way where I am seeing the tile repeat, which is not the desired effect. I was hoping somebody on the forum might have some insight or experience with how to do this? I've attached my code to show the problem I'm running into. Thanks for any help with this. 'use strict'; function Level() {} Level.prototype = { init: function() { this.drone = null; this.background = null; this.cursors = null; this.balloon = null; }, // preload: function () {}, initPhysics: function() {, 0, 3072, 1536);; // = 0.8; = 0.3;; = 100; = 0.8; }, addBackground: function() { this.background =, 0, 3072, 1536, 'background'); this.background.fixedToCamera = true; this.background.tilePosition.x = 0; this.background.tilePosition.y = 0; }, addDrone: function() { this.drone =, 0, 'drone'); this.drone.animations.add('fly');'fly', 30, true); }, addContactMaterials: function() { this.spriteMaterial ='spriteMaterial', this.drone.body); this.worldMaterial ='worldMaterial');, true, true, true, true); this.contactMaterial =, this.worldMaterial); this.contactMaterial.friction = 0.0; // Friction to use in the contact of these two materials. this.contactMaterial.restitution = 1.0; // Restitution (i.e. how bouncy it is!) to use in the contact of these two materials. this.contactMaterial.stiffness = 1e7; // Stiffness of the resulting ContactEquation that this ContactMaterial generate. this.contactMaterial.relaxation = 3; // Relaxation of the resulting ContactEquation that this ContactMaterial generate. this.contactMaterial.frictionStiffness = 1e7; // Stiffness of the resulting FrictionEquation that this ContactMaterial generate. this.contactMaterial.frictionRelaxation = 3; // Relaxation of the resulting FrictionEquation that this ContactMaterial generate. this.contactMaterial.surfaceVelocity = 0; // Will add surface velocity to this material. If bodyA rests on top if bodyB, and the surface velocity is positive, bodyA will slide to the right. }, enablePhysics: function() {; this.drone.body.clearShapes(); this.drone.body.loadPolygon('dronePhysics', 'drone'); this.drone.body.damping = 0.5; // this.drone.body.x = 100; // this.drone.body.y = 1400; // this.drone.anchor.setTo(0.5, 1.0); }, initCamera: function() {; }, addControls: function() { this.cursors =; }, create: function() { this.initPhysics(); this.addBackground(); this.addDrone(); this.enablePhysics(); this.addContactMaterials(); this.initCamera(); this.addControls(); }, moveHorizontally: function() { if (this.cursors.left.isDown) { this.drone.body.rotateLeft(100); } else if (this.cursors.right.isDown) { this.drone.body.rotateRight(100); } else { this.drone.body.setZeroRotation(); } }, moveVertically: function() { if (this.cursors.up.isDown) { this.drone.body.thrust(400); } else if (this.cursors.down.isDown) { this.drone.body.reverse(400); } }, moveBackground: function() { if (! { this.background.tilePosition.x -= (this.drone.body.velocity.x *; } if (! { this.background.tilePosition.y -= (this.drone.body.velocity.y *; } }, update: function() { this.moveHorizontally(); this.moveVertically(); this.moveBackground(); } // , // paused: function () {}, // render: function () {}, // shutdown: function () {} }; module.exports = Level;
  22. Hi, I have an application that uses BabylonJS: As you see, i have a skybox with 3D backgrounds and a ArcRotateCamera in my scene. This works well, but i need a second behavior in my scene. When the user select an option, i need to rotate only the object and the plane in my scene, but not the background. It is because i need a option to user add your own backgorund image, but users will upload only one texture, and the background skybox must be fixed to see only one face. Is it possible? How to make it? Thanks by the support!
  23. Hi everyone! I'm trying to make a top down racing game, but I can't find a way to make a proper scrolling background. Every example I find is about tiles but my background is not something I can repeat horizontally. The background image is basically the track, so I need that image to be 100% width and repeated vertically, with an infinite vertical scroll. Can you please give me a hint? Thanks in advance! Damian
  24. Hi! Does anyone know how I might be able to load a different background each time a game is started? I have three different preloaded backgrounds and would like the game to select a random one each time the game begins. I'm a complete newbie to Phaser and any help/tutorials would be hugely appreciated! Can link code if needed. Thanks!
  25. Anyone who has looked at the code I use for playing sound, music or dialog will notice that I use howler.js for playing sound. Now this New Year, I made a resolution to investigate more the the sound capabilities of BJS - and I have been looking at this tutorial . Now there is one feature that I can't see in the BJS that howler.js has - sound sprites. See here - scroll down to "Define and play a sound sprite" to see an example. All the sounds are contained in one file - but it is possible to play just parts of the file (and if you click the "Play Winner" button and then click the other two buttons you can play all three sounds at the same time - sounds get mixed). So why might this be useful? Well for playing what I call scene environment sounds - like doors opening and closing, footsteps fading away, a scream, a bell sounding, a dog howl etc. Now I have a little collection of these types of sound (between 15 and 20 sounds) the longest of which is about 9 secs and the shortest is 1.2 secs. so rather than load 15 separate files it would be nice to load just one file that I could play small parts of - saves clutter, and download requests. So am I missing/overlooking this type of functionality in BJS with sound? Or is it a feature that could be added? And as a side question, what compressed sound format is playable on all OSs, devices and browsers - or is that a fantasy? cheers, gryff