Search the Community

Showing results for tags 'question'.



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

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

  1. Jimaginary

    Anyone Using Redux with Phaser?

    So I started a project in es5 javascript and put everything in one huge game file. This quickly became hard to manage so I decided to use ES6 Javascript and break things out into their own classes. However, I then realized that there are times when these different classes need to display and modify the same data. In a part project I've used Redux with react which was pretty awesome, and I've used shivering very similar in angular 2 (Ngrx library). In another post about React it seems like people are saying the virtual DOM, JSX, and all that is pretty much useless with the way that phaser renders in canvas and doesn't really use any HTML. However, I just stumbled across this really cool jsfiddle that uses the redux library, straight up, as a way to manage state with redux alone: https://jsfiddle.net/archierocks183/zygz2ksm/17/ What do you guys think about this? Do you think it's a good way to go? Does anyone have any projects where you've gone down his route (or something similar)? How did it go? Just trying to get ideas and figure out how to manage state in my growing app. Thanks!
  2. Hello guys, I'm new to game development but I have some background on HTML/CSS/JS that's why I found Phaser perfect for me. So far I'm really loving it but can't understand some basic game logics. For example: What is the best way to build platforms? I was reading about groups but not sure is it the right way to do it. Let's just say that I have sprite and I want to build specific pattern. So far I tried : Every platform is diffrent sprite Using single tile to build platforms Also is there any books or other sources for information about game logics and good practices? Thank you and sorry for my bad English
  3. estudillod

    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, game.world.height - 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
  4. Hey guys, I made a game on my Macbook pro, I use scale.set() in many places and use the screens height/width to help place sprites. The problem is that my Macbook has a retina screen (which has a pixel density of 2.0). When I play my game on a non-retina (normal 1.0) screen the game is blown up to look massive. The way to fix it would be to divide any numbers I use for size/position by the pixel density. This however seems weird as I have to have this everywhere somevar * game.device.pixelRatio Is there a way to do this better?
  5. I'm trying to update a rectangle drawn using drawRect by changing the value of fillColor but I can't get it to work. Here's my code: var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create}); function preload() { } function create() { this.rect = game.add.graphics(0, 0); game.stage.backgroundColor = '#FBFAFA'; this.rect.beginFill(0xf44253); this.rect.lineStyle(15, 0xf44253, 1); this.rect.drawRect(350, 250, 100, 100); game.input.onDown.addOnce(changeColour, this); window.graphics = this.rect; } function changeColour() { debugger; var newColour = Phaser.Color.hexToRGB('#42f445'); this.rect.graphicsData[0].fillColor = newColour; console.log("clicked"); } On mouseclick changeColour is getting called and I can see in the debugger this.rect.graphicsData[0].fillcolor is being changed from 16007763 to 21165125 which are the correct color values in 0xAARRGGBB format. Do I need to call a function to get this.rect to redraw the rect primitive? I know I can call this.rect.clear() and call beginFill/drawRect again with the new color but I'd seen other examples on this forum of people just setting fillColor directly.
  6. Hi guys, I was wondering, how do I get my picture added to that top image thing on the homepage? Yknow it shows like a posts image, then u can check out the link below it? Thanks,
  7. Hello, guys. I'm trying to set up a workplace using CreateJS and Typescript. So far I tried only to use VisualStudio for this. I see everyone using the "createjs." namespace, can't find it in .d files from here: https://github.com/borisyankov/DefinitelyTyped Or is there another way of using Typescript with all the typing, intellisense and debugging?
  8. Hello. I am very new to PIXI, so please bare with me. I have been in search of good API for my game. The game uses a map which contains tiled images as well as a bunch of path on the screen. Think Google Map, except a lot simpler. I was able to use PIXI to implement the map background where it scrolls and loads tiled map images as needed. I was also able to draw paths onto the map. Now the problem is that I cannot figure out how to interact with those paths. I used PIXI.Graphics to create and draw a path. I applied mouse events to it. But no event is fired. I was able to get the even to fire if I made the graphic into closed path will fill. But unfortunately that will not work for my purpose. Is there any way to accomplish this? Any way to interact with just a path (could be complex paths with multiple segments and/or curves) rather than enclosing shape? Thanks in advance!
  9. Covacs

    Painting Shots

    Hi, im new here. I have one big doubt, I´m making a game where you shoot ink, and I'd love to staint the floor with it. But I don´t know how. Does anyone know how to do it? Any ideas? Thanks.
  10. Temich

    Problem with Tiled ( Probably )

    Hello, Phaser Community! I'm new to HTML5 development, and i've got some problems. Currently i'm working on platformer movement. If a character moves to the edge of the platform, he gets instantly moved to the beginning of that platform, GIF - http://imgur.com/4mKZoH3 Here's my Level1 code: Game.Level1 = function(game){}; var map; var layer; var player; var player_test; var heart; var MAX_SPEED = 48; var ACCELERATION = 1; var DRAG = 500; var GRAVITY = 920; var JUMP_SPEED = -250; var RIGHT = true; var LEFT = false; var JUMP_TIME = 0.5; Game.Level1.prototype = { upInputIsActive:function(duration) { var isActive = false; isActive = this.input.keyboard.downDuration(Phaser.Keyboard.Z, duration); isActive |= (this.input.activePointer.justPressed(duration + 1000/60) && this.input.activePointer.x > game.width/4 && this.input.activePointer.x < game.width/2 + game.width/4); return isActive; }, upInputReleased:function() { var released = false; released = this.input.keyboard.upDuration(Phaser.Keyboard.Z); released |= this.game.input.activePointer.justReleased(); return released; }, leftInputIsActive:function() { var isActive = false; isActive = this.input.keyboard.isDown(Phaser.Keyboard.LEFT); isActive |= (this.game.input.activePointer.isDown && this.game.input.activePointer.x < this.game.width/4); return isActive; }, rightInputIsActive:function() { var isActive = false; isActive = this.input.keyboard.isDown(Phaser.Keyboard.RIGHT); isActive |= (this.game.input.activePointer.isDown && this.game.input.activePointer.x > this.game.width/2 + this.game.width/4); return isActive; }, create:function() { map = this.add.tilemap('lv1', 8, 8 ); map.addTilesetImage('Tileset', 'tileset'); layer = map.createLayer(0); layer.resizeWorld(); map.setCollisionBetween(1,5); player = this.game.add.sprite(this.game.width/4, this.game.height - 32, 'player'); player.animations.add('run_left', [0, 1], 13, true); player.animations.add('run_right', [2, 3], 13, true); player.animations.add('idle_left', [8, 8, 8, 8, 8, 8, 9, 9, 9, 9], 5, true); player.animations.add('idle_right', [10, 10, 10, 10, 10, 10, 11, 11, 11, 11], 5, true); heart = this.game.add.sprite(this.game.width/2, this.game.height/2, 'heart'); heart.animations.add('idle', [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8], 18, true); player_test = this.game.add.sprite(this.game.width-20, this.game.height - 20, 'player_idle_test'); player_test.animations.add('test_idle', [0, 1, 2, 3, 4], 13, true); this.physics.enable(player, Phaser.Physics.ARCADE); this.physics.arcade.gravity.y = GRAVITY; player.body.maxVelocity.setTo(MAX_SPEED, MAX_SPEED * 10); }, update:function() { this.physics.arcade.collide(player, layer); var onTheGround = player.body.blocked.down; heart.animations.play('idle'); player_test.animations.play('test_idle'); if (player.body.velocity.y>0) { if (LEFT == true) player.frame = 6; if (RIGHT == true) player.frame = 5; } if (this.leftInputIsActive()) { player.body.velocity.x += -ACCELERATION/3; LEFT = true; RIGHT = false; } else if (this.rightInputIsActive()) { player.body.velocity.x = ACCELERATION/3; LEFT = false; RIGHT = true; } else { player.body.velocity.x = 0; if(LEFT == true && RIGHT == false && onTheGround && player.body.velocity.y == 0) { player.animations.play('idle_left'); } if(RIGHT == true && LEFT == false && onTheGround && player.body.velocity.y == 0) { player.animations.play('idle_right'); } } if (this.leftInputIsActive() && player.body.onFloor) { player.animations.play('run_left'); } if (this.rightInputIsActive() && player.body.onFloor) { player.animations.play('run_right'); } // Set a variable that is true when the player is touching the ground if(onTheGround) { DRAG = 2250; ACCELERATION = 750; } else { DRAG = 1750; ACCELERATION = 1000; } // If the player is touching the ground, let him jump if (onTheGround) { this.jumping = false; } // Jump! Keep y velocity constant while the jump button is held for up to 150 ms if (this.upInputIsActive(100) && (this.jumping == false)) { player.body.velocity.y = JUMP_SPEED * JUMP_TIME; player.animations.stop(); if(LEFT) { player.frame = 7; } if(RIGHT) { player.frame = 4; } } // Reduce the number of available jumps if the jump input is released if (this.upInputReleased()) { this.jumping = true; } } }
  11. kgibson

    [SOLVED] AI movement question

    Alright, been stuck on this for a few days and starting to think I'm overlooking a very simple solution. I have a character that I want to walk back and forth on the screen. He needs to walk to one edge, turn around, then walk to the other edge, again turn, walk, etc.; rinse and repeat. I've tried simply '+=' and '-=' on his x coord with an if statement but he wont seem to walk in the other direction. Example, writing 'steve.x += 1;' then 'steve.x -= 1;' won't work. He gets to one edge but then stops. I've also tried using tweens but he seems to become jittery as he's a spritesheet already, maybe? His physics body will stay, but the pixels themselves seem to move outOfBounds. Anyway, here's the full code for what I'm working on, any help is greatly appreciated. http://pastebin.com/V0GM7z3w Also still learning Phaser so any feedback on code flow is helpful too! Thanks!
  12. GAveryWeir

    How to apply Filter to entire game?

    I'm really liking Phaser, and am trying out converting a WIP Flixel project. I'd like to do a bloom filter over the whole canvas. What's the best way of going about this? I have a working bloom filter already; I'm just trying to figure out how to apply it to an entire Game or State. Sprites seem to have the filters property, but Game doesn't seem to have an equivalent. I've tried drilling into the Pixi code, but its filters don't seem to be superclasses of Phaser's filters, and I thought I'd ask a question before hacking away any further.
  13. sprite.events.onInputUp.add(function(){},this); game.input.onUp.add(function(){},this); They are triggering when I click sprite.help!
  14. Hello fellow 3D engineers, at the moment I'm working on a replacment of our old 3D system (was a plugin). I am using babylon for this and I am really impressed so far. The work flows easily through the hands. So I have a small problem, might be a really small one. We have a costumizeable pavillon. I build the Roof construction for one side of the roof. (it has a repeating triangular form). Then merged the mesh, created six instances and rotated them around the center to place them properbly. The main work is finished (calculation and boolean subtractions). Now I just want to polish the scene with shadows etc. I have already read what to do to sovle the problem with self shadowing (bias value). But what I see now is that the roof parts a illuminated the wrong for me. Please look at the screenshot. Is this right? It looks wrong. I can't say whether this is a bug or I am doing something wrong. Thanks for any help and best regards Kevin
  15. Take a look at the WebGL rendering in this fiddle: http://jsfiddle.net/intrinsica/L9z655jy/ Note the extension of the polygon beyond the 200px width it is defined to be. Is this a bug or a feature? If it's a bug, I'll file an issue. For reference, the fiddle includes a PIXI Canvas rendering and a ProcessingJS rendering. Thanks.
  16. Hi, I have been using Pixi.js for a few months now and I am wondering if it is possible to erase lines drawn on a PIXI.Graphics object. Basically I have some functionality where I am able to draw on a Graphics object on a Sprite using mouse and touch events. My issue is that the sprite has a texture which is not just 1 color. If the texture was blue I would just draw with blue color to "erase" the lines i had drawn earlier with another color. If I was not using Pixi.js I could use the functionality shown here: http://cssdeck.com/labs/jwvajze4/ This eraser functionality is excactly what I need, but I need it in Pixi.js. Is it possible to adapt this same functionality in Pixi.js? Any suggestions or tips would be great.
  17. In my game I want an animation to play when the player collides with a red block and dies. I used the arcade physics system and said a function called gameOver should trigger when the player and a block overlap. The animation I'm using is an explosion, the function then calls for the player to be killed and removed from the canvas and for the explosion sprite to be added and for it's animation to play. The problem is that the function only plays the first frame, I'm assuming this is because either the function only runs once after they overlap or because the player dies and therefore without the player nothing is overlapping and the function stops. Tl;Dr: how do you make a death animation play after a sprite dies Thanks for any help My code: *Note the relevant part is coloured green. var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,});var Rx = Math.random () * 800; // ball spawns in a random placevar Ry = Math.random() * 600;var Bx = Math.random () * 800; var By = Math.random() * 600;var Gx = Math.random () * 800 var Gy = Math.random() * 600;var colours = ["redBlock","greenBlock","blueBlock"];var colour = colours[Math.floor(Math.random()*2)];var score = 0; var scoreText;var collideCounter = 0;var playerX = 10;var playerY = 10; function preload() {cursors = game.input.keyboard.createCursorKeys(); //allows keyboard inputthis.game.load.image("redBlock","assets/red.png");this.game.load.image("greenBlock","assets/green.png");this.game.load.image("blueBlock","assets/blue.png");this.game.load.spritesheet("explosion","assets/explosionSheet.png",433,410);this.game.load.image("block","assets/block.png");} function create() {this.game.physics.startSystem(Phaser.Physics.ARCADE);this.game.scale.pageAlignHorizontally = true; //centers canvasthis.game.scale.pageAlignVertically = true;this.game.scale.refresh(); Rblock = game.add.group(); Rblock.enableBody = true; for (var i = 1; i < 4 ; i++){var RblockT = Rblock.create(i * Rx,i * Ry,"redBlock"); // x and y are randomy coordinates the ball spawns atRblockT.body.velocity.setTo(200,200);RblockT.body.collideWorldBounds = true; RblockT.body.bounce.set(1);} Bblock = game.add.group(); Bblock.enableBody = true; for (var i = 1; i < 4; i++){BblockT = Bblock.create(i * Bx,i * By,"blueBlock"); // x and y are randomy coordinates the ball spawns atBblockT.body.velocity.setTo(200,200);BblockT.body.collideWorldBounds = true; BblockT.body.bounce.set(1);} Gblock = game.add.group(); Gblock.enableBody = true; for (var i = 1; i < 4 ; i++){GblockT = Gblock.create(i * Gx,i * Gy,"greenBlock"); // x and y are randomy coordinates the ball spawns atthis.game.physics.arcade.enable(Gblock);GblockT.body.velocity.setTo(200,200);GblockT.body.collideWorldBounds = true; GblockT.body.bounce.set(1);} player = this.game.add.sprite(10,10,"block");this.game.physics.arcade.enable(player);player.body.collideWorldBounds = true;player.scale.setTo(0.2,0.2); explosion = this.game.add.sprite(800,700,"explosion");explosion.animations.add ("explode",[1,0,2],2,true); scoreText = this.game.add.text(16,16,"Score:0",{ FontSize: "32px",fill: "#CCFFFF"});test = this.game.add.text(16,32,"test:",{ FontSize: "32px",fill: "#CCFFFF"});test2 = this.game.add.text(16,50,"test:",{ FontSize: "32px",fill: "#CCFFFF"});} function update() {this.game.physics.arcade.overlap(player,Rblock,gameOver,null,this);this.game.physics.arcade.overlap(player,Gblock,addPointG,null,this);this.game.physics.arcade.overlap(player,Bblock,addPointB,null,this); function addPointR (player, RblockT){score += 1;scoreText.text = "Score:" + score;RblockT.kill();} function addPointG (player, GblockT){score += 1;scoreText.text = "Score:" + score;GblockT.kill();} function addPointB (player, BblockT){score += 1;scoreText.text = "Score:" + score;BblockT.kill();} function gameOver(){player.kill();explosion = this.game.add.sprite(player.body.x,player.body.y,"explosion");explosion.anchor.setTo(0.5,0.5);explosion.animations.play("explode");} playerY = player.body.velocity.y; //playerY tracks the y coordinate of the player and is used to tell where the explosion should spawnplayerX = player.body.velocity.x; //playerX tracks the x coordinate of the player and is used to tell where the explosion should spawnplayer.body.velocity.x = 0;player.body.velocity.y = 0; if (cursors.up.isDown){player.body.velocity.y += -200;} if (cursors.down.isDown){player.body.velocity.y += 200;} if (cursors.left.isDown){player.body.velocity.x += -200;} if(cursors.right.isDown){player.body.velocity.x += 200;}}
  18. xcb

    I need some code explained.

    Hi. I was just rewriting http://vimeo.com/105955605 this thing and searching for stuff i don't understand while rewriting it. Here is jsFiddle: http://jsfiddle.net/mstfrwvn/2/ . I learned a lot doing so, but there are still a few things I don't quite understand. -why did she use those prototypes? Can't I just put those functions inside the constructors with "this."? Was it to make it less cluttered or something? -why is everything in a function? Is it to "encapsulate" it from other potential code? (I hope I'm using this term correctly) I also know it isn't well optimized/there are things which can be improved (I know the purpose of the presentation wasn't to make it optimized, but finding flaws in it may be a good exercise!). Things I found: -projectiles aren't deleted after flying out of the view. -speed of the game depends on the framerate. Sooo, could someone explain these things to me and maybe find some other flaws? (I would like to strip it out of everything and make some simple games using this)
  19. Hello community. is there a way to handle this type of collisions with tilemaps ?I'm starting with phaser and i couldn't find any similar example
  20. I have been trying to separate my code into states but no matter what I try the game comes up with a black screen, and an error saying "No state found with the key: playTest " . Here is my code: Thanks for any help this has been bothering me for a while *Note: each colour is a different file (index,load and playTest). Index: <!DOCTYPE html><html> <head><meta charset="utf-8" /><script src="phaser.js"></script><script src="load.js"></script><script src="playTest.js"></script></head> <body> <script> function create() { var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'game'); game.state.add("load",load);game.state.add("playTest",playTest);game.state.start("playTest");};</script></body</html> load: var load = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create}); function preload() {cursors = this.game.input.keyboard.createCursorKeys(); //allows keyboard inputthis.game.load.image("sky","assets/sky.png");} function create() {this.game.state.start("playTest")} play: var playTest = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,}); function create() {this.game.add.image(0,0,"sky");this.game.add.text(16,16,"test");this.game.scale.pageAlignHorizontally = true; //centers canvasthis.game.scale.pageAlignVertically = true;this.game.scale.refresh(); } function update() { }
  21. I want a ball to bounce but my current code isn't working and I don't know why, thanks for any feedback. My Code: * I have made the parts of the code which are relevant green var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,});var x = Math.floor(Math.random () * 800); // ball spawns in a random placevar y = Math.floor(Math.random() * 600);var text; function preload() {cursors = game.input.keyboard.createCursorKeys(); //allows keyboard inputthis.game.load.image("block","assets/block.png");this.game.load.image("redBlock","assets/red.png");this.game.load.image("greenBlock","assets/green.png");this.game.load.image("blueBlock","assets/blue.png");} function create() {this.game.physics.startSystem(Phaser.Physics.ARCADE);this.game.scale.pageAlignHorizontally = true; //centers canvasthis.game.scale.pageAlignVertically = true;this.game.scale.refresh(); block = this.game.add.sprite(x,y,"redBlock"); // x and y are randomy coordinates the ball spawns atthis.game.physics.arcade.enable(block); player = this.game.add.sprite(10,10,"block");this.game.physics.arcade.enable(player);player.scale.setTo(0.2,0.2);player.body.collideWorldBounds = true; } function update() { player.body.velocity.x = 0;player.body.velocity.y = 0; block.body.velocity.x += 50;block.body.velocity.y += 50; if(x > game.world.width){ //if the balls x coordinate is larger than the width of the screen make the x velocity block.body.velocity.x = block.body.velocity.x * -1; //of the ball the opposite of what it is, making it seem like it bounces off of it.} if(x < game.world.width - game.world.width){ //if the balls x coordinate is smaller than the width of the screen make the x velocity block.body.velocity.x = block.body.velocity.x * -1; //make it bounce} if(y > game.world.height){ //if the balls y coordinate is larger than the height of the screen make it bounceblock.body.velocity.y = block.body.velocity.y * -1;} if(y < game.world.height - game.world.height){ //if the balls y coordinate is smaller than the height of the screen make it bounceblock.body.velocity.y = block.body.velocity.y * -1;} if(cursors.left.isDown){player.body.velocity.x += -200; } if(cursors.right.isDown){player.body.velocity.x += 200;} if(cursors.down.isDown){player.body.velocity.y += 200;} if(cursors.up.isDown){player.body.velocity.y += -200;}}
  22. Is a local web server like cloud9 necessary to code in phaser? I heard about it recently but up until now i have simply been opening the canvas on my web browser and everything has been working fine. I dont use anything like cloud9 to run my code and havent had any problems. But even the phaser setup talks about downloading a local web server. So ultimately im confused, do we really need one, and if so why. I dont seem to have any problems just coding and opening it in my browser.
  23. I downloaded Brackets and opened my files in it, but once I open the html file the canvas is all black and two errors come up. These are, error 1: Failed to load resource: the server responded with a status of 400 (Bad Request) and error 2: Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('http://127') does not match the recipient window's origin ('http://127'). *note: I took out some of the numbers in the brackets of the second error since it displays personal data regarding the server. Thanks for any help
  24. Hi, I'm a beginner with Phaser and Javascript and have been learning by playing around with the wonderful Game Mechanic Explorer http://gamemechanicexplorer.com/ (by John Watson @yafd) I noticed in the double jump example http://gamemechanicexplorer.com/#platformer-5 that on mobile (iphone) double jumping wasn't working. I'm not going to paste in all the code just the code I think deals with the issue. // Set a variable that is true when the player is touching the ground var onTheGround = this.player.body.touching.down; if (onTheGround) this.canDoubleJump = true; if (this.upInputIsActive(5)) { if (this.canDoubleJump || onTheGround) { // Jump when the player is touching the ground or they can double jump this.player.body.velocity.y = this.JUMP_SPEED; // Disable ability to double jump if the player is jumping in the air if (!onTheGround) this.canDoubleJump = false; } }// This function should return true when the player activates the "jump" control// In this case, either holding the up arrow or tapping or clicking on the center// part of the screen.GameState.prototype.upInputIsActive = function(duration) { var isActive = false; isActive = this.input.keyboard.justPressed(Phaser.Keyboard.UP, duration); isActive |= (this.game.input.activePointer.justPressed(duration + 1000/60) && this.game.input.activePointer.x > this.game.width/4 && this.game.input.activePointer.x < this.game.width/2 + this.game.width/4); return isActive;};From what I gather is that if (this.upInputIsActive(5)) condition is never met on mobile. My question is why doesn't this work on mobile and if someone could point me in the right direction to solve this so it does work on mobile. Thanks!
  25. callidus

    problem with code please help

    I'm trying to have my sprite jump, and the conditions are if he is on the floor and if I'm pressing the up key. But he wont jump even when he's on the floor. When taking "player.body.touching.down" out of the code the sprite jumps so I'm assuming something in my code is interfering with hit detection between the player and the ground. Here is the code: (I have coloured the part of the code which I assume is the problem and anything that is relevant green) Any help is greatly appreciated var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload, create: create, update: update,});var rightCounter = 0;var leftCounter = 0;var score = 0;var scoreText;var obstacles;var highScore = 0;var highScoreText;var x = 50;var y = -50; function preload() {cursors = game.input.keyboard.createCursorKeys(); //allows keyboard inputgame.load.spritesheet("doggie","assets/doggie.png",32,32);game.load.image("treat","assets/cookie.png");game.load.image("sky","assets/sky.png"); game.load.image("platform","assets/platform.png");game.load.spritesheet("boulder","assets/boulderComplete.png",95,96);} function create() {game.physics.startSystem(Phaser.Physics.ARCADE);this.game.scale.pageAlignHorizontally = true; //centers canvasthis.game.scale.pageAlignVertically = true;this.game.scale.refresh(); game.add.image(0,0,"sky");scoreText = game.add.text (350,16, "Score:" + score, { fontSize: '32px', fill: '#ffffff' });highScoreText= game.add.text (16,16, "Highscore:" + highScore, {fontSize: "11px", fill: "#ffffff" }); ground = game.add.group(); ground.enableBody = true; var platform = ground.create(0,game.world.height - 30,"platform");platform.body.immovable = true;platform.scale.setTo(3,1) treat = game.add.sprite(200,0,"treat");game.physics.arcade.enable(treat)treat.body.gravity.y = 300; treat.body.bounce.y = 0.2; treat.body.collideWorldBounds = true; treat.scale.setTo(0.2,0.2); player = game.add.sprite(300,game.world.height - 100,"doggie"); game.physics.arcade.enable(player);player.body.gravity.y = 480; player.body.bounce.y = 0.2; player.body.collideWorldBounds = true; player.animations.add ("left",[0,1],5,true)player.animations.add ("idleLeft",[1],5,true)player.animations.add ("idleRight",[2],5,true)player.animations.add ("right",[2,3],5,true) boulder = game.add.sprite(100,-10,"boulder"); game.physics.arcade.enable(boulder);boulder.body.gravity.y = 1000; boulder.body.bounce.y = 0.2; } function update() {player.body.velocity.x = 0; if (cursors.left.isDown){ player.body.velocity.x = -300;player.animations.play("left");leftCounter += 1;rightCounter = 0;} else if (cursors.right.isDown){ player.body.velocity.x = 300;player.animations.play("right");leftCounter = 0; rightCounter +=1; }else if (cursors.up.isDown){player.body.velocity.y = -200;player.animations.play("idleLeft"); // This is the part of the code that doesn't work}else if (leftCounter > 0) { player.animations.play("idleLeft")}else if (rightCounter > 0){ player.animations.play("idleRight")}if (highScore<score){ highScore = score;highScoreText.text = "Highscore:" + highScore;}else {highScoreText.text = "Highscore:" + highScore;} function eatTreat() {treat.kill()treat = game.add.sprite (Math.floor(Math.random()*800),0,"treat")game.physics.arcade.enable(treat)treat.body.gravity.y = 300; treat.body.bounce.y = 0.2; treat.body.collideWorldBounds = true; treat.scale.setTo(0.2,0.2);score += 1;scoreText.text = "Score:" + score;} function boulderReset(){boulder.kill();boulder = game.add.sprite(Math.floor(Math.random() * 800),-10,"boulder"); game.physics.arcade.enable(boulder);boulder.body.gravity.y = 1000; boulder.body.bounce.y = 0.2; } function gameOver(){score = 0;scoreText.text = "Score:0", score;} game.physics.arcade.overlap(player,treat,eatTreat,null,this);game.physics.arcade.overlap(boulder,ground,boulderReset,null,this);game.physics.arcade.overlap(boulder,player,gameOver,null,this); game.physics.arcade.collide(player,ground);game.physics.arcade.collide(treat,ground);game.physics.arcade.collide(boulder,ground);}