HTML5 instance_destory difference between desktop and HTML5

Discussion in 'Programming' started by oliverr, Jan 11, 2019.

Tags:
  1. oliverr

    oliverr Member

    Joined:
    Feb 24, 2018
    Posts:
    21
    Hi,

    I'm not sure if this is a bug or I am doing something incorrectly. Simple click and destroy instance code. Works as expected on desktop, but not in HTML export:

    Desktop


    HTML


    2 objects, one to track the click and movement of the arrow, the other to just remove the instance of the created circle. Any help would be much appreciated!

    The problem seems to relate to the instance_destory() in the obj_click_point step event. It's as if it is looking for the id of the object after it has been destroyed.

    obj_arrow:
    Code:
    //Create event:
    
    easingAmount = 0.01;
    clicked_x = 0;
    clicked_y = 0;
    target_angle = 0;
    target_object = "null";
    
    
    Code:
    //Step event:
    
    if (mouse_check_button_pressed(mb_any)) {
        clicked_x = mouse_x;
        clicked_y = mouse_y;
        var new_object = instance_create_layer(mouse_x, mouse_y, "Instances", obj_click_point);
        target_angle = point_direction(x, y, mouse_x, mouse_y);
        target_object = new_object.id;
    }
    
    if (target_object) {
        //distance
        var xDistance = target_object.x - x;
        var yDistance = target_object.y - y;
        var distance = sqrt(xDistance * xDistance + yDistance * yDistance);
        if (distance > 150) {
            x += xDistance * easingAmount;
            y += yDistance * easingAmount;
        } else {
            x += xDistance * 0.05;
            y += yDistance * 0.05;
        }
        
        //angle
        var anglediff = angle_difference(image_angle, target_angle);
        //incrementally change image angle
        var pd = point_direction(x, y, target_object.x, target_object.y);
        var dd = angle_difference(image_angle, pd);
        image_angle -= min(abs(dd), 10) * sign(dd) * 0.5;
    }
    
    obj_click_point
    Code:
    //Step event:
    
    if(place_meeting(x,y,obj_arrow)){
    
    score += 1;
    
    instance_destroy();
    
    //set the new target as the nearest point
    
    obj_arrow.target_object = instance_nearest(obj_arrow.x, obj_arrow.y, obj_click_point);
    
    }
    
     
  2. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,632
    First off, set target_object to noone by default. You're setting it to a string and it's possible HTML5 hates it when you change data types.

    Also, "new_object.id" is redundant, I think. Just do

    target_object = instance_create_layer(mouse_x,mouse_y,"Instances",obj_click_point);

    Beyond that, I guess it is possible HTML5 isn't handling the destroy event in the same way as Windows. In which case, your obj_arrow's code should be more like

    if instance_exists(target_object) {
    //your moving code here
    }
    else
    target_object = instance_nearest(x,y,obj_click_point);


    Also, unrelated: I think you should move the collision checking to the arrow, not inside the click points. The reason I say this is what if the arrow passes through another click point on its way toward the target click point? It will destroy the click point it passes through and then possibly change targets. Whereas if you had the arrow simply check if it reached the target, then there wouldn't be any issues.

    with instance_place(x,y,target_object) {
    instance_destroy();
    score+=1;
    }
     
    Last edited: Jan 11, 2019
    oliverr likes this.
  3. oliverr

    oliverr Member

    Joined:
    Feb 24, 2018
    Posts:
    21
    Thanks TheouAegis! I appreciate you taking the time to answer.

    Unfortunately no luck, so for now I will just use instance_deactivate_object().
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice