[SOLVED]Sprites & Instances acting weird | Problem with movement using onscreen arrow keys [GML]

Yumeito

Member
Hi,

This is my very first original project. I'm making an Android game(haven't purchased pro/module yet but will do it as soon as I have successfully completed this games prototype) and wish to complete(full game) it by October. But since I'm a newbie this EPIC game idea that I have in mind and been working on for a couple of weeks now has proven to be EXTREMELY CHALLENGING. I really want to make this game see the light of day.

So now here's my problem.

1)
When I move the instance over others after I spawn them into the room some of them appear below the others. All the dominosthat are spawned into the room has got exactly the same properties too but this still happens and it will affect my game. Check out this video to see what I'm talking about.

It appears that obj_front is always in front of all the other dominos even though all of them has the depth set to 0. here's a small part of the scr_moving_dominos that is responsible for the mouse movement.

Code:
if(instance_position(mouse_x, mouse_y, obj_front))
{
    with(instance_position(mouse_x, mouse_y, obj_front))
        {
            //Move the dominos with mouse.
            x = mouse_x;
            y = mouse_y;

            //Enlarge dominos
            scr_size_changer();
        }
}
else if(instance_position(mouse_x, mouse_y, obj_back))
{
    with(instance_position(mouse_x, mouse_y, obj_back))
        {
            //Move the dominos with mouse.
            x = mouse_x;
            y = mouse_y;

            //Enlarge dominos
            scr_size_changer();
        }
}
In the above code it starts of with obj_front which is the domino with the white dot in front as seen in the video. And the others are all separated by an else if . I have only shown the else if for obj_back and it's the same for all the others in the video. There is no code in any of the domino objects. They all have one parent and it's called obj_domino_controller and this is its step event .

Code:
///Controls the dominos

x = clamp(x, 15, 525);
y = clamp(y, 20, 610);


//Moving dominos
if(mouse_check_button(mb_left))
{
    scr_moving_dominos();
}
else
{
    image_xscale = 1;
    image_yscale = 1;
}
Could anyone tell me why some of the dominos appear on top of another? I think the problem is in the scr_moving_dominos. If you think there's nothing wrong here I'll post the code that is inside the buttons that spawn the dominos as well.

2)
Problem 2 is actually a continuation of problem #1. As you have already seen(from the above video) that not only that the dominos appear below some others but when I go through others my controls move to the domino that is over me. I don't know if I worded that right. But please watch the video - it's the same one above, you'll understand. Please tell me how to fix this.

3)
Problem 3 is completely different from the above two and it is about controlling/moving the dominos with those on screen arrows. As I have already said my end goal is an Android game...so I need these arrows to work. Here's what all I have tried so far and all have failed...

  • First I tried commenting out the the code in the obj_domino_controller (where the scr_moving_dominos is called). And then I added the following to the step event of the obj_arrow_up :


    Code:
      ///Moving dominos when pressed
      if(point_in_rectangle(mouse_x, mouse_y, 387, 657, 450, 721))
      {
        if(mouse_check_button_pressed(mb_left))
         {
            if(instance_exists(obj_front))
                {
                    with(obj_front)
                        {
                           y = -5;
                           break;
                        }
                }
        }
    }
this simply moved the dominos(obj_front) all the up to the top of the screen where it is clamped.

  • I think I need to use the function move_towards_point or move_snap here...but I can't figure how to implement them...
What I actually need is I simply want the dominos to move a certain pixels(lets say 5) to the top/left/right/down when the corresponding button is pressed. I want to get rid of the mouse controls(I know how to do this) as seen in the above video and make that arrow controls. Please help me with this.

Thank you for your help in advance.
 
Last edited:
T

TheMatrixHasMe

Guest
look at the y = -5. Did you mean to put y -= 5? Are you trying to just move five pixels?

Also, depth and draw order are what effects the appearance of your objects. If they are the same depth then the one that is drawn last will appear in front. Try to re work your system to use depth, maybe assign the y coordinate to the depth?

example: depth = -y (in step event)
 
Last edited by a moderator:
W

wagyu_so_gud

Guest
var inst_obj_front = instance_position(mouse_x, mouse_y, obj_front);
var inst_obj_back = instance_position(mouse_x, mouse_y, obj_back);

if (inst_obj_front != noone) && can_move == -1
{
with (inst_obj_front)
{
//Move the dominos with mouse.
x = mouse_x;
y = mouse_y;

//Enlarge dominos
scr_size_changer();
}
can_move = 1;
}
else if (inst_obj_back != noone) && can_move == -1
{
with (inst_obj_back)
{
//Move the dominos with mouse.
x = mouse_x;
y = mouse_y;

//Enlarge dominos
scr_size_changer();
}
can_move = 1;
}

1)
my suspicion is that when you are holding an object and you hover over another obj, it reads the 'else if' statement that follows and registers it true (thus moving the obj). One way to alleviate that is if you add an instance variable (ex. can_move). In the create event, initialize it as a -1. In the example code above, when you've picked something up, can_move = 1. This indicates you can no longer pick anything else up. Once you've released the obj, remember to return it (can_move) back to -1 so you can pick up another obj.

2)
Might be related to 1. Solve 1. Then reevaluate 2.


3)
I recommend using the keyboard keys and getting it to do what you want it to do first. Then, look in to virtual keys as a one possible solution:
  1. virtual_key_add
  2. virtual_key_show
  3. virtual_key_hide
  4. virtual_key_delete
 
Top