I need help. I have a script creating a entity when you press "P". When I move around it sometimes glitches and sometimes it doesn't? Is this just me?
The source (Baked) is found
here.
Could anybody help me?
-Andrew
It has to do with the keypress. If you are moving with WASD and then press P, it will spawn a little guy. But you have to let up on the WASD keys for the next P to spawn again.
I didn't look at the code but maybe you can change input.pressed to input.state to check if P is depressed. But make sure you don't spawn every frame while P is down. Make a delay or something to prevent a stream of spawned entities while P is down. Like only allow 1 spawn per second.
When you are moving around, and the press P, It spawns an entity at 100, 100. Since it wan't there to receive the ig.input.pressed, it doesn't move. If you keep pressing P while you are moving it adds multiple entities in the same spot. When you release the moving keys, and then start moving again, they go along with you.
I already knew this.
The problem was, after you press P and you stop moving, you move again and sometimes the entity glitches. I am going to attach a gif or movie that shows you what I mean
-Andrew
Movie file
here. Notice how the second guy (the one not centered) glitches back and forth.
-Andrew
Fixed it! I added this:
this.pos.x = Math.round(this.pos.x);
this.pos.y = Math.round(this.pos.y);
To the end of my cowboy.js's update function, after the this.parent();
-Andrew
Page 1 of 1
« first
« previous
next ›
last »