Hello everyone,
i am working on a script to save time for remote controlled events (for example a crane controll).
At first it looks good but it has a small design flaw, everytime when i hold the direction button for to long, the event accelerates.
My best guess is, that the inputs are queued between the update cycles and this causes to execute more moveStraight() commands later on but i am not sure how i can prevent this.
Can someone give me advice how I can tackle this problem?
i am working on a script to save time for remote controlled events (for example a crane controll).
At first it looks good but it has a small design flaw, everytime when i hold the direction button for to long, the event accelerates.
My best guess is, that the inputs are queued between the update cycles and this causes to execute more moveStraight() commands later on but i am not sure how i can prevent this.
Can someone give me advice how I can tackle this problem?
PHP:
/*Override of rpg_objects.js to initialize Game_Event as extended class */
Game_Map.prototype.setupEvents = function() {
this._events = [];
for (var i = 0; i < $dataMap.events.length; i++) {
if ($dataMap.events[i]) {
//Check for <remote> tag in note otherwise default.
if($dataMap.events[i].note === '<remote>'){
this._events[i] = new Remote_Event(this._mapId, i);
}else{
this._events[i] = new Game_Event(this._mapId, i);
}
}
}
this._commonEvents = this.parallelCommonEvents().map(function(commonEvent) {
return new Game_CommonEvent(commonEvent.id);
});
this.refreshTileEvents();
};
/*Extended class of Game_Event to implement a keyListener*/
class Remote_Event extends Game_Event{
constructor(mapId, eventId) {
super(mapId, eventId);
document.addEventListener('keydown', this.onKeyDown.bind(this));
}
onKeyDown(event) {
if(!this.isMoving() && Input.isPressed('right')){
this.moveStraight(6);
}
if(Input.isPressed('left')){
this.moveStraight(4);
}
if(Input.isPressed('up')){
this.moveStraight(8);
}
if(Input.isPressed('down')){
this.moveStraight(2);
}
}
}