Jump to content

Setting boundaries for hack n' slash


Meowts
 Share

Recommended Posts

Kinda confused about what the best way is to go about doing this...

 

The style of platformer is hack n' slash (think Golden Axe), so the bottom 200-300px of the screen is walkable and the rest is BG.

 

Just prototyping the player movements, and after trying a couple things to do with physics collision detection (both Arcade and P2 acted weird for what I'm trying to accomplish, sticking with P2 for movement), I figured for now I'd just keep it simple and check the player sprite's y when moving up.

// In the player's update loopif(input.cursors.up.isDown){	if(this.sprite.y >= 580){		this.sprite.body.moveUp(200);	}}

If I hold up, the player will keep moving up even when its y is less than 580. If I am past that point and let go, then try moving up, it'll stop. It's like body.moveUp() is creating some kind of internal loop and ignores the condition when up is held.

 

Anyway, just wondering if anyone else has created this style of platformer with Phaser and what might be a better approach?

Link to comment
Share on other sites

RIght now playing with setting the world boundaries, which I think might be the ideal solution - however after it updates the camera I can't seem to set it back into the right place.

//Screen's create function	create : function(){	this.bg = this.game.add.sprite(0, 0, 'bg');							this.floor = this.game.add.sprite(0, this.bg.height, 'floor');	this.game.world.resize(this.bg.width, 780);	this.game.world.setBounds(0, this.bg.height, this.bg.width, this.floor.height);	this.game.world.camera.setPosition(0, -this.bg.height);	this._player.init(115, 660);},

Basically it just ends up only showing the floor, and setting the camera's y to -bg.height (or 0) doesn't seem to bring the camera back up to the original position

 

*Edit - I realize having one big BG sprite and one big floor sprite is a fairly crude way of doing it, eventually I'll be moving on to using tilemaps, I'm just trying to work out a few of the basics first

Link to comment
Share on other sites

Okay, ended up switching back to Arcade physics and I'm giving the BG a physics body for collisions. I was confused over how when you use P2, it just goes ahead and collides whatever has P2 enabled, where with Arcade you need to actually assign a handler for the collision, otherwise the collision won't register at all.

//Screencreate : function(){	this.bg = this.game.add.sprite(0, 0, 'bg');	this.game.physics.arcade.enable(this.bg);	this.bg.body.immovable = true;					this.floor = this.game.add.sprite(0, 580, 'floor');	this.game.world.resize(this.bg.width, 780);	this._player.init(115, 660);},update : function(){	this._player.update(this._controller);        //This one right here - without it the player sprite would pass through the BG	this.game.physics.arcade.collide(this._player.sprite, this.bg,		function(){}, null, this);},

Anyway I guess that'll be the solution, still wondering if anyone else has made this style of game and what methods you might have gone with!

Link to comment
Share on other sites

I think that it's the good way of doing collisions. Yes you have to explicitly define the collisions because you could want some stuff not to collide (like arrows or coins for example). 

 

If you used a Tilemap, you could define the tiles you want the players to collide with and the ones not to collide with, which is very handy. It allows you to do more sophisticated maps (with bushes, lights, waterfalls etc. the player will be able to go through without colliding).

 

If you use Tiled (which is extremely easy to use), creating a Tilemap will be very straightforward and dead simple. And I also think that Phaser has improved mechanisms for calculating collisions with tilemaps.

 

With your code there isn't really a map for the moment, there are just sprites into an empty canvas. By setting the map sprite to immovable you 'fake' a map.

Link to comment
Share on other sites

Thanks for clarifying Skeptron! Yeah I've actually done some testing with Tiled/Tilemap collisions before, definitely the route I'd like to go. I think with this case I was just messed up between Arcade and P2 physics.

 

I think I might end up going with a mix between this 'fake' map technique and tilemap, the game I'm working on is actually a hack n' slash / point+click hybrid which will end up featuring detailed backdrops. But I'll definitely handle certain parts of it with a tilemap (like the floor) to reduce the amount of huge images involved.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...