Problems with Camera Zoom and Movement

61 views
Skip to first unread message

Ardivall

unread,
Oct 6, 2015, 12:24:30 PM10/6/15
to haxef...@googlegroups.com
Hello guys, I'm having some issues with FlxCamera's zoom distorting positional values of the mouse inconsistently with respects to everything else on screen.
In my game I am trying to implement a movement system where the player character follows the mouse when it is being pressed, but I am running into a problem when the camera
zoom is changed (increased or decreased) from the default the player does not locate the mouse correctly.

To do this i am doing the following:

if (selected && FlxG.mouse.pressed)
   
{
        wayPoint
.revive();
       
var mousePos:FlxPoint = FlxG.mouse.getWorldPosition(cam);
        wayPoint
.setPosition(mousePos.x, mousePos.y);
   
}

if (wayPoint.alive) {
   
FlxVelocity.moveTowardsObject(this, wayPoint, _acceleration);
   
if (overlaps(wayPoint)) {
        wayPoint
.kill();
       
FlxVelocity.moveTowardsObject(this, wayPoint, 0);
   
}
}
(selected is a bool defined to be true on player creation.)

Where the waypoint is a variable declared before hand that will be used to store the position of the mouse when last pressed, and is dead by default until a mouse click is registered.

It also breaks when using FlxVelocity.moveTowardsMouse/Point functions.

After some investigating It seems it may be something to do with obtaining the screen coordinates for objects/mouse correctly.

trace("Mouse world pos: " + FlxG.mouse.getWorldPosition(cam));
trace
("Mouse screen pos: " + FlxG.mouse.getScreenPosition(cam));

They return the same values as each other, and both change with zoom.
(Should these be identical, and should wolrd position change with the camera?
What's the difference supposed to be?)

on the other hand when calling the following to obtain an object/sprite's position:

var myPos:FlxPoint = new FlxPoint();
getScreenXY
(myPos, cam);
trace
("Player Screen Pos: " + myPos);
trace
("Player world pos: " + getMidpoint());
(called during update, after super.update())

Both return exactly the same coordinates, regardless of the camera's zoom.
I am not sure if this is a bug or there is some parameter I am forgetting to take into account when calculating positions.

This causes the coordinates of the mouse to be wildly different to that of the player character on screen, regardless of their relative position within the viewport.

Note: I am also using an FlxZoomCamera, although the problem remains with FlxCamera and I'm running this using lime test neko

lime: 2.6.6
HaxeFlixel command-line tools (1.1.1)
Installed flixel version: 3.3.11
Reply all
Reply to author
Forward
0 new messages