PDA

View Full Version : Scroll 2 Div's at the same time



BlitZa
11-12-2009, 04:00 PM
Hello, sorry to bother you all :p - I am quite new to javascript, i have found an engine that i would like to edit, in the following javascript code, it will contain code on moving a player to the left, what i want is for every 32px it moves the player left, i want it to also to scroll the map at the same time (it's all contained in a div called "global_map") - Please help me, i am in urgent need of help please and thank you guys!


function player_move_left(user_id, bloc_id, charaset, prefix)
{
var player_id = prefix + user_id;
var next_left_pos = Math.round((parseInt(document.getElementById(player_id).style.left) - tile_size + player[user_id].left_gain) / tile_size);
var next_top_pos = Math.round((parseInt(document.getElementById(player_id).style.top) + player[user_id].top_gain) / tile_size);
//var next_lower_bloc = 'l' + next_left_pos + '-' + next_top_pos;
//var next_upper_bloc = 'u' + next_left_pos + '-' + next_top_pos;
var next_event_bloc = 'i' + next_left_pos + '-' + next_top_pos;

if ( map_pass[next_top_pos][next_left_pos] )
{
if ( user_id == my_user_id )
{
move_update(bloc_id, -1, 0);
}
document.getElementById('charaset_' + user_id).style.top = -player[user_id].height + 'px';
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[1] + ') + \'px\';', 62);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[2] + ') + \'px\';', 125);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[3] + ') + \'px\';', 187);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[4] + ') + \'px\';', 250);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[5] + ') + \'px\';', 312);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[6] + ') + \'px\';', 375);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[7] + ') + \'px\';', 437);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[8] + ') + \'px\';', 500);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[9] + ') + \'px\';', 562);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[10] + ') + \'px\';', 625);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[11] + ') + \'px\';', 687);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[12] + ') + \'px\';', 750);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[13] + ') + \'px\';', 812);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[14] + ') + \'px\';', 875);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[15] + ') + \'px\';', 937);
setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[16] + ') + \'px\';', 1000);
setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + player[user_id].width + 'px\';', 63);
setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + (player[user_id].width * 2) + 'px\';', 188);
setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + (player[user_id].width * 3) + 'px\';', 313);
setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'0px\';', 438);
setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + player[user_id].width + 'px\';', 563);
setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + (player[user_id].width * 2) + 'px\';', 688);
setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + (player[user_id].width * 3) + 'px\';', 813);
setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'0px\';', 938);

/*if ( (parseInt(document.getElementById(player_id).style.left) - tile_size + player[user_id].left_gain) > parseInt(document.getElementById(bloc_id).style.left) )
{
setTimeout('player_move_left(\'' + user_id + '\', \'' + bloc_id + '\', \'' + charaset + '\', \'' + prefix + '\')', 1000);
}
else
{*/
if ( prefix == 'p' )
{
if ( user_id == my_user_id && events_placement[next_top_pos][next_left_pos][0].length > 0 )
{
if ( path_finished )
{
setTimeout('exec_event(' + user_id + ', ' + next_left_pos + ', ' + next_top_pos + ', 0);', 1000);
}
}
else
{
setTimeout('player[' + user_id + '].moving = false;', 1000);
}
}
/*}*/
}
else
{
document.getElementById('charaset_' + user_id).style.top = -player[user_id].height + 'px';
if ( prefix == 'p' )
{
if ( user_id == my_user_id && events_placement[next_top_pos][next_left_pos][1].length > 0 )
{
if ( event_data[next_event_bloc].changedir )
{
document.getElementById('charaset_' + next_event_bloc).style.top = '-' + (parseInt(document.getElementById('charaset_' + next_event_bloc).style.height) / 2) + 'px';
}

if ( user_id == my_user_id )
{
move_update(bloc_id, 0, 0);
}
exec_event(user_id, next_left_pos, next_top_pos, 1);
}
else
{
player[user_id].moving = false;
}
}
}
}

If you still don't get what i am asking for (which i appreciate!) is that i want to know how to scroll 2 things at the same time (the player div and the global_map div)

BlitZa
11-12-2009, 10:45 PM
*BUMP* PLease guys, it's important. :confused: