• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[JASS] Register that camera was moved

Status
Not open for further replies.

Antares

Spell Reviewer
Level 22
Joined
Dec 13, 2009
Messages
528
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 64
Joined
Aug 10, 2018
Messages
6,583
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.
 

Antares

Spell Reviewer
Level 22
Joined
Dec 13, 2009
Messages
528
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 64
Joined
Aug 10, 2018
Messages
6,583
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