character actions with eBlock stop scrolling background

Started by KiraHaraReturns, Wed 13/02/2019 14:40:32

Previous topic - Next topic

KiraHaraReturns

I have some issues with making my character walk and pick up an object while scrolling the parallax background.
- the game resolution is 428 px in width but the background is 320 px (the remaining space is a GUI), therefore I fixed it with SetViewPort depending on the character's X-position.
- there is a parallax scrolling background which works pretty well
The problem appears when the character is doing something. Blocking stops the scrolling, and NoBlock runs the functions at once. What I need is making the character go to position xy and then pick up an object (change view etc), do you have any suggestions? I think, there is a solution using the rooms repeatedly_execute function but in my opinion, that's quite inconvenient.

morganw

Quote from: KiraHaraReturns on Wed 13/02/2019 14:40:32I fixed it with SetViewPort depending on the character's X-position
Where are you calling the code that does this?
If it is in repeatedly_execute or room_RepExec it would probably work to use repeatedly_execute_always instead.

KiraHaraReturns

#2
Quote from: morganw on Wed 13/02/2019 15:30:05
Quote from: KiraHaraReturns on Wed 13/02/2019 14:40:32I fixed it with SetViewPort depending on the character's X-position
Where are you calling the code that does this?
If it is in repeatedly_execute or room_RepExec it would probably work to use repeatedly_execute_always instead.
I put it in the global script's room_RepExec function, putting it in repeatedly_execute_always helped. THANX!, now I have to solve the problem with the parallax scrolling, the function is object-related and in the room-script

edit: problem solved, simple but effective


function repeatedly_execute_always() {
 
  if(player.x > gTextBar.Width/2){
        SetViewport(cBrick.x -gTextBar.Width/2, 0);
        }
 
  if(Room.GetProperty("parallax") && object[0].Name == "sky"){
        object[0].X = GetViewportX()/2;
        }
}


Khris

Just add a function called repeatedly_execute_always to your room script, and it will get called.
Move all your parallax / viewport code for the room in there.

Room-specific code shoudn't be in the global script, and it usually doesn't have to be. Other functions that will just work without linking them are on_mouse_click and on_key_press.

(And just for reference: if you must put room-specific code in the global script (using on_event would be an example), simply wrap your code: if (player.Room == 3) { ... })

KiraHaraReturns

#4
@Khris
thank you for the suggestion, but I like the function to be global, it's in a if-loop now and is going to be activated when the room property is appropriate. I hope this will be fine now, if not I will follow your advice


function repeatedly_execute_always() {
 
  if(Room.GetProperty("parallax")){
        if(player.x > gTextBar.Width/2){
        SetViewport(cBrick.x -gTextBar.Width/2, 0);
        }
       
        if(object[0].Name == "sky"){
        object[0].X = GetViewportX()/2;
        }
    }

SMF spam blocked by CleanTalk