Jump to content

Invisible Walls


Recommended Posts

Hi there,


Myself and a few friends are currently working on developing a game for our website. The game is an aerial view (top down).

We have created a background image to serve as the map but this image already includes all the walls for our game.


Ideally, we want to be able to create invisible walls within the game that match up to the same position as they are shown in the background image. It is fairly easy to determine these coordinates just by using an image editor.


Reading online, some people have suggested simply creating a sprite without attaching a background image. We were trying this out yesterday, but were unable to give the invisible sprite a width and height (this would normally be taken care of by the sprites image dimensions) so it effectively did nothing.


We're wanting to know if it's possible to create invisible walls or if we will need to create new wall image manually using our existing background image.


We tried...

x = phaser.add.sprite(0, 1150);

x.scale.x = 450
x.scale.y = 5
We also tried...
x = wizGame.phaser.add.sprite(0, 1150);
x.body.width = 450
x.body.height = 5
Are we just changing the wrong variables?


Link to comment
Share on other sites

Add a sprite with an image. It can be a simple one colour image. Small size say 8x8 pixels. Add it to the game four times. Scale and position them as needed. When happy,set each sprite.alpha = 0 and then it will become entirely transparent.


Thats wasteful, just add the sprite without the image, its how i do it. if you have many many walls and they all rendering with a 0 alpha its gonna cause a load time and maybe lag depending on how many etc.


Load the spirte as normal, give it physics body enablement and set the collide. Set the scale X/Y to your liking and it should be fine. 


for an example heres a one i actually use:

pausePlatform = this.add.sprite(player.x - 5, player.y + 13);pausePlatform.body.immovable = true;pausePlatform.collideWorldBounds = true;pausePlatform.allowGravity = false;

As you see i have no image associated with the platform but it has a physics body and collides etc.

Link to comment
Share on other sites

True it wouldnt be ideal if there are lots of walls, but his scenario sounded quite simple, four walls.


So when you create an imageless sprite, does it have a size of 1 by 1 pixels?

And then the scale x and y values end up as the actual pixel size? ie sprite.scale.x = 100 means it will be 100 pixels wide (1px x 100)


I suppose for positioning, you can just turn on body debug too.

Link to comment
Share on other sites

Yeah just use the body debug info you need. I don't use any scaling on my invisible platform but im sure you can debug the body info and see what the sizes are etc.

pausePlatform.body.debug = true;

Would be done like that if you don't use the render function.


Or in the OP's case

x = phaser.add.sprite(0, 1150);x.body.debug = true;
Link to comment
Share on other sites


  • Recently Browsing   0 members

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