Customise Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorised as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.

No cookies to display.

[ad_1]

The code from the place i based mostly my script.

The code i’ve has the these 2 issues:

  • The visible space for the participant to see what unit are going to be chosen would not work as meant, if i begin dragging from left to proper, and down, the choice space is drawn inverted. if i attempt to do the identical however inverting the motion the choice space is drawn appropriately.

  • The choice space and the models i wish to choose should not chosen, or simply selects only one, might need one thing to do with the issue above.

  • One thing i’ve tried is the code alone in one other scene, this baffles me as a result of it really works as meant!, it would not have any one of many drawback above

The code:

extends Node2D

var dragging = false  # are we presently dragging?
var selected_units = []  # array of chosen models
var drag_start = Vector2.ZERO  # location the place the drag begian
var select_rect = RectangleShape2D.new()
const blue =  Colour(0.59, 0.86, 1.0,0.4)
var drag_end  = Vector2.ZERO 
var chosen = 0


func _unhandled_input(occasion):
    if occasion is InputEventMouseButton and occasion.button_index == BUTTON_LEFT:
        # When the mouse button is pressed, then the dragging begins
        if occasion.pressed:
            if selected_units.measurement() == 0:
                dragging = true
                drag_start = occasion.place
            else:
                for unit in selected_units:
                    unit.collider._set_selected(false)
                    selected_units = []
            dragging = true
            drag_start = occasion.place
            
        elif dragging:
            dragging = false
            drag_end = occasion.place
            replace()
            drag_end = occasion.place
            select_rect.extents = (drag_end - drag_start) / 2
            var area = get_world_2d().direct_space_state
            var question = Physics2DShapeQueryParameters.new()
            question.collide_with_bodies = true
            question.set_shape(select_rect)
            question.rework = Transform2D(0, (drag_end + drag_start)/2)
            selected_units = area.intersect_shape(question)
            chosen = selected_units.measurement() 
            for unit in selected_units:
                unit.collider._set_selected(true)
                
    if occasion is InputEventMouseMotion and dragging:
        replace()

func _draw():
    if dragging:
        draw_rect(Rect2(drag_start, get_global_mouse_position() - drag_start),
                blue, true)

Unsure why is that occuring, now i believe that is the road the place the issue lies:

question.rework = Transform2D(0, (drag_end + drag_start)/2)

because it ‘s not inverting the realm the place we are attempting to get the models chosen. unsure if did i missed one thing to configure elsewhere? why my code fails when it is in the primary scene of my recreation however not on the check scene?

[ad_2]

Leave a Reply

Your email address will not be published. Required fields are marked *