Mouse / player to bound to an given area

Get help using Construct 2

Post » Fri May 27, 2016 4:13 am

I was wonder so im making a bullet hell type shooter. And I was wondering how can i bound the ship to an area where my UI is and not have the player to go off the game.

I know what bound to layout but this is within the given area. Is there some fancy footwork i can do this easily or do i have to create invisible solid sprite ?

Just a quick edit here I am using movement of mouse using everytick to mouse position is there something similar i can use so that the UI can be solids to do this with ?
Posts: 391
Reputation: 7,855

Post » Fri May 27, 2016 2:57 pm

For Keyboard movement - yes, just make a solid transparent sprite.

For Mouse movement - even with solid sprites, it will not work. But there is a way to make it.
Just edit your ship/player sprite. Click "resize", and now add to the width and height, pixel values of your "walls/UI", Then change "Image" to "align center" so your ship will not be stretched, check "apply to whole animation" and your almost done. Now you have bigger image, but your ship is same size as before, so just "set collision polygon" just for the ship and thats it. That empty space in your sprite will now be working like extra walls, so your ship cant leave that your speciffic area.

If every wall you have has diffrent width/height then just add value of each wall as blank/transparent pixels to your player sprite in photoshop or other program like this.

If you want see how it works, then look at my brickout/arkanoid clone: ... brick-7787
As you can see there, you move with mouse easly but you cant break thru the laser walls. (these are just simple sprites, not solid)
And here you can see how looks my ship/player sprite. As you can see I have some empty space on both sides of this sprite. This empty space is just as big as my walls, so with behavior "bound to layout" these empty space works like invisible solid walls :)

PS. Sorry for my english :P I hope you get the point :)
Posts: 5
Reputation: 2,669

Post » Fri May 27, 2016 3:57 pm

clamp(x, lower, upper)
Return lower if x is less than lower, upper if x is greater than upper, else return x.

sprite set x clamp(mousex,100,700) and same for sprite.y , makes it easy to contain a mouse controlled sprite movement .
What I know would fill a Book , what I don't know would fill a Library
Posts: 331
Reputation: 16,499

Return to How do I....?

Who is online

Users browsing this forum: dznerpro, ultrafop and 7 guests