Legacy GM [SOLVED] background_htiled Appears to be Ineffective

M

MrFlippy

Guest
Hello all!
After about two years of losing all game-making knowledge, I'm back on the forums!

Now that I'm back into GMS1.4, I'm struggling with something that I can't seem to find the answer to for as long as I've tried to find an answer inside and outside the forums.

I'm trying to create a scrolling background for my main menu that should tile only horizontally. In my draw event code, I can use draw_background_tiled(city,0,682) but this causes the background to tile both horizontally and vertically, which surely doesn't look pretty!

Furthermore, when I add background_htiled = true and/or background_vtiled = false to my create event, step event, or draw event, it does nothing whatsoever! Unfortunately I can't use the default room background settings for my game, so I'm forced to create and manipulate backgrounds from code.

Anything I can do here? Open to questions. Thanks, community! :-D
 

2Dcube

Member
background_htiled and vtiled apply to the background set to background_index, I believe.
You can also have multiple backgrounds with background_index[1], [2] etc and background_htiled[1], [2]...
 
M

MrFlippy

Guest
Thanks for your response, but let me ask you; how can I set the background to background_index properly?

I've actually tried to add background_index[0] = city in my create event, step event, AND draw event, and it doesn't seem to work with me. Of course, I'm doing something wrong, but I can't figure out what it is.

I now fully understand that background_htiled and background_vtiled only apply to a background in the background_index (thanks for that, this was also a concern I had!), but how would I (1) draw my background in code, (2) set my drawn background to background_index[0] so that I can (3) use background_htiled = true to get my background to tile only horizontally?
 
M

MrFlippy

Guest
Thanks! Though, that's not exactly the problem. My background is visible; that's good. My background is tiled; also good. But my background is also tiling vertically; that's where it's bad. I only need my background to tile horizontally. Here's the issue in a screenshot:
 

Attachments

W

Wraithious

Guest
You could just use the draw event and a loop and draw your background images stitched together horizontally, if you name your backgrounds like background0, background1... etc you could do:
Draw event:
Code:
for(i=0;i<number_of_backgrounds;i+=1;) {
draw_background(asset_get_index("your_background_name_w/o_number"+string(i)), x+ (your_background_width*i), y);
}
This way if you drag the object left or right that draws the backgrounds they will scroll left or right.
 
M

MrFlippy

Guest
Hey @Wraithious!

So, I only have one background (Bck_MenuCity_Day), and I used your code in Obj_MenuBackground's draw event this way:
Code:
for (i=0; i<3; i+=1;)
{
    draw_background(asset_get_index(Bck_MenuCity_Day+string(i)),1080*i,682);
}
And I get this error:
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Draw Event
for object Obj_MenuBackground:
DoAdd :: Execution Error
at gml_Object_Obj_MenuBackground_DrawEvent_1 (line 3) - draw_background(asset_get_index(Bck_MenuCity_Day+string(i)),1080*i,682);
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Object_Obj_MenuBackground_DrawEvent_1 (line 3)
So three questions I have are:
1) How can I fix this error?
2) Would this only 'loop' the background three times?
3) Is there any way to make it loop indefinitely?

Thanks. =)
 
W

Wraithious

Guest
@MrFlippy Ahh ok you only have 1 background, my code would work if more than 1 and if the background names are set up sequentially, so you could just do
Code:
for(i=0;i<ceil(room_width/your_background's_width);i+=1;) {
draw_background(Bck_MenuCity_Day, x+ (your_background_width*i), y);
}
That will repeatedly loop in the draw event and tile that single background accross the room.
 
M

MrFlippy

Guest
Oh my gosh, I owe you so much, you're a miracle right in front of my eyes! It works perfectly now and I can use hspeed to move the background. I can finally beat a deadline I had. :D

Thank you so much @Wraithious and others!
 
Top