Page 1 of 1

Trouble with the View

PostPosted: Mon Oct 23, 2017 6:39 am
by DrakeStoel
OK, so I'm making a game, but I'm having some trouble with my dungeon type areas. What I would like to do in them is have the "view" actor stop following my player (who is currently the parent to "view") when it runs into the edge of the screen. I would then like it to continue following my player (as the "view"s parent) as normal after the player gets back to the centre of the view.

As an example, I'm specifically thinking of 2D Zelda games like Link to the Past.

What I've got set up right now is an actor called "viewCollide" that is a filled region the same size as "view". I've also got wire frame actors set up to serve as the edges of the room. When "viewCollide" hits the "edge," its a physical response to stop "viewCollide's" momentum. I've then got the view set up to start moving again after my player gets so far away from the "edge" actors.

Hopefully all that makes sense... If not, let me now and I'd love to clarify.
Any help would be greatly appreciated!

Thanks! :mrgreen:

Re: Trouble with the View

PostPosted: Mon Oct 23, 2017 7:45 am
by ITomi
Maybe you have to add the player's coordinates to the View in Draw event of View, without setting the player the parent of View (in that case if the "edge" object is a rectangle area). Then in the Draw event of View you need to check whether the new coordinates of View collide the edge of the screen.
Somehow in the Draw event of View:

Code: Select all
if (player.x<=(edge.x+edge.width/2)-view.width && player.x>=(edge.x-edge.width/2)+view.width)
{
 view.x=player.x;
}


And so on with the other coordinates.
If it is not work, please attach an example file, let me see it exactly.

Re: Trouble with the View

PostPosted: Mon Oct 23, 2017 5:54 pm
by DrakeStoel
Alright, I fiddled around with your code, but I got funny results. I'm not sure if it's just how it interacts with my own code, but it just didn't seem to do anything. So I've made a quick mockup of what my project looks like. This one is without your code, just to see what you think. :mrgreen:

Re: Trouble with the View

PostPosted: Mon Oct 23, 2017 8:47 pm
by Hares
ITomi wrote:Maybe you have to add the player's coordinates to the View in Draw event of View, without setting the player the parent of View (in that case if the "edge" object is a rectangle area). Then in the Draw event of View you need to check whether the new coordinates of View collide the edge of the screen.
Somehow in the Draw event of View:

Code: Select all
if (player.x<=(edge.x+edge.width/2)-view.width && player.x>=(edge.x-edge.width/2)+view.width)
{
 view.x=player.x;
}


And so on with the other coordinates.
If it is not work, please attach an example file, let me see it exactly.


The code seems to work fine.

DrakeStoel wrote:Alright, I fiddled around with your code, but I got funny results. I'm not sure if it's just how it interacts with my own code, but it just didn't seem to do anything. So I've made a quick mockup of what my project looks like. This one is without your code, just to see what you think. :mrgreen:


You should remove all your collisions, don't set the player as the parent for the view actor and just add Itomi's code to the draw event of the view actor.


Code: Select all
if (player.x>=(EdgeLeft.x+EdgeLeft.width/2)+view.width/2 && player.x<=(EdgeRight.x+EdgeRight.width/2)-view.width/2)
{
 view.x=player.x - view.width/2;
}

if (player.y<=(EdgeBottom.y-EdgeBottom.height/2)-view.height/2 && player.y>=(EdgeTop.y+EdgeTop.height/2)+view.height/2)
{
 view.y=player.y - view.height/2;
}

Re: Trouble with the View

PostPosted: Tue Oct 24, 2017 6:01 am
by DrakeStoel
Huh... You're right! It works great now. Thanks for your help!

Re: Trouble with the View

PostPosted: Tue Oct 24, 2017 7:04 am
by DrakeStoel
Actually, I've got an expansion question. I do not want this just to be limited to one room within this dungeon area. I'll set up the screen to scroll when you get to a doorway, but how do I make this effect follow the player? Each room is differently sized, so I cannot easily make the "edge" actors move without doing an individual code for each. I tried using clones, just resizing the wire frame for each room's edges, but that didn't work. Any suggestions?

Thanks!

Re: Trouble with the View

PostPosted: Tue Oct 24, 2017 6:54 pm
by Hares
For the edge actors, only one of their coordinates is important. For the left and right edges it is their x coordinate.
When you get to a door, just have a code change the coordinate of the edge so it fits the new room.

For example, the door is on the right side. When you reach the door, the right edge actor's x position is changed to a new value (making it move to the right edge of the new room).
When you have passed the door (plus halve the width of the view), make the left edge move to the position of the door.

The code that changes the coordinates of the edge actors does not have to be in an event of the edge actors, it can be executed from any another actor.

Hope this helps.

Re: Trouble with the View

PostPosted: Thu Oct 26, 2017 5:12 pm
by DrakeStoel
Thank you so much! My actual game is set up a little differently than that demo, so I had some additional fiddling to do, but your concept worked perfectly! Thank you both for your help.