GameMaker changing the depth of others, moving the right thing

nnn1czech

Member
Nice day.
(I do not know how much English - I translate in the translate.)

Please, how can I do it (dress up game):
1.) When I click on thing A, the other things (thing B, thing C ...) are under A. And when I click on B to put other things under it (thing A, C ...).

2.) It was moved with the thing that is the highest (currently moving with the thing below what is above).
Edit:
I mean, object A rises. Although there is an object B above it, over which is a mouse. As seen on the video, the object B does not move even if I want to drag it if there is an object A next to it. Instead, object A is selected.

In other words: In order to move any clothes. But only the one on which the mouse is (not something under)?

I use an event Draw GUI Begin to render an image. Object thing A is the parent of other things.

explanatory notes:
canclick clicking on a specific thing

object thing A
Event Left Down (mouse button)
Code:
if (canclick1 == 1)
{
    x = mouse_x;
    y = mouse_y;

    depth = -200;
    with (other)
    {
        depth = -100;
    }

    canclick2 = 0;
    canclick3 = 0;
...
}
 
Last edited:

nnn1czech

Member
:( it seemed to have solved both of them now I went back into the run mode and I found out that the other did not help the second question (maybe I went click to the right place where it worked)...
 
so your questionis how to place the objects to the puppet?

mark the center point of the body, then center your clothes sprite, then:

obj_A.x = puppet.x;
obj_A.y = puppet.y;
 

nnn1czech

Member
I meant the question number 2 in my opening commentary. In that he writes:
2.) It was moved with the thing that is the highest (currently moving with the thing below what is above).

I mean, object A rises. Although there is an object B above it, over which is a mouse. As seen on the video, the object B does not move even if I want to drag it if there is an object A next to it. Instead, object A is selected.

I hope this is understandable.
 
aaaah okay i see!!

in the objects you must say in the step event:

if depth==200 //your depth here
{
clickable = false;
}
else if depth==50 //your depth here
{
clickable=true;
}

and in the mouse click event:

f clickable == true
{

//your code here

}


that way you can check, that the player can actually click on the object (when its above the others)
 

nnn1czech

Member
I do not know, but does this "only" deal with the fact that when I click on a thing, it can not take another thing at the same time? (This is solved by the variable canclick.)

I tried to do it. Maybe I have something wrong. Because when I take a second dress, I can not move anything. So I do not know for sure what your code is doing.
 

nnn1czech

Member
obj_dress_A0 // parent of others dress
Event Left down (mouse button)
Code:
if global.clickable == true // your code
{
if (canclick1 == 1) // This variable name is different in every dress. It means clicking on a specific apparel. If canclick1 equals 1, this clothing can be lifted.
{
    x = mouse_x;
    y = mouse_y;

    global.top_dress = 1; // This variable is different in every dress. A little differently I done what you advised me. In another object* I have stated that if global.top_dress == 1, depth this object is 100. The depth of the others is 150

    canclick2 = 0; //Clicking on all other clothes is equal to 0 => can not be moved.
    canclick3 = 0; //Clicking on all other clothes is equal to 0 => can not be moved.
...
}
Event Step
Code:
if depth == 150
{
    global.clickable = false;
}
else if depth == 100
{
    global.clickable = true;
}
Event Left released
Code:
canclick1 = 1; // It means that all objects can be lifted.
canclick2 = 1; // -||-
canclick3 = 1; // -||-
...


*Another object
Event Create
Code:
global.clickable = 0;
global.top_dress = 0;
Event Step
Code:
if global.top_dress == 1
{
    with(obj_dress_A0)
    depth = 100;
    with(obj_dress_A1)
    depth = 150;
    with(obj_dress_A2)
    depth = 150;
    with(obj_dress_B0)
    depth = 150;
}

if global.top_dress == 2
{
    with(obj_dress_A0)
    depth = 150;
    with(obj_dress_A1)
    depth = 100;
    with(obj_dress_A2)
    depth = 150;
    with(obj_dress_B0)
    depth = 150;
}

if global.top_dress == 3
{
    with(obj_dress_A0)
    depth = 150;
    with(obj_dress_A1)
    depth = 150;
    with(obj_dress_A2)
    depth = 100;
    with(obj_dress_B0)
    depth = 150;
}
 
1.)
if you set the x and y position to mouse_x and mouse_y in the mouse event, this wil do basically nothing except shifting the object a tiny pinch..
after it is clicked, it should have something activated like: "active=true"
and in the step event you could say: if active==true {x=mouse_x; y=mouse_y;}

