Moving Link around the screen ???

Started by
0 comments, last by JDUK 19 years, 4 months ago
Hi I'm currently working on a small game. I'm trying to achive a scrolling effect simliar to that of zelda link to the past on the SNES. The game is made up of surfaces 1024x768. The Window is 640x460. Now in zelda, when link moves, he tends to stay roughly in the center of the screen, and the window scrolls, until he gets near the end of a surface, then link begins to make his way towards the edge of the window. Once at the edge, the entire window scrolls 640 or 480 pixels depending on the direction. The link begins to move, and once he is in the center of the surface the window begins to scroll again, until that surface comes near an end. Does anyone have any ideas how to implement this?? My thoughts were to keep track of an offset, once link gets to the edge of the offset the window starts to scroll, until the surface reaches an end. Thats when link can move outside of the offset area, and towards the edge of the screen, once link reaches the edge of the screen, everything is scrolled 640 or 480.
Advertisement
Well your "veiw" of the worlds X&Y pos relative to the map will move every time you input directions just the same as links will.
When the user presses right: LinkPosX += 1;ScreenPosX+= 1;

just use if statments to see if the screen is at the level/map edge
i.e

if ScreenPosX > (LevelWidth-ScreenWidth) ScreenPosX = (LevelWidth-ScreenWidth);
if ScreenPosX < 0 ScreenPosX = 0;
if ScreenPosX > (LevelHeight-ScreenHeight) ScreenPosX = (LevelHeight-ScreenHeight);
if ScreenPosY < 0 ScreenPosY = 0;

now do exaclty the same for link:
if LinkPosX > (LevelWidth-LinkWidth) LinkPosX = (LevelWidth-LinkWidth);
if LinkPosX < 0 LinkPosX = 0;
if LinkPosX > (LevelHeight-LinkHeight) LinkPosX = (LevelHeight-LinkHeight);
if LinkPosY < 0 LinkPosY = 0;


The scren will hit and be stoped by the edge before link is and he will freely move around in a map corner while the screen remains still as he walks away the screen will regain freemovment.

EDIT/
Sorry didnt think this one through. Yes you will need to monitor by how much link is off centre screen so that the "veiw" either doesnt move until link is centre screen OR make link move faster than the screen until he hits centre screenso as to settle back in that position when the user starts moving.

youcould use some code in your screen set up thats sets:
if(LinkPosX!= ScreenWidth/2)ScreenScrollX = SlowMovment; // some number lower than is usual speed or replace with NoMovment
else ScreenScrollX = NormalMovment;
if(LinkPosY! = ScreenHeight/2)ScreenScrolly = SlowMovment;//or replace with NoMovment
else ScreenScrollY = NormalMovment;

Im not sure thats the best way but it's the 1st thing that suggests its self to me.

This topic is closed to new replies.

Advertisement