[SOLVED] Scrolling background as object

N

NGZKKYKZK46

Guest
Hello, i was wondering if its possible to make an object that im using as background to scroll and loop infinitely as when using normal backgrounds?

I tried when i imported the sprite checking the option that says Tile:Horizontal in texture settings and then in the Create->Step code of the object i set its speed to 2, but that didnt work.

What is the correct way of achieving this? Thanks for reading.
 
K

Kuro

Guest
Can you explain in a bit more detail what you're trying to do please? That's not a lot to go on.

And is there any particular reason why you want to use an object instead of do it in the backgrounds?

One more question; which version of gamemaker are you using?
 

DesArts

Member
If you want to tile a sprite horizontally, use this script to draw it.
Code:
///draw_sprite_tiled_horizontal(sprite,subimg,x,y)

    var left, right, step;    
    step = sprite_get_width(argument0);
    left = view_xview+((argument2-view_xview) mod step)-step;
    right = view_xview+view_wview+step;
    while (left < right)
    {
        draw_sprite(argument0, argument1, left, argument3);
        left += step;
    }
 
N

NGZKKYKZK46

Guest
Can you explain in a bit more detail what you're trying to do please? That's not a lot to go on.

And is there any particular reason why you want to use an object instead of do it in the backgrounds?

One more question; which version of gamemaker are you using?
Hello, i was trying to make an object that does the same function as when in backgrounds you check the Tile Horizontal setting and set its Horizontal speed to something. I need to use objects as backgrounds because at some point i need objects to be inbetween my backgrounds and if i did the backgrounds as backgrounds i cant tell their depth.
 
N

NGZKKYKZK46

Guest
If you want to tile a sprite horizontally, use this script to draw it.
Code:
///draw_sprite_tiled_horizontal(sprite,subimg,x,y)

    var left, right, step;   
    step = sprite_get_width(argument0);
    left = view_xview+((argument2-view_xview) mod step)-step;
    right = view_xview+view_wview+step;
    while (left < right)
    {
        draw_sprite(argument0, argument1, left, argument3);
        left += step;
    }
Hello, sorry, im very new to gamemaker, i dont understand this, where should i add it?
 
E

Edmanbosch

Guest
Hello, i was trying to make an object that does the same function as when in backgrounds you check the Tile Horizontal setting and set its Horizontal speed to something. I need to use objects as backgrounds because at some point i need objects to be inbetween my backgrounds and if i did the backgrounds as backgrounds i cant tell their depth.
What do you mean by "i cant tell their depth"?
 
N

NGZKKYKZK46

Guest
What do you mean by "i cant tell their depth"?
Yeah, if i need to make one object appear inbetween one background (lets say as example some mountains) and another (the sky) , i dont know what depth number should the object have. I found it easier and more controllable for me as a beginner to do it that way (having the backgrounds be objects where i can control their depth settings)
 
K

Kuro

Guest
The code Desix supplied can be put in a script. Just be sure to name the script:
'draw_sprite_tiled_horizontal'.

The once you have that code in a script, and have named the script, you can then call that code from your object. Assuming you have your object's image set to the sprite you want to use as a background.

You would do this adding draw event, and adding a run code box, and then typing in:
draw_sprite_tiled_horizontal(sprite_index,image_index,x,y);

I think that should work but I've not tested it, so I can't be 100% sure. If you have any problems getting it to work just let us know.
 
E

Edmanbosch

Guest
Yeah, if i need to make one object appear inbetween one background (lets say as example some mountains) and another (the sky) , i dont know what depth number should the object have. I found it easier and more controllable for me as a beginner to do it that way (having the backgrounds be objects where i can control their depth settings)
Well, which version of GameMaker are you using? If it is Studio: 1, then maybe the system mentioned above will have to do. If it is Studio 2, then just make multiple background layers, and order them in the way you want to.
 
N

NGZKKYKZK46

Guest
The code Desix supplied can be put in a script. Just be sure to name the script:
'draw_sprite_tiled_horizontal'.

The once you have that code in a script, and have named the script, you can then call that code from your object. Assuming you have your object's image set to the sprite you want to use as a background.

You would do this adding draw event, and adding a run code box, and then typing in:
draw_sprite_tiled_horizontal(sprite_index,image_index,x,y);

I think that should work but I've not tested it, so I can't be 100% sure. If you have any problems getting it to work just let us know.
Hello guys, sorry for the late answer , the script worked perfectly! Thank you everyone for the help!
 
K

kilnakorr

Guest
Reviving an old thread here.

Trying to get this to work, but failing.
Can someone explain what 'argument2' is supposed to be?
 
Top