2.)
The way you are composing the codes for your game is really really hard to see through for me. actually some things don't quite seem to make sense...


you have 3 different apparel objects: obj_A, obj_B, obj_C.

in all of the objects left clicked event you'll say:

obj_A:

depth=100:
obj_B.depth=150;
obj_C.depth=150:
active=true;
obj_B.active=false;
obj_C.active=false;

obj_B:

depth=100:
obj_A.depth=150;
obj_C.depth=150:
active=true;
obj_A.active=false;
obj_C.active=false;

obj_C:

depth=100:
obj_A.depth=150;
obj_B.depth=150:
active=true;
obj_A.active=false;
obj_B.active=false;


------------
in their step events you'll say:

if active == true
{
x=mouse_x;
y=mouse_y;

if mouse_check_button_released(mb_left) && position_meeting(mouse_x,mouse_y,obj_puppet)
{
active=false;
x=obj_puppet.x;
y=obj_puppet.y;
}
}

try this so far. if you have any question or don't understand the code, please ask me. you need to understand it rather than copying it. and by the way: it's important to use = when giving a value to a variable and == when comparing two values.
 

nnn1czech

Member
Thank you, I'll try it now.. I have a disease that I'm having trouble with memories - like the problem of remembering new things. Moreover, I have not worked with GM for a long time. That's why I just copy most of the things.
 

nnn1czech

Member
Now it does this:
Things move more distances. And even now, it does not solve my second problem - I'm moving thing A that is under B thing. Instead of moving with B (which is on top).

(for inspection) I wrote this:
obj_A // parent of others
Create
Code:
var active;

Draw GUI Begin
// last time I forgot to write it
Code:
image_speed = 0;
draw_sprite(spr_A,0,x,y);
Left down
Code:
active = true;
obj_B.active = false;

depth = 100;
obj_B.depth = 150;
Step
Code:
if active == true
{
    x = mouse_x;
    y = mouse_y;

    if mouse_check_button_released(mb_left) // I do not need the code position_meeting (if I understand it well)
    {
    active = false;
    }
}
obj_B
Draw GUI Begin // last time I forgot to write it

Code:
image_speed = 0;
draw_sprite(spr_B,0,x,y);
Left Down
Code:
active = true;
obj_A.active = false;

depth = 100
obj_A.depth = 150;
In the room I tried to set the grid to 1, 1. It did not help
 
The position meeting checks whether you "release" the apparel on the doll or not. So you can't just throw it in the room.

And why do you even use draw gui?


Left down:

If depth == 100
{
Active == true;
}

EDIT: ADD IT TO YOUR STEP EVENT
 
Last edited:

nnn1czech

Member
Why I changed Draw to Draw GUI I'm not sure. I do not even know when to use the Draw GUI. Something I read about it (it was translated using an online translator), but I did not understand it. I just know that when I used Draw GUI (not Draw GUI Begin), the picture was somewhat angry. (but it could also be a coding error)

The code you are writing now (If depth == 100) would mean that it will move only with a matter that has a depth of 100. With nothing else. That would be a problem - I expect the player will want to give the doll more clothes (such as dresses and jewelery).
 

nnn1czech

Member
Can do it somehow what did I ask above? In other words: In order to move any clothes. But only the one on which the mouse is (not something under)?
 
Top