Wicklets / wick-editor

A free and open-source tool for creating games, animations and everything in-between!
https://www.wickeditor.com
GNU General Public License v3.0
618 stars 101 forks source link

Fix slider.wickobj #371

Open twarped opened 1 year ago

twarped commented 1 year ago

changed the knob Default Script

this._bounds = 130;
this.parentClip.value = 0;
this._dragging = false;

to

this._bounds = 130;
this.parentClip.value = (this.x + this._bounds) / this._bounds / 2;
this._dragging = false;

this initially sets the value variable to the location the knob starts at to a number between 0 and 1.

changed the knob Update Script

if(!isMouseDown()) {
    this._dragging = false;
}

if(this._dragging) {
    this.x = mouseX - this.parentClip.x;
    if(this.x < -this._bounds) {
        this.x = -this._bounds;
    }
    if(this.x > this._bounds) {
        this.x = this._bounds;
    }
    this.value = (this.x + this._bounds) / this._bounds * 2;
}

to

if(!isMouseDown()) {
    this._dragging = false;
}

if(this._dragging) {
    this.x = mouseX - this.parentClip.x;
    if(this.x < -this._bounds) {
        this.x = -this._bounds;
    }
    if(this.x > this._bounds) {
        this.x = this._bounds;
    }
    this.parentClip.value = (this.x + this._bounds) / this._bounds / 2;
}

this lets the actual slider have a value variable, this also makes the return a number between 0 and 1

changed the slider's Default script

stop();

onEvent('update', function () {
  this.value; //returns a value between 0 and 1
});

this just makes the slider code much more intuitive so that people who don't know much about coding will have an easier time getting their slider to work.