So my island is 1500x1100. My viewable screen is 800x400. When I move my mouse around, the island scrolls left down up and right. I want to place objects that are independant of the map, that move around at the same frequency as the map. However, when I apply the same code to another (much smaller) object, the object behaves erratically. It almost follows my mouse instead of being fixed to the map like it should... Can anyone help my keep my object grounded to the map?
Here's the code, with comments for comprehension:
var speed:Number = .05; //range .01-1
this.addEventListener(Event.ENTER_FRAME,parallax,false,0,true);//happens every frame
function parallax(e:Event):void{
var myPosx = mouseX/800; //width
var myPosy = mouseY/400; //height
movexy(island,myPosx,myPosy);//object island is the main map, behaving normally
movexy(deviceofpower,myPosx,myPosy);//an object on the map, much smaller than the map, almost following my mouse
}
function movexy(me:MovieClip,myPosx:Number, myPosy:Number){//this function affects movement, I don't really understand it.
me.maxwidth = stage.stageWidth - me.width;
var destinationX = myPosx * me.maxwidth;
me.x += speed * (destinationX - me.x); //easing
me.maxheight = stage.stageHeight - me.height;
var destinationY = myPosy * me.maxheight;
me.y += speed * (destinationY - me.y); //easing
}
I've been working for months on a game. However I'm stuck and I don't know what to do. Help is greatly appreciated!