#Title Screen + Continuous Fade Transition

303 messages · Page 1 of 1 (latest)

pearl hatch
#

So I was following “How To Create A Main Menu In GameMaker” and my text managed to look like this. I inputted the exact same code as he stated, but yeah. Things went south.

As for the Fade transition from one room to another, I used the tutorial made by Matharoo. It works, but I want to know how to make that transition work for multiple rooms.

#

Also here’s the code for allowing it to go from Room1 to Room2

next compass
#

its most likely not the same code or in the same order

pearl hatch
#

So which line should valign and halign be in?

next compass
#

I'd look at the tutorial you're using to figure that out, but usually if you're changing the halign and valign, the text goes after that, not before that

pearl hatch
#

Ok I’ll get back to you asap

#

Also I was thinking for the fade transition I do a copy, but just change which room it’s transition to

#

Or

#

I would make the room an integer like room_i and every time they switch to one room the integer goes up, and keeps switching every time the player presses enter

#

🤷‍♀️

next compass
#

theres several ways to go about it; your best bet would be to make a function out of the code inside those brackets

#

if you don't want to use data structures, you can use a switch statement, like:

function room_switch()
{
  //the target room
  var target_room;
  //check what room we're currently in
  switch(room)
  {
    case rm_room_2:
        target_room = rm_room_3;
        fadeToRoom(target_room, 60, c_black);
        break;
  }
}
#

and put that room_switch() inside the brackets

pearl hatch
#

Ok so his code is like this. His output was middle, but mine was complete left.

next compass
#

yea so, see how the draw_text() call is after the halign and valigns?

pearl hatch
#

Yh

next compass
#

the bottom haligns and valigns calls reset the aligns, otherwise ALL further drawing will be aligned the same way, so they have to be reset

#

but since you had draw_text first, it isn't getting aligned properly

pearl hatch
#

Hm

#

Mmmmm

#

But when I put the exact same code in the video, it is the same result

next compass
#

your first pic doesn't show the same code though

pearl hatch
#

Oh right

next compass
pearl hatch
#

Let me send you the updated version

pearl hatch
#

Ok I think this is the same

next compass
#

you have your fa's reversed in some

#

like bottom valign should be fa_top, not the halign

pearl hatch
next compass
#

seems right

#

according to the video anyways

pearl hatch
#

Ok

#

This is what I got

#

:(((((

next compass
#

is this the same font used in the video? could be a font size difference

pearl hatch
#

I used a different font and size

next compass
#

I'd also say maybe the origin of your button sprites is different

pearl hatch
#

He made his own font but the size 40

#

Let me see what happens when I use 40

pearl hatch
next compass
#

yep, all things to consider

#

tutorials are very "by the book" so if something isn't working correctly, its usually some minor difference in code or in the assets

pearl hatch
#

Hm

#

I’m very by the book so I don’t blame

#

Ok

#

So I changed the size

#

And uh

#

In conclusion Level Up 1000 in respect to Game Devs

next compass
#

whats the origin of the sprites?

#

the button one? is it centered?

pearl hatch
#

The origin of the sprite is on the top left

next compass
#

what is it in the tutorial?

pearl hatch
#

OMG it’s Middle Centre!!!

#

How did I miss that

#

One step closer to being done, woohoo

next compass
#

nice, glad it worked pacha5

pearl hatch
#

Now we just need it to be in the middle

next compass
#

just move the buttons themselves

#

in the room editor, don't have to touch the code at all anymore

#

I take it these are buttons in the room right?

pearl hatch
#

You, my good sir

#

R a genius

#

Now all I need to do is try the transition code you gave me

next compass
#

just edit it to your needs, its pseudocode, so its not meant to work as is since I dont know your room names etc

pearl hatch
#

Good point

#

I'll update you abt what's happening to it

#

Ok so I don’t have a variable for room_switch

#

I think this code would be best to give you context so

next compass
#

no the function needs to go in a script asset

#

you're creating a custom function you can then call anywhere

#

once that function code is in a script you can then do:

if keyboard_check_pressed(vk_space) && !instance_exists(obj_fade)
{
  room_switch();
}
#

you don't NEED a function per se, but functions are chunks of re-usable code, in case you want to use that bit of code in other objects etc

pearl hatch
#

Ok so

#

When I want to start the game I press “enter”

#

To make the transition work I have to press “space”

#

The start screen = Room 1
Dark screen = Room 2

#

= Room 3

#

= Room 4

#

It’s not allowing me to move from Room 3 to Room 4

#

But allows me to go from Room 2 to Room 3

next compass
#

right, because you have to add a case for it

#

inside the switch

#

the switch is checking for what room you're currently in, but without a specific case telling it what to do in specific rooms, it wont do anything

next compass
pearl hatch
#

Hm I’m going to try and explain this

#

So

#

The code for Room 2 to Room 3 can work without the room switch

next compass
#

right, because your old code does that

#

the switch in the function is so you can handle as many rooms as you make, not just those two rooms

pearl hatch
#

Hmmmm

pearl hatch
next compass
#

in the room_switch function

#

inside the switch

pearl hatch
#

and the room_switch function should be in the script?

next compass
#

I take it this is your first time seeing a function and a switch though, so you may want to read up on those in the manual to fully understand them

#

yes

#

the whole function goes in a script asset

pearl hatch
#

But will try!

next compass
#

when you then do:

room_switch();

to call that function, you're telling gamemaker "hey, find this section of code in the script asset and run it"

pearl hatch
#

Ok wait I think I’m making myself slightly confused

next compass
#

oh how?

pearl hatch
#

The objective of the room switch is that when a player presses space, they move on to the next room - no problem right?

#

And since we do not have a variable called room_switch, we have to make one in the fade transition script

next compass
#

mmm so, a function is not a variable, its a chunk of code you execute

#

in this case, you named a function called room_switch

#

you know draw_text() right? thats a function

#

room_switch is a custom made function

#

the fade transition is most likely also a custom made function by whoever made it

pearl hatch
#

It is

next compass
#

so a script asset can hold as many functions as you want

pearl hatch
#

But it only applies to the transition between 2 rooms

next compass
#

the fadetoroom function accepts arguments, which tell it what room to go to

#

its not hard coded to just two rooms

#

thats why you're setting target_room to the room you want, and then putting targetroom in the function

pearl hatch
#

My brain cells trying to understand:

#

I can see why programming is a high-paying job

pearl hatch
next compass
#

yep, thats right

#

the first argument is the room you're going to

pearl hatch
#

Yeah

#

So we’re changing argument 0

#

?

next compass
#

yep, based on the room we're currently in with the switch statement

#

so this bit of code here:

switch(room)

checks what room you're currently in, and the cases are simply the rooms in your game

#

so lets say you're in room2; you have a case for it in the switch(room) so when you press space, you know what code to run to go to the next room

#

but if you're in room 3, you don't have a case for it yet, so GM doesn't know what to do

#

so if you add a case for room3, room4,room5,room6, etc, then it'll know what to do

pearl hatch
#

So what does var target_room do?

next compass
#

we're just setting the room to a local variable; in fact you don't even need it if you wanted to remove it, and just put the room name directly in the argument

#

is this GMS2 by the way?

pearl hatch
#

Yes

next compass
#

is this in a script? I dont see the above code in a function wrapper

#

the code above room_switch

pearl hatch
#

Alr let me take a better picture

next compass
#

what version of GM are you on? is it before 2.3?

#

if so, this function won't work for you then

pearl hatch
#

Hmmm

#

I’ll check

#

Not sure if this helps

next compass
#

yea it does, you're good then, but that fadetoroom script shouldn't work

#

which is weird

#

any code inside scripts need function wrappers now

#

if you just add:

function fadeToRoom()
{
  //copy all that code above room_switch here
}

you should be fine

pearl hatch
#

So do I completely remove the code from the script?

next compass
#

no you can just copy and paste it into it

#

or cut and paste, either works

#

you just want that code inside the function wrapper, which is what I wrote there

pearl hatch
#

Hm

#

Let’s hope it works

next compass
#

pretty much any code in scripts need to be inside of functions

#

as of v2.3+

#

older tutorials didn't use it, so some older tutorials may not work for you unless if you do this

#

anyways I do have to run now, but I'll check back later; you should definitely have enough info to do what you're wanting to do now, but I would check the manual to learn about functions and switch statements; if you still need more help, someone will probably come along and reply

nocturne kernelBOT
#

In a number of situations you want to let your instances perform different actions depending on a particular value. You can do this using a number of consecutive if / else statements, but when the possible choices gets above two or three it is usually easier to use the switch statement.

pearl hatch
#

Hmmm

pearl hatch
#

Unfortunately tho, it’s still not working 😅

pearl hatch
#

Ok

#

So

#

I am still strugglign

#

🙂

#

Please send help

#

Please 😭

#

@next compass

next compass
pearl hatch
#

OMG

#

OMGOMGOGMOGMGOMGOMGOMGOMGMOGOGMG

#

TOSH

#

TOSH

#

TOSHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

#

😭

#

I've literally been depressed for the last 5 hours

#

🤗

#

FUCK WRONG EMOJI

#

🫂

next compass
#

I thought you had fixed this actually lol, so whats the issue still?

pearl hatch
#

So

#

Uh

#

function room_switch()
{

switch(room)
{
case Room2:
targetRoom = Room3;
fadeToRoom(targetRoom);
break;

case Room3:
targetRoom = Room4
fadeToRoom(targetRoom);
break;

}
}

#

I added that

#

And when I press space a 2nd time it just stays in the same room

next compass
#

can you share your current code?

nocturne kernelBOT
#
You can format your code by encapsulating it within three backticks before and after

```
show_debug_message("I'm formatted!");
```

The above example displays:

show_debug_message("I'm formatted!");

The backtick key can be found above the TAB key on most keyboards.

pearl hatch
#

Cool cool

next compass
#

so yea, need to see the code you're using in step event

pearl hatch
#

Ohhhh gotchu

next compass
#

its better if you paste the code here and format it with the example above

pearl hatch
#

Gotchu

#

if (state == 0) {
timer++

// Change room 
if (timer >= duration) {
    room_goto(targetRoom);
    
    //Set state 
    state = 1;
}

}
//Exit state
else if (state == 1) {
timer--;

//Destroy 
if (timer <= 0) {
    instance_destroy();
}

}

//Set alpha
alpha = timer/duration;

next compass
#

yea follow the example above to format it with backticks

#

so its readable

#

also what object and event is this in?

#

is this all the code in that event?

pearl hatch
#

This is in the obj_fade, in the Step Event

#

Basically the thing that makes the fade work

next compass
#

right but you said you press space to do something, but I dont see any code here for spacebar

pearl hatch
#

Oh wait I think I'm getting myself confused

#

So there's an obj_fade and an obj_controlelr

#

obj_controller sry

#

obj_controller, step event:

#

if (keyboard_check_pressed(vk_space) && !instance_exists(obj_fade)) {
//Target Room
var _targetRoom = Room3;

if (room == Room2) _targetRoom = Room3;

//Fade
fadeToRoom( _targetRoom,60, c_black);

}

if keyboard_check_pressed(vk_space) && !instance_exists(obj_fade)
{
room_switch();
}

next compass
#

yea you gotta format your code here on discord so its readable please

#
if (keyboard_check_pressed(vk_space) && !instance_exists(obj_fade)) {
    //Target Room
    var _targetRoom = Room3;

    if (room == Room2) _targetRoom = Room3;

    //Fade
    fadeToRoom( _targetRoom,60, c_black);
}

if keyboard_check_pressed(vk_space) && !instance_exists(obj_fade)
{
  room_switch();
}

like this

pearl hatch
#

Sorry my connection momentarily disconnected

next compass
#

so you're saying when you press space it makes another fade object?

#

or wait, it doesn't change rooms you said?

next compass
pearl hatch
pearl hatch
next compass
pearl hatch
#

Ok well the problem is, is that it's not allowing me to transition from 1 room to another

next compass
#

but what is it doing then?

#

does it fade at all?

#

cause I'm not sure what that state machine is supposed to be doing since the function is supposed to be handling the fade effect already

#

or is that state machine inside of obj_fade?

#

I gotta run soon so, I'll check back later if you add more info and I'm around then

#

its best if you share ALL your code here, and explain what is going wrong; if theres no info to work with, people can't help even if they want to

pearl hatch
#

Apologies

#

I didn't expect the internet to go down again

#

Good point

#

Ok so

#

Let me send you the tutorial

#
var _dur = argument[1];
var _color = argument[2];

//Create 
var _inst = instance_create_depth(0, 0, 0, obj_fade);

//Set properties 
with (_inst) {
    targetRoom = _room; 
    duration = _dur; 
    color = _color;
}

function room_switch()
{

  switch(room)
  {
    case Room2:
        targetRoom = Room3;
        fadeToRoom(targetRoom);
        break;
        
    case Room3:
    targetRoom = Room4
    fadeToRoom(targetRoom);
    break;
  }
}
    ```
#

That's the script fadeToRoom

#

obj_fade, Step event:

#
    timer++
    
    // Change room 
    if (timer >= duration) {
        room_goto(targetRoom);
        
        //Set state 
        state = 1;
    }
}
//Exit state 
else if (state == 1) {
    timer--;
    
    //Destroy 
    if (timer <= 0) {
        instance_destroy();
    }
}


//Set alpha
alpha = timer/duration; ```
#

obj_fade, Draw GUI event:

#
var _guiH = display_get_gui_height();

//Draw fade 
draw_set_alpha(alpha);
draw_set_color(color);

draw_rectangle(0, 0, _guiW , _guiH , 0);

draw_set_alpha(1);
draw_set_color(c_black);```
#

obj_controller, Step event:

#
var _guiH = display_get_gui_height();

//Draw fade 
draw_set_alpha(alpha);
draw_set_color(color);

draw_rectangle(0, 0, _guiW , _guiH , 0);

draw_set_alpha(1);
draw_set_color(c_black);```
next compass
pearl hatch
#

function{fadetoRoom} ?

#

OMG

#

IT'S TOSH

#

YOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO

#

🥹

next compass
pearl hatch
#

❤️

next compass
#
function fadeToRoom()
{
  var _room = argument[0];
  var _dur = argument[1];
  var _color = argument[2];

  //Create 
  var _inst = instance_create_depth(0, 0, 0, obj_fade);

  //Set properties 
  with (_inst) {
    targetRoom = _room; 
    duration = _dur; 
    color = _color;
  }
}
#

try it again once you have this wrapped in its own function

pearl hatch
#

Script: fadeToRoom at line 38 : got '' expected '}'

#

Does that mean I should've added

#

Wait

#

Ok I fixed the error

#

Ok so

#

Still not transitioning through multiple rooms

next compass
#

this is in create?

#

looks like the same code as the script

pearl hatch
#

Yeah my bad

#

obj_fade, Create event:

#
duration = 420;
targetRoom = room;
color = c_black;

//Vars 
timer = 0;
alpha = 0;
state = 0;```
next compass
pearl hatch
#

Like it can go from Room 1 -> Room 2

#

But not Room 2 -> Room 3

next compass
#

so it DOES work, just not for anything other than room1 to room 2 then

#

so can you confirm it works like that right now before we try some other stuff? that room1 -> room 2 works but not other rooms?

#

also where are you calling room_switch? is this the code still?

if (keyboard_check_pressed(vk_space) && !instance_exists(obj_fade)) {
    //Target Room
    var _targetRoom = Room3;

    if (room == Room2) _targetRoom = Room3;

    //Fade
    fadeToRoom( _targetRoom,60, c_black);
}

if keyboard_check_pressed(vk_space) && !instance_exists(obj_fade)
{
  room_switch();
}

because this is most likely the issue

#

you have two keypress checks here, when it should only be the bottom one

pearl hatch
pearl hatch
#

But they told me to delete it completely which made an error

#

Also brb

next compass
#

try it with only:

if keyboard_check_pressed(vk_space) && !instance_exists(obj_fade)
{
  room_switch();
}
pearl hatch
#

I've returned

#

OMG

#

OMG

#

OMGOMGOGMGMOGM

#

IT WORKED!!!

#

Now how on earth do I do it for other rooms?

#

Oh wait I do the case argument

#

Let me see if it works

#

Ok so

#

I'm not sure how to space it out

#
{

  switch(room)
  {
    case Room2:
        targetRoom = Room3;
        fadeToRoom(targetRoom, 60, c_black);
        break;
  }

    case Room3:
    targetRoom = Room4
    fadeToRoom(targetRoom, 60, c_black);
    break;
    
    }
    
    case Room4;
    targetRoom = Room5
    fadeToRoom(targetRoom, 60, c_black);
    break;
  }
}```
next compass
#

all the cases have to be inside the switch brackets, they dont need brackets of their own

next compass
pearl hatch
#
{

  switch(room)
  {
    case Room2:
        targetRoom = Room3;
        fadeToRoom(targetRoom, 60, c_black);
        break;
 
    case Room3:
    targetRoom = Room4
    fadeToRoom(targetRoom, 60, c_black);
    break;
  
    case Room4;
    targetRoom = Room5
    fadeToRoom(targetRoom, 60, c_black);
    break;
  }
}```
#

It's still giving me a syntax error

#

on "case Room 4"

#

and the 2nd to last bracket

next compass
#

also show the entire script as it is right now

pearl hatch
#

Ok

#

Also sorry I really gtg

#

But Tysm 4 helping me!