I'm trying to figure out how to make the camera move like it does in the secret of mana. It seems to scroll with the player sprite but only if the player is within x distance of the game window edge. Here's a video to see what I mean.
Any idea how to do this? I can't figure it out.
You can use the viewport expressions to work it out, and have an invisible object with the scrollTo behaviour. So something like: distance(player.x,0,viewportLeft(0),0) < 200 = scroller move at angle: 180, 60*dt.
Hope that helps a little!
Just give the player the ScrollTo behaviour.
Tobye That's basically what I'm doing now and it's not working how I would expect (though I'll continue playing with it).
@plinkie I wish it were that easy. :)
It is that easy? If the player has 8-direction and you give him ScrollTo behaviour, the viewport will follow the player when he reaches the edge of the screen.
plinkie - With scrollTo on the player it will always scroll so he is in the centre. You could disable it until he is near an edge, but then when you re-enable it it would snap to him.
Here's one way: capx
You can also do what I said before with move at angle. Or you could use a behaviour that sets the angle of motion to the player and decelerates when it gets close, lots of ways really. Just need to detect the viewport's distance to the player.
Hope it helps!
Tobye Cool, that's closer then I was able to get. I'll keep tinkering! Thank you.
@plinkie Just using ScrollTo on its own the camera will always scroll with the sprite, not just when the sprite is near the edge of the game window.
Instead of using the scrollto behaviour in this case it's probably much better to use the system scrollto action, setting up events and conditions for when to scroll and when not.
There are ways to do this with even less events, but I made the events so they can be easily understood.
This example would actually work just as good with scrollto-behaviour, but the big advantage of the scrollto action is that it's easier to handle through events. It doesn't have to be every tick. Also, you don't have to use an object to scroll to, it could just be done with coordinates..
LittleStain Thank you! That's exactly what I've been trying to achieve. Would you be willing to share your optimization ideas (how to do it with less events/sprites etc as you mentioned).
Also, I see you answering peoples posts every day and I just wanted to say how appreciative the community is for people like you who are so willing to help us out. Thank you!
Thanks.. I know from my own experiences how helpful these forums can be.. I've learned most of the basics on here myself..
I'm on here almost every day, mostly inbetween creating my own stuff.. Helping others is a good way for taking a break from my own programming..
I'll see if I have time tomorrow to whip up another example for you..
Develop games in your browser. Powerful, performant & highly capable.
LittleStain That would be wonderful. Thank you very much.