PDA

View Full Version : Avoid stutter when scroll map



tiru
July 31st, 2009, 03:00 AM
Hi iam using following code to scroll map. when scrolling horizontal or vertical, it scrolls perfect without any jerk(stutter) but when scroll diagnol this stutter happens.



function scrollMap(){
var p = {x:0, y:0};
var minX=(stageW/2)-32;
var maxX=(stageW/2)+32;
var minY=(stageH/2)-32;
var maxY=(stageH/2)+32;
myAvatar.localToGlobal(p);
if (p.x<minX) {
if (avatarMC._x<-walkSpeed) {
avatarMC._x += walkSpeed;
}
} else if (p.x>maxX) {
if (avatarMC._x>-areaW+stageW+walkSpeed) {
avatarMC._x -= walkSpeed;
}
}
if (p.y<minY) {
if (avatarMC._y<-walkSpeed) {
avatarMC._y += walkSpeed;
}
} else if (p.y>maxY) {
if (avatarMC._y>-areaH+stageH+walkSpeed) {
avatarMC._y -= walkSpeed;
}
}
}


any help?

Thanks in advance.

acebuddy29
July 31st, 2009, 05:38 AM
Hi iam using following code to scroll map. when scrolling horizontal or vertical, it scrolls perfect without any jerk(stutter) but when scroll diagnol this stutter happens.



function scrollMap(){
var p = {x:0, y:0};
var minX=(stageW/2)-32;
var maxX=(stageW/2)+32;
var minY=(stageH/2)-32;
var maxY=(stageH/2)+32;
myAvatar.localToGlobal(p);
if (p.x<minX) {
if (avatarMC._x<-walkSpeed) {
avatarMC._x += walkSpeed;
}
} else if (p.x>maxX) {
if (avatarMC._x>-areaW+stageW+walkSpeed) {
avatarMC._x -= walkSpeed;
}
}
if (p.y<minY) {
if (avatarMC._y<-walkSpeed) {
avatarMC._y += walkSpeed;
}
} else if (p.y>maxY) {
if (avatarMC._y>-areaH+stageH+walkSpeed) {
avatarMC._y -= walkSpeed;
}
}
}
any help?

Thanks in advance.


its probably because the movieclip u r trying to move is too large in dimension and/or it is vector based. try converting ur vector art to bitmap(.png) and thn try using ur code. And using localToglobal onEnterframe is not a good idea. Also if possible post ur swf, so that we can know exactly what u r trying to move.

tiru
July 31st, 2009, 06:06 AM
hi thanks for reply.

i forgot to mention one thing.

in above function with these lines no stutter. the map moving smoothly. so there is no question of large in dimension or vector based.

no stutter

avatarMC._x += walkSpeed;
avatarMC._y += walkSpeed;


with these lines causing the stutter. i cant remove the conditions bcoz, the avatar needs to be center always.

with stutter

if (p.x<minX) {
if (avatarMC._x<-walkSpeed) {
avatarMC._x += walkSpeed;
}
} else if (p.x>maxX) {
if (avatarMC._x>-areaW+stageW+walkSpeed) {
avatarMC._x -= walkSpeed;
}
}
if (p.y<minY) {
if (avatarMC._y<-walkSpeed) {
avatarMC._y += walkSpeed;
}
} else if (p.y>maxY) {
if (avatarMC._y>-areaH+stageH+walkSpeed) {
avatarMC._y -= walkSpeed;
}
}

iam using jpg images for map. The above conditions to keep always player center of the map.I suspect only the above conditions causes the stutter, so how to avoid stutter with player always in center of the map.

any idea to avoid stutter?

Thanks.

justkevin
July 31st, 2009, 10:14 AM
Without seeing it in action, I can only speculate, but my guess is that it's pixel snapping. The background's displayed position is an integer value (i.e., x can be 3 or 4 but not 3.3). If you're moving along the x or y axis (or both axes equally) the background image moves smoothly. If your dx = 3 and your dy = 1, then on some frames the backround's y won't move when the x does.

Are you using scrollrect or masking to get the effect? Sometimes masking works better because masking preserves twip values, whereas scrollrect (for some reason) does not.