Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by TrexKikBut

I need help with another problem:

I want my entity to point directly at the cursor, but I don't know how to offset the angle.

How can this be done?

this.currentAnim.angle = Math.atan2(ig.gui.cursor.pos.y - this.pos.y, ig.gui.cursor.pos.x - this.pos.x);

1 decade ago by Datamosh

You can use a picture or an entity and position in mouse X/Y:
http://impactjs.com/documentation/class-reference/input#mouse-x-mouse-y

Some time ago I made this plugin can be useful:
https://github.com/datamosh/ImpactJS-GUI

You can set the cursor anytime with:
ig.gui.cursor.set(image);

or remove:
ig.gui.cursor.clear();

In your entity (player) update:
if(ig.input.pressed('mouse1')) {
	ig.game.spawnEntity(EntityWeapon, this.pos.x, this.pos.y, {
		source: this,
		click: {
			x: ig.gui.cursor.pos.x + ig.game.screen.x,
			y: ig.gui.cursor.pos.y
		}
	});
}

In your weapon init:
this.angle = Math.atan2(settings.click.y - this.pos.y, settings.click.x - this.pos.x);
this.vel.y = Math.sin(this.angle) * 100;
this.vel.x =  Math.cos(this.angle) * 100;

1 decade ago by TrexKikBut

I'm getting this error:

Uncaught TypeError: Cannot read property 'cursor' of undefined - Player.js:37

Line 37:
	x: ig.gui.cursor.pos.x + ig.game.screen.x,

1 decade ago by TrexKikBut

Neither of your things are working for me, I can't draw the cursor either.

1 decade ago by TrexKikBut

Its WOrking

1 decade ago by Datamosh

Everything works fine?

Later I will add offset (x / y) to the mouse cursor. In some cases it may be useful to specify where is the 'hotspot' in the image.

1 decade ago by TrexKikBut

I have a new question. Read OP
Page 1 of 1
« first « previous next › last »