[SOLVED] What may cause one instance to disappear when another is moved over it?

D

Dmitri Pisarenko

Guest
Hello!

I'm developing a simple card game with my child. In this game, you can move one instance of an object obj_card over another.

When this happens (one card is moved over another so that they overlap), one of the instances disappears from the screen.

How can I diagnose this issue? How can I fix it?

Is it possible that this happens because there is some error related to the z order?

Notes:

1. The instances are not destroyed (I put breakpoints into the "destroy" method and these breakpoints were not activated).
2. Both instances were created in the same layer (a layer "Cards" separate from the background and the instances layer).

Thanks in advance

Dmitri Pisarenko
 
D

Dmitri Pisarenko

Guest
> So are you saying this happens at any overlap?

I'm not sure, how many pixels need to overlap in order for this effect to occur. It definitely occurs when the overlap is large (i. e. 50 % of one card is covered by another).

> And when you move it away, the card reappears?

No, the card doesn't reappear. It's gone. Basically, it works like this:

1. Put card 1 on a green area (green area is a separate object).
2. Move card 2 so that it overlaps with card 1.
3. Now one of the cards disappears (I don't know which one -- card 1 or card 2 -- because they look the same).

In step 2 we had 2 cards, in step 3 and afterwards there is only one.
 

Simon Gust

Member
Sounds to me like the card below gets teleported under the card above and then it stays at the same position forever.
You said you're moving cards, maybe a peek into your code could help us resolve the issue.
 

spe

Member
I was thinking the same thing as @Simon Gust

The same thing happened in a little card game prototype I have. I had the cards snap into the right place on the screen, which would cause both cards to overlap exactly if there was more than one. Then, when I would pick up the card, it would pick up both at the same time, like they were stuck together, and you could never see the one on the bottom.

There may be a different issue entirely, but this is a good place to start in terms of the trial-and-error approach. Try adding some code into your game that allows you to only carry one card at a time. Perhaps you could store the unique instance ID of a card in a variable somewhere whenever you click on it, and only allow any card to move if its instance ID matches that variable. This way, it's impossible to move more than one card at once, as only one card can have that particular ID. If your cards are indeed being 'stuck together' when you try to move them, this should likely solve the issue.
 
D

Dmitri Pisarenko

Guest
Sounds to me like the card below gets teleported under the card above and then it stays at the same position forever.
You said you're moving cards, maybe a peek into your code could help us resolve the issue.
I don't have access to the code right now. As far as I remember, there are following methods in it (all methods of obj_card):

1) Left button click handler: Variable "isMoving" is set to true.

2) Step:

if (isMoving == true), then

2.1) Position is updated (the card is moved to the coordinates of the mouse)
2.2) Variable "overGA" (over green area) is updated (true, if the card is over a green are, false otherwise).

3) Left button release handler:

if (overGA), then

3.1) isMoving = false

else // the card is not over a green area

3.2) destroy the card.

This means that the user can drop the card only on a green area.
 
D

Dmitri Pisarenko

Guest
Sounds to me like the card below gets teleported under the card above and then it stays at the same position forever.
How could I test this hypothesis? What exactly happens when a card is "teleported"? Can I detect this by placing a breakpoint somewhere?
 

Simon Gust

Member
Never worked with breakpoints, but you could let the card display it's positions via draw GUI

DRAW GUI EVENT of anything that exists not more than once
Code:
var xx = 10;
var yy = 10;

with (obj_card)
{
   var c = c_red;
   if (isMoving) {
      c = c_green;
   }

   draw_text_colour(xx, yy,       x, c, c, c, c, 1);
   draw_text_colour(xx, yy+20, y, c, c, c, c, 1);

   yy += 40;
}
not pretty code but it should display the position of all cards.
The text is drawn red unless a card is in the isMoving state, in which case the text should appear green.
 
D

Dmitri Pisarenko

Guest
Many thanks, I'll try it out today in the evening.
 
N

NeonBits

Guest
1) Left button click handler: Variable "isMoving" is set to true. **
2) Step:
if (isMoving == true), then
2.1) Position is updated (the card is moved to the coordinates of the mouse) **
2.2) Variable "overGA" (over green area) is updated (true, if the card is over a green are, false otherwise).
3) Left button release handler:**
I'm not a good programmer but sometimes I see objects disapearing because I forget to refer to coordinates (x = obj instead of x = obj.x, etc). Your object follows the coordinates of the mouse when button is pressed; if you release the button, does it still know what destination to follow? Maybe coordinates disapear once button is released and so the object disapears?
 
D

Dmitri Pisarenko

Guest
I'm not a good programmer but sometimes I see objects disapearing because I forget to refer to coordinates (x = obj instead of x = obj.x, etc). Your object follows the coordinates of the mouse when button is pressed; if you release the button, does it still know what destination to follow? Maybe coordinates disapear once button is released and so the object disapears?
Thanks. That could well be the case. I'll check this hypothesis today in the evening.
 
Top