1 decade ago by coreysnyder
Ok. I've taken a stab at how to do this but I'm not at all happy with it. The end goal is that the user can aim the cannon and the game will draw an arc showing how it will fly when fired. I have figured out how to draw the line, but only in game time by spawning an entity with that velocity and then recording its position on every tick. Then drawing those positions as red dots on the screen. What I want to happen is to show where it will fly in real time, vs having to wait for the game to step() 30 or so times to show it.
If you try the demo below you can aim the cannon, and then keep your mouse steady and it will show you how the projectile will fly via red-dots. Any help?
Demo:
http://coreysnyder.me/ZombieHolidayGame/
My code:
If you try the demo below you can aim the cannon, and then keep your mouse steady and it will show you how the projectile will fly via red-dots. Any help?
Demo:
http://coreysnyder.me/ZombieHolidayGame/
My code:
............. update: function(){ if(this.positionLog.length < 60){ this.positionLog.push({x: this.pos.x, y: this.pos.y}); } }, draw: function(){ var prevPos = this.positionLog[0]; var currPos = {}; ig.system.context.strokeStyle = "red"; ig.system.context.lineWidth = 4; ig.system.context.beginPath(); for(i = 0; i< this.positionLog.length; i++){ currPos = this.positionLog[i]; ig.system.context.beginPath(); ig.system.context.moveTo(currPos.x, currPos.y); ig.system.context.lineTo(currPos.x+1, currPos.y+1); ig.system.context.stroke(); ig.system.context.closePath(); prevPos = currPos; } ig.system.context.closePath(); }