jagd

Members
  • Content Count

    10
  • Joined

  • Last visited

  1. I'm creating a game with a very large world which will all be loaded from the beginning of the game. However, to cut down on resource use, I want to make it so objects will only do stuff if they are in the player's view. For example, an object that spawns a rockslide will only do so if it is within the player's view--or 'on-screen' if you want to use that term. How do I do this? Is there a way to say something like, if(Object.isOnScreen){ >>>do stuff } and would that work? Or for example, if it is offscreen, delete it.
  2. I'm creating a game with a very large world which will all be loaded from the beginning of the game. However, to cut down on resource use, I want to make it so objects will only do stuff if they are in the player's view. For example, an object that spawns a rockslide will only do so if it is within the player's view--or 'on-screen' if you want to use that term. How do I do this? Is there a way to say something like, if(Object.isOnScreen){ }
  3. Oh, shoot, I forgot about that! So I looked at the code with developer tools and am still confused as to how they did it. When I did this in Arcade physics I used VelocityfromAngle. Does anyone know if there is an equivalent to VelocityfromAngle in P2?
  4. Yeah thanks, so the complete demo available there looks like what I want (except I'm using 2D mode, not whatever 2.5D mode they are using), but that page doesn't have any of the code showing how to do it.
  5. So in my game the player object is made up of several different sprites, so I made a Group called "player," and tried to add an object to it, "rover_proto." I am also trying to use forEach() to change attributes of each item belonging to the group. Here is my code: function createGameScene() { // format: (game, name, addToStage, enableBody, physicsBodyType) player = game.add.group(game.world, 'player', true, true, Phaser.Physics.P2); Rover_proto = player.create(0, 0, 'Rover_proto'); //player.setAll('body', true, true, false); //Group collision player.forEachExists(function (item){ item.body.setCollisionGroup(playerCollision); item.body.collides(wallCollisionGroup); item.body.createGroupCallback(wallCollisionGroup, hurt_rover, player); });}So when I comment out the setAll() is says that "item.body is null." I thought that using game.add.group allows you to enableBody for each item in the group, at least I think it worked that way in Arcade (I am using P2 now which is what is causing me this trouble). So that's when I added in player.setAll(), to hopefully give everything a body. However, if I uncomment it, then the program gives two errors: "TypeError: item.body.setCollisionGroup is not a function" and "TypeError: This.body.preUpdate is not a function." I don't understand why these problems are being caused. I remember using arcade the only way to fix the problem of objects in a group not having bodies was to use the game.add.group() method which I did use in this code. I've also used forEach before, but here it's not working. Is there something I'm missing? Am I using these functions wrong? Can forEach only be called during Update() and not Create() or something? How can I create a body and physics and set collisions, etc. for each object in a group if game.add.group() isn't working (and why isn't it working)? Thank you for your time, --jagd
  6. Hi, I'm making a game where the player controls a Mars Rover from a top-down perspective. I'm using the WASD control scheme and I'm trying to make it so the rover moves like a car. If you aren't sure what I mean, imagine looking down at a car performing a K-turn and you might know what I mean. I got this to work with Arcade Physics, even got it to work with groups. Now I don't know how to get it to work with P2 Physics. Here is my code: function MovePlayer(player, cursors, game){ //Player Basic Movement Controls //WASD declerations might be making things slower fyi. var W = game.input.keyboard.addKey(Phaser.Keyboard.W); var Al = game.input.keyboard.addKey(Phaser.Keyboard.A); var S = game.input.keyboard.addKey(Phaser.Keyboard.S); var D = game.input.keyboard.addKey(Phaser.Keyboard.D); if (Al.isDown) { //player.body.rotateLeft(100); player.body.angularVelocity = -5; } else if (D.isDown) { //player.body.rotateRight(100); player.body.angularVelocity = 5; } else { player.body.setZeroRotation(); } if (W.isDown) { player.body.thrust(450); } else if (S.isDown) { player.body.reverse(300); } else { player.body.damping = 0.75; } if (player.body.velocity > 1.0) { player.body.velocity = 1.0; } }Right now the rover moves like it's in a slip'n'slide. Holding down forward and left or forward and right keys results in the rover spinning around in place. Imagine an object facing the center of a circle and just rotating around the center. Same thing using the reverse key. I don't know how to get it to work right. Any ideas?
  7. Okay I figured it out, turns out for groups you have to do enableBody not .body.enable.
  8. I got a lot of my code from the tutorial here <http://www.photonstorm.com/phaser/tutorial-making-your-first-phaser-game> but it's not working for me.
  9. Yes, as can be seen in the code above, I already tried that. The problem seems to be that for some reason the game isn't creating a body for the Player group. I just tried getting rid of the Player group and just having the Rover object by itself, but when I try to do Rover_proto.body.velocity.x it gives me the error ReferenceError: Rover_proto is not defined As compared to the error when I try to use Player.body where it says: TypeError: Player.body is undefined So with the Player group, it gives me a TypeError on the line where I say "Player.body.enable = true;" saying that Player.body is undefined. And when I use Rover_proto object, for some reason it is fine with the line "Rover_proto.body.enable = true;" but gives me a ReferenceError when I try "Rover_proto.body.velocity.x" saying Rover_proto itself is undefined. I have no idea what's going on but it looks like there are multiple problems.
  10. Hi, first-time user here, In my game, I have a vehicle that is made up of multiple objects. Since we're going to have to rotate or move every piece together, I thought I could make a group for all the objects, call it "Player", then use code like Player.body.velocity.x = 1, etc. in the update function to control it. However, it keeps telling me Player.body is undefined. Here is my code: window.onload = function() { var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'prototype', { preload: preload, create: create, update: update }); function preload () { game.load.image('Rover_proto', 'Assets/Art/Rover/Rover_proto.png');} var Player; function create () { // We're going to be using physics, so enable the Arcade Physics system game.physics.startSystem(Phaser.Physics.ARCADE); //The actual rover will be made of separate objects, //we put them all in a group so they all act together. Player = game.add.group(); game.physics.arcade.enable(Player) // We will enable physics for any object that is created in this group Player.body.enable = true; // ERROR: Player.body is undefined //create the prototype rover in the Player group //Rover_proto = Player.create(game.world.centerX, game.world.centerY, 'Rover_proto'); var Rover_proto = game.add.sprite(game.world.centerX, game.world.centerY, 'Rover_proto'); game.physics.arcade.enable(Rover_proto); Rover_proto.body.enable = true; Player.add(Rover_proto); } function update(){ //Moving the rover //reset the player's velocity Player.body.velocity.x = 0; // ERROR: Player.body is undefined}}; So yeah, it keeps telling me Player.body is undefined, even though I say "Player.body.enable = true." If I use the Rover_proto.body and comment out everything to do with Player, it works fine and tells me that Rover_proto.body is defined. I want to know if I'm using groups right and how to make this error go away, and still be able to put everything for our Rover under one group. I've looked at various guides and examples online but they are all contradictory, using totally different commands (like object.body.enable versus object.enableBody, I don't know if there is even a difference). I checked the documentation but it doesn't have any real examples. Thanks for the help,--jagd