1 decade ago by Ecnarongi
Hello, I am new to impact and I need a little help. I have figured out a few things.
To get the entity to follow the mouse:
(inside main.js init()) - actually you just need to do ANY ig.input.bind mouse event
(inside entity init()) - set initial velocity
(inside entity) - crate an update function (don't forget the comma after the } above this code)
To get the entity to follow a mouse click
(inside main.js init()) - again you need a ig.input.bind mouse event. even if not explicitly used in the entity
(inside entity init()) - set the initial velocity and set the initial change in x and y to 0
(inside entity) - create an update function
The reason that the entity is moving diagonally because the origin (x:0,y:0) is the top left hand corner of the canvas. Positive x coordinates move right while negative move left. Positive y coordinates move down while negative move up.
I am making a mobile game that has an entity that once started (by dragging your thumb over it in a direction) it continues in that directions until it completes the task, dies, or you change its direction. The entity will always be moving.
I read through the forums that ##ig.input.bind( ig.KEY.MOUSE1, "CanvasTouch" );## (mouse clicks) are equivalent to touches for mobile devices.
My question is how to I get my entity to move in a direction from one of these "touches"?
To get the entity to follow the mouse:
(inside main.js init()) - actually you just need to do ANY ig.input.bind mouse event
ig.input.bind( ig.KEY.MOUSE1, "click" );
(inside entity init()) - set initial velocity
this.vel.x = 0.1; this.vel.y = 0.1;
(inside entity) - crate an update function (don't forget the comma after the } above this code)
update: function() { nY = ig.input.mouse.y; nX = ig.input.mouse.x; curr_y = this.pos.y; curr_x = this.pos.x; // makes your entity follow the mouse *** this.pos.y += (nY - curr_y)/2; this.pos.x += (nX - curr_x)/2; }
To get the entity to follow a mouse click
(inside main.js init()) - again you need a ig.input.bind mouse event. even if not explicitly used in the entity
ig.input.bind( ig.KEY.MOUSE1, "click" );
(inside entity init()) - set the initial velocity and set the initial change in x and y to 0
this.vel.x = 0.1; this.vel.y = 0.1; chg_y = 0; chg_x = 0;
(inside entity) - create an update function
update: function() { nY = ig.input.mouse.y; nX = ig.input.mouse.x; curr_y = this.pos.y; curr_x = this.pos.x; this.pos.y += chg_y; this.pos.x += chg_x; if(nY > curr_y) { chg_y = 1; } else { chg_y = -1; } if(nX > curr_x) { chg_x = 1; } else { chg_x = -1; } }
The reason that the entity is moving diagonally because the origin (x:0,y:0) is the top left hand corner of the canvas. Positive x coordinates move right while negative move left. Positive y coordinates move down while negative move up.
I am making a mobile game that has an entity that once started (by dragging your thumb over it in a direction) it continues in that directions until it completes the task, dies, or you change its direction. The entity will always be moving.
I read through the forums that ##ig.input.bind( ig.KEY.MOUSE1, "CanvasTouch" );## (mouse clicks) are equivalent to touches for mobile devices.
My question is how to I get my entity to move in a direction from one of these "touches"?