Dower

Members
  • Content Count

    18
  • Joined

  • Last visited

About Dower

  • Rank
    Member

Contact Methods

  • Twitter
    @dowerchin
  1. Good News! Xamarin now free in Visual Studio https://t.co/IRjkkcmgXT

  2. This is quite impressive: https://t.co/9dqBpYWrDl

  3. Dower

    Bullets above my player sprite?

    Oh god! I think I figured it out!!!! It looks like if I just created my bullet group first, then my player, it appears in the order I want... So my create function looks like this now, before this, the player was made before the bullets group... // Create our Bullet Groupthis.bullets = game.add.group();this.bullets.enableBody = true;this.bullets.createMultiple(5,"bullet");this.bullets.setAll("anchor.x", 0.5);this.bullets.setAll("anchor.y", 0.5);this.bullets.setAll('outOfBoundsKill', true);this.bullets.setAll('checkWorldBounds', true);this.bullets.z = 1; // Put the player on the screen, centeredthis.player = game.add.sprite(game.world.stage.width/2,game.world.stage.height-25,"player");this.player.anchor.setTo(0.5);this.player.angle = -90; If anyone has any other more elegant way of handling z-order, please let me know.
  4. This seems like a simple z-order or positional issue. But I have a simple top down shooting example, and I want to have a player at the bottom which can rotate in place and shoot. Now overall the example is working. But the problem I'm having is the bullets are above the player sprite location. In my test case, I have boxes, and the bullets are originating from the center anchor point of my sprite. I'm trying to figure out how I can hide that by moving the player above the bullets, or if possible reposition the firing to the front of the player. My initial test was to adjust the Y, but that doesn't work when the sprite rotates... Is there some sort of local coordinate system I should use for position the origin of the shots? Here's my current example using Phaser Sandbox: http://phaser.io/sandbox/LsJAGKsr In the sandbox demo it's only slightly noticeable, my local test with boxes, it's more evident.
  5. Dower

    Static starfield with some blinking stars

    Thanks Jmp909, I was wondering if there would be trade-offs... One thing I'm finding right now is the shader's background is blank... At least in this instance. I was hoping to see if I can get that to run on top of a colored background that would change randomly.
  6. Dower

    Static starfield with some blinking stars

    JakeCake's suggestion was excellent. I found a nice starfield to use here: http://glslsandbox.com/e#27815.0 I had never used Filters before, but they seem very powerful, and luckily not too hard to implement into Phaser. I did, however, need to use the latest 2.4.4 version of Phaser to run the filters.
  7. Dower

    Static starfield with some blinking stars

    Thanks for the suggestion JakeCake... That's some pretty impressive stuff over at glslsandbox! I'll look into that.
  8. Dower

    Static starfield with some blinking stars

    That's an interesting idea. I'll give that a shot!
  9. I'm trying to figure out a way to make a simple starfield for a background 2d side scrolling game. I could make a png file for the main background, but I would like some of the stars to blink... Would the best way to handle it be make a group and randomly scatter blinking sprites throughout the background? Or is there maybe a more elegant way of handling it? Particles maybe, or is that overkill?
  10. Try using Photoshop's SAVE FOR WEB option to save the PNG.
  11. Dower

    Sprite Picking Up Another Sprite

    Looks like I was able to do this with a group, and having each group with an "attached" attribute. Phaser group collisions are nice enough to know what element in the group is being collided and I'm able to make that one follow the chopper sprite. It's a bit more work, since I need to have a check in the update function for any in the entire group that has an "attached" of true, and then set that to the chopper location... I need to put more work into only allowing one to be picked up though... In the end, it works, but I'm still not sure if how I did it is the best way to handle it. Here's the latest code. I added a new sprite, 25x25 blue box, for the crates. I'm open to suggestions for improvement. Thanks. <!DOCTYPE html><html> <head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" /><title>PickUp Test</title><script type="text/javascript" src="js/phaser.min.js"></script><style>body {padding: 0px;margin: 0px;background: black;}</style> <script>var chopper; var crates;var mainState = {init: function() {this.stage.backgroundColor = "#111111";},preload: function() {game.load.image("chopper", "assets/images/player.png");game.load.image("crate", "assets/images/crate.png");},create: function() {game.physics.startSystem(Phaser.Physics.ARCADE);// create the groundvar floorBmp = game.add.bitmapData(480,5);floorBmp.ctx.fillStyle="#AAAAAA";floorBmp.ctx.fillRect(0,0,480,5);this.floor = game.add.sprite(0,315,floorBmp); // Add chopperchopper = game.add.sprite(game.world.centerX, game.world.centerY, "chopper");chopper.anchor.setTo(0.5);chopper.scale.setTo(1,-0.25);chopper.collideWorldBounds = true;// Add cratescrates = game.add.group(); crates.enableBody = true;for (var i=0; i<5; i++) {var c = crates.create(100+ (i*80),290,"crate");c.body.bounce.y = 0.5;c.body.gravity.y = 300;c.collideWorldBounds = true;c.name = "crate" + i;c.anchor.setTo(0.5);}crates.enableBodyDebug = true;crates.setAll("attached", false);// Define Physicsgame.physics.arcade.enable([chopper, this.floor, crates]);this.floor.body.immovable = true;this.floor.allowGravity - false;// setup the viewport cameragame.world.setBounds(0, 0, 480, 320); game.camera.follow(chopper);game.camera.deadzone = new Phaser.Rectangle(0,0,480,320);this.cursors = game.input.keyboard.createCursorKeys();},update: function() {game.physics.arcade.collide(chopper, crates, this.chopperHit, null, this);game.physics.arcade.collide(crates, this.floor);chopper.body.velocity.x = 0;chopper.body.velocity.y = 0;if (this.cursors.up.isDown){chopper.body.velocity.y = -200;}else if (this.cursors.down.isDown){chopper.body.velocity.y = 200;}if (this.cursors.left.isDown){chopper.body.velocity.x = -200;}else if (this.cursors.right.isDown){chopper.body.velocity.x = 200;}crates.forEach(function(i) {if (i.attached) {i.x = chopper.x;i.y = chopper.y + 30;}});},render: function() {game.debug.body(chopper);//game.debug.body(crates); game.debug.body(this.floor);crates.forEach(function(i) {game.debug.body(i);});},chopperHit: function(body, crateHit) {console.log("HIT CRATE = " + crateHit.name);crateHit.attached = true;crateHit.x = chopper.x;crateHit.y = chopper.y+30;crateHit.body.gravity.y = 0;}}var game = new Phaser.Game(480, 320, Phaser.AUTO);game.state.add("main", mainState);game.state.start("main");</script> </head> <body> </body></html>
  12. Dower

    Sprite Picking Up Another Sprite

    After some messing around, I came up with this solution, but I don't know how well it will scale. So, in the chopperHit function, I check to see if the crate.attached = true, if not, I set that, and I position the crate to the chopper's x and y+30 position. I also figured out that I had to turn the gravity.y off on the crate, because it would continue to slide down. Then i put in the update function a check if crate.attached, then I set the position to the chopper's x and y+30... I seems to work... But I don't know if this would scale once I converted the crate into a group and had a bunch on the screen... I still don't quite get the addChild, since once I try to addChild(crate). It just disappears. <!DOCTYPE html><html> <head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" /><title>PickUp Test</title><script type="text/javascript" src="js/phaser.min.js"></script><style>body {padding: 0px;margin: 0px;background: black;}</style> <script>var chopper; var crate;var mainState = {init: function() {this.stage.backgroundColor = "#111111";},preload: function() {game.load.image("chopper", "assets/images/player.png");},create: function() {game.physics.startSystem(Phaser.Physics.ARCADE);// create the groundvar floorBmp = game.add.bitmapData(480,5);floorBmp.ctx.fillStyle="#AAAAAA";floorBmp.ctx.fillRect(0,0,480,5);this.floor = game.add.sprite(0,315,floorBmp); // Add chopperchopper = game.add.sprite(game.world.centerX, game.world.centerY, "chopper");chopper.anchor.setTo(0.5);chopper.scale.setTo(1,-0.25);chopper.collideWorldBounds = true;// Add cratecrate = game.add.sprite(300,50,"chopper");crate.scale.setTo(-0.5);crate.anchor.setTo(0.5,0.5);crate.attached = false;// Define Physicsgame.physics.arcade.enable([chopper, this.floor, crate]);this.floor.body.immovable = true;this.floor.allowGravity - false;crate.body.bounce.y = 0.5;crate.body.gravity.y = 300;crate.collideWorldBounds = true;// setup the viewport cameragame.world.setBounds(0, 0, 1920, 320); game.camera.follow(chopper);game.camera.deadzone = new Phaser.Rectangle(0,0,480,320);this.cursors = game.input.keyboard.createCursorKeys();},update: function() {game.physics.arcade.collide(chopper, crate, this.chopperHit, null, this);game.physics.arcade.collide(crate, this.floor);chopper.body.velocity.x = 0;chopper.body.velocity.y = 0;if (this.cursors.up.isDown){chopper.body.velocity.y = -200;}else if (this.cursors.down.isDown){chopper.body.velocity.y = 200;}if (this.cursors.left.isDown){chopper.body.velocity.x = -200;}else if (this.cursors.right.isDown){chopper.body.velocity.x = 200;}if (crate.attached) {crate.x = chopper.x;crate.y = chopper.y+30;}},render: function() {game.debug.body(chopper);game.debug.body(crate); game.debug.body(this.floor);},chopperHit: function(body, bodyB, shapeA, shapeB, equation) {if (!crate.attached) { crate.x = chopper.x;crate.y = chopper.y+30;crate.body.gravity.y = 0;crate.attached = true;}}}var game = new Phaser.Game(480, 320, Phaser.AUTO);game.state.add("main", mainState);game.state.start("main");</script> </head> <body> </body></html>
  13. Dower

    Sprite Picking Up Another Sprite

    Here's my code in an all-in-one file. The player.png file is just a 50x50 box, and I'm repurposing it for testing, so I've not made sprites for the crate. I'm also just manually creating a ground sprite from a bitmap. The chopperHit function is where I attempt to addChild. Maybe this isn't the right approach, maybe I should just manually move the crate to the chopper position in the update function? <!DOCTYPE html><html> <head><meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" /><title>PickUp Test</title><script type="text/javascript" src="js/phaser.min.js"></script><style>body {padding: 0px;margin: 0px;background: black;}</style> <script>var chopper; var mainState = {init: function() {this.stage.backgroundColor = "#111111";},preload: function() {game.load.image("chopper", "assets/images/player.png");},create: function() {game.physics.startSystem(Phaser.Physics.ARCADE);// create the groundvar floorBmp = game.add.bitmapData(480,5);floorBmp.ctx.fillStyle="#AAAAAA";floorBmp.ctx.fillRect(0,0,480,5);this.floor = game.add.sprite(0,315,floorBmp); // Add chopperchopper = game.add.sprite(game.world.centerX, game.world.centerY, "chopper");chopper.anchor.setTo(0.5);chopper.scale.setTo(1,-0.25);chopper.collideWorldBounds = true;// Add cratethis.crate = game.add.sprite(300,50,"chopper");this.crate.scale.setTo(-0.5);this.crate.anchor.setTo(0.5,0.5);this.crate.attached = false;// Define Physicsgame.physics.arcade.enable([chopper, this.floor, this.crate]);this.floor.body.immovable = true;this.floor.allowGravity - false;this.crate.body.bounce.y = 0.5;this.crate.body.gravity.y = 300;this.crate.collideWorldBounds = true;// setup the viewport cameragame.world.setBounds(0, 0, 1920, 320); game.camera.follow(chopper);game.camera.deadzone = new Phaser.Rectangle(0,0,480,320);this.cursors = game.input.keyboard.createCursorKeys();},update: function() {game.physics.arcade.collide(chopper, this.crate, this.chopperHit, null, this);game.physics.arcade.collide(this.crate, this.floor);chopper.body.velocity.x = 0;chopper.body.velocity.y = 0;if (this.cursors.up.isDown){chopper.body.velocity.y = -200;}else if (this.cursors.down.isDown){chopper.body.velocity.y = 200;}if (this.cursors.left.isDown){chopper.body.velocity.x = -200;}else if (this.cursors.right.isDown){chopper.body.velocity.x = 200;}},render: function() {game.debug.body(chopper);game.debug.body(this.crate); game.debug.body(this.floor);},chopperHit: function(body, bodyB, shapeA, shapeB, equation) {if (!this.crate.attached) { this.crate.x = chopper.x;this.crate.y = chopper.y + 50;chopper.addChild(this.crate);this.crate.attached = true;}}}var game = new Phaser.Game(480, 320, Phaser.AUTO);game.state.add("main", mainState);game.state.start("main");</script> </head> <body> </body></html>
  14. Dower

    Sprite Picking Up Another Sprite

    Thanks for the responses. I'm not quite understanding the addChild method. So, when my chopper collides with the crate. I call a chopper.addChild(this.crate). The crate then disappears. I'll see if I can post up some code.
  15. So, I'm still getting used to Phaser, and my question for the community is what would you do to get a sprite to pick up another sprite. So, example. The player is a helicopter, and the ground has crates, I want the chopper to make contact with the crate, and pick it up; in essence, the crate becomes attached to the chopper sprite, so it will move wherever the chopper goes. Of course, I'll need the player to drop the crate too. So, would I make the player into a group, and then add the collided crate into this group? What do you all think? Thanks, Dower