Jump to content


Photo

Changing Depth when Slected


Best Answer thegame, 29 March 2016 - 03:02 AM

Just use the depth variable. It is local to each instance, so this is the one you want.

/** Left pressed **/
///Select  Object
if (global.canSelect) {

    selected = true;
    with(obj_colour_parent) {
        depth = -1; // Put all colours behind
    }
    // Now put this one in front
    depth = -2;
}
Go to the full post


  • Please log in to reply
2 replies to this topic

#1 BoxCar35

BoxCar35

    GMC Member

  • GMC Member
  • 56 posts
  • Version:GM:Studio

Posted 29 March 2016 - 02:45 AM

Hi I am trying to make a puzzle game where you select different coloured blocks with a mouse and put them in the right spot.

 

The code I used for selecting, moving and 'dropping' I found here:

 

 https://www.youtube....eature=youtu.be

 

and is as follows:

 

Information about object: obj_colour_parent

Sprite:
Solid: false
Visible: true
Depth: -1
Persistent: false
Parent:

Children
obj_blue
obj_green
obj_yellow
obj_orange
obj_red
obj_purple
Mask:
No Physics Object
Create Event:
execute code:

/// Setup

selected = false;
global.canSelect = true;
Step Event:
execute code:

/// Move object

if (selected = true)
{
    x=mouse_x
    y=mouse_y
    global.canSelect = false
    
}

Mouse Event for Left Pressed:
execute code:

///Select  Object
if (global.canSelect)

selected = true;


Mouse Event for Glob Left Released:
execute code:

/// Release Select

selected = false
global.canSelect = true

I then made this object the parent for all my coloured blocks. What I want to happen is that when I am moving the block the depth changes so it is 'above' all the others (basically moving from -1 to -2)

I have tried a variety of object_set_depth in mouse buttons events and step events in both the parent object as well as the individual coloured objs. I also tried changing the selected variable to global and then doing if Selected = true { object_set_depth blah blah} in the individual colours as well but still nothing. 

 

 I dont know what to do. Where am I going wrong?

 

 


  • 0

#2 thegame

thegame

    OinkIguana

  • GMC Member
  • 1549 posts
  • Version:GM:Studio

Posted 29 March 2016 - 03:02 AM   Best Answer

Just use the depth variable. It is local to each instance, so this is the one you want.

/** Left pressed **/
///Select  Object
if (global.canSelect) {

    selected = true;
    with(obj_colour_parent) {
        depth = -1; // Put all colours behind
    }
    // Now put this one in front
    depth = -2;
}

  • 0

Examples: Inventory and Shop Example ||| Dialog System with messages, questions, input and more ||| Old dialog box example (May not work in new versions of GM:Studio)
Jam Games: 11: Abby and Elliot - 21st place ||| 12: Forks - 16th place ||| 13: White - 19th place
Completed games: White


#3 BoxCar35

BoxCar35

    GMC Member

  • GMC Member
  • 56 posts
  • Version:GM:Studio

Posted 29 March 2016 - 04:03 AM

Thank you so much!  

 

Works perfectly I was unaware of 'with' 


  • 0