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 congwang0517

The mouse left button pressdown,and don't put up. After move the mouse for a distance put the left button up. Then how to count the mouse's move distance in y axis by using ig.input's function.
Thanks.

1 decade ago by Arantor

So you're trying to measure the distance of clicking and dragging something? (Just so I'm clear on this)

I'm not sure expressly how you'd do it in ig.input, though I know how you'd do it normally in a browser - you attach a function to the mousedown event, to calculate the x,y position of the mouse relative to the screen and store that somewhere, attach a similar function to the mouseup function and calculate the distance between the two.

Is it expressly only in the y axis you're interested in? Or total distance moved in that time?

1 decade ago by congwang0517

Thanks Arantor,I know you mean. I just don't know well with ig.input functions about mousemove. Any code can be show me?

1 decade ago by Arantor

I can't show you any code until I can actually understand what you're trying to do, and telling me what you've told me isn't enough. I need details of what you're trying to do in order to write you the code.

1 decade ago by congwang0517

OK, Arantor. My English is poor ,and I am hard to express my thought exactly in English.
I think it's similar with drag. But I don't click any entity. I just mousedown on the canvas, and move a distance and mouseup. with this action,the entites on canvas,all will change their pos.y follow the mouse.y. e.g. I put the mouse move up 3cm in y axis, and the entities pos.y+=3. And it's dynamic instead of after mouse move up 3cm.
Did i express my idea clear? Thanks again Arantor and anyother helpers.

1 decade ago by Arantor

So, do you want it to follow mouse.x too, or just mouse.y? Follow it exactly (so if you move 1cm, everything else moves 1cm) or proportionately (e.g. move 3cm, everything moves 2cm or more or less)

I still don't really know what you're trying to achieve, I wanted to know more about the game itself, not just the exact thing with the mouse.

1 decade ago by congwang0517

just mouse.y.
OK,Arantor .I tell the game itself. It's about a building with 100 floors. I can move the downed mouse to let the building change the floors. e.g. when the building location is 10 floor to 20 floor on the canvas. I move down the downed mouse,the building will display the higher floors. I difine every floor as a entity. I think change their pos.y can achieve the effect.
the 3cm ,2cm ...is not the important thing. it can be set with what i want.
My ugly code is below:
buildingRoll: function(){
			var y;
			if(ig.input.pressed('click')){
				this.mouse_y = ig.input.mouse.y;
			}
			if(ig.input.state('click')){
				y = ig.input.mouse.y;
				if(this.mouse_y < y){
					for(var i = 0;i<this.getEntitiesByType(EntityFloor).length;i++){
						this.getEntitiesByType(EntityFloor)[i].pos.y+=3;
					}	
				}else if(this.mouse_y > y){
					for(var i = 0;i<this.getEntitiesByType(EntityFloor).length;i++){
						this.getEntitiesByType(EntityFloor)[i].pos.y-=3;
					}
				}else{
					return;
				}	
			}
		},


Can the code be improved?

1 decade ago by Arantor

So, the movement's supposed to happen while you have the mouse button down, or when you release it? (The two are different and will require different code)

Also, note that it should be ig.Input not ig.input (uppercase I).

1 decade ago by congwang0517

while the mouse button down and moving. Once mouse button up or stop move,the movement stop.
Page 1 of 1
« first « previous next › last »