• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Register that camera was moved

Status
Not open for further replies.
Hello there,

I'm trying to make a camera system in which the camera is locked to the player's hero by default, but once the player is attempting to scroll the camera (or clicks on the minimap), the camera unlocks until he or she locks it again.

I tried to implement the camera lock with SetCameraPosition on a 0.02s loop, then check each time if the camera position is not where it should be to see if the player wants to move the camera. The code is asynchronous.

JASS:
//only runs for Player P.
if lockCamera[P] then
	set dx = cameraX[P] - GetCameraTargetPositionX()
	set dy = cameraY[P] - GetCameraTargetPositionY()
	if dx > CAMERA_UNLOCK_MIN_DIST or dx < -CAMERA_UNLOCK_MIN_DIST or dy > CAMERA_UNLOCK_MIN_DIST or dy < -CAMERA_UNLOCK_MIN_DIST then //CAMERA_UNLOCK_MIN_DIST = 10
		set lockCamera[P] = false
	else
		set cameraX[P] = x
		set cameraY[P] = y
		call SetCameraPosition( cameraX[P] , cameraY[P] )
	endif
endif

The problem I'm running into is that there seems to be a delay with GetCameraTargetPositionX() and the camera displacement is never registered. I think the camera is returned back to the original place with SetCameraPosition before it returns the value. Sometimes, you can scroll just fine, sometimes it takes 1-2 seconds before it moves, sometimes it remains locked permanently. I'm guessing that's based on how the internal camera update lines up with my loop.

Is there a way to fix this or maybe a completely different, better method to achieve the same goal?

Thanks!
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
Maybe this would work:
Lock the camera to the player's hero.
Use OSKeys/Mouse events to detect scrolling, arrow keys, and when the player clicks the minimap.
Unlock the camera in response to these events.
Have a hotkey like "C" dedicated to locking the camera to the player's hero again.
 
I tried that, but it didn't work well (yet?). As far as I know, you can only return the position of the mouse on the map, not on the screen. You have to convert from map coordinates to screen coordinates, which sounds like a nightmare. In addition, the top UI bar intercepts the mouse and so the position returns 0 when you move it there. I haven't been able to find the frame that I need to disable.

Yea, I have a hotkey for relocking the camera. I decided on "T".
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,875
I tried that, but it didn't work well (yet?). As far as I know, you can only return the position of the mouse on the map, not on the screen. You have to convert from map coordinates to screen coordinates, which sounds like a nightmare. In addition, the top UI bar intercepts the mouse and so the position returns 0 when you move it there. I haven't been able to find the frame that I need to disable.

Yea, I have a hotkey for relocking the camera. I decided on "T".
How about placing 0 alpha frames along the edges of the screen and using FRAMEEVENT_MOUSE_ENTER to detect when the user mouses over them.
 
Status
Not open for further replies.
Top