Jump to content
Search Community

TweenMax moving object on screen but not changing x/y/rotation values

vossiewulf test
Moderator Tag

Recommended Posts

This is what I seem to be seeing, and it's causing a bug, I start by moving a main playing piece (ship) on screen, resetting column/row/direction values as well that are used to track that playing piece's on screen location. TweenMax is then use to move the ship on screen, and it does exactly as expected.

 

However, the x/y/rotation values that we just tweened that ship to aren't reflected in the tween objects' properties, which remain unchanged.

 

Therefore when I pass that ship to a function that moves its miniature version on the mini map, the mini ship doesn't move anywhere. Only reason I haven't caught this before is there's a later step that explicitly resets x/y/rotation values based on the ship's column/row/direction properties.

 

Here's my breakpoint in the debugger, showing we've just tweened x/y/rotation on selectedShip to newRotation, newX, and newY values. And as mentioned, the ship moves onscreen as if the x/y/rotation values have been updated.

 

QlNWwea.jpg

 

The disable/enable onStart and onComplete functions do just what they say, setting a boolean value false/true to disable keyboard/mouse input listeners while we move the ship on screen.

 

However, as you can see the ship's Y value doesn't match newY - that's the only expected change for this move.

 

vJxA2tq.jpg

 

So then I go to:

 

miniMapContent.updateMiniShipLocation(selectedShip);

 

This is where we update the minimap's version of this ship by updating its x/y/rotation values based on the supposedly-updated selectedShip's x/y/rotation values. But since those haven't changed, the mini ship doesn't move.

 

Note that I just walked through a series of other places I use TweenMax to tween object location/rotation on screen and all of them work as expected, the tweened object's values change to match the on-screen motion, EXCEPT this one.

 

Any idea why this is happening? Or am I missing something?

 

Link to comment
Share on other sites

In hopes that by asking this question I will again see the blatantly obvious thing staring me in the face, I'm going to ask another question that has me for the moment stumped.

 

In this game players plot movement of ships on screen, then hit a go button to move to next turn phase, when that occurs the ships are moved back to their original locations before the player moved them. After player 2 does the same, the movement sequence is then played back with a ship from one side making one move, then a ship from the other side makes one move, etc. until the sequence is complete.

 

So there are 3 movement cases:

 

1. Player plotting movement for a single ship at a time. Call this the movement case.

2. All ships from one side simultaneously revert to beginning of turn positions. Call this the revert case.

3. Individual ships are moved by code when executing the movement playback sequence. Call this the playback case.

 

All of that works fine for the "real" ships but I'm having a problem with the minimap, which is a dynamic representation of the main map with mini-ships that make the same movement as their big brothers, mostly in sync.

 

The problem is that the mini-ships move correctly in the movement case and the playback case, but in the revert case they change their x/y position but seemingly ignore the rotation value of the tween. And the stumper is that all three cases are calling the exact same mini-ship movement function.

 

Move case. WORKS:

var newRotation:int = selectedShip.rotation + incrementRotation;
var newX:int = selectedShip.x + incrementX;
var newY:int = selectedShip.y + incrementY;
				
miniMapContent.updateMiniShipLocation(selectedShip, newX, newY, newRotation, .15);

Playback (playbackMode == true) case and revert case (same code, but (playbackMode != true). PLAYBACK WORKS, REVERT FAILS TO ROTATE

//call one of two repositionShip functions depending on if we're in movement playback mode or ships are being reverted to original turn locations by revertShipLocations()
//movement of ships during the movement plotting phases (by the players) are handled in the moveShip class
if (playbackMode) {
					
	//update mini-ship location to match big brother. Last param is delay to sync with big brother on screen movement
	miniMapContent.updateMiniShipLocation(ship, newShipX, newShipY, newShipRotation, .8);
					
	//tween ship, update counter values
	repositionShipPlaybackMode(playbackMoveObj.ship, playbackMoveObj.newShipX, playbackMoveObj.newShipY, playbackMoveObj.newShipRotation, playbackMoveObj.shipRotationIncrement, playbackMoveObj.moveType);
}
				
else {
					
	//update mini-ship location to match big brother. Last param is delay to sync with big brother on screen movement
	miniMapContent.updateMiniShipLocation(ship, newShipX, newShipY, newShipRotation, .15);
					
	//tween ship, update counter values
	repositionShip(ship, moveType, newShipX, newShipY, newShipRotation, shipRotationIncrement);
}

As you can see, all are calling miniMapContent.updateMiniShipLocation():

public function updateMiniShipLocation(updateShip:Ship_1, newX:Number, newY:Number, newRotation:Number, tweenDelay):void {
			
	var newMiniShipX:Number = (newX * .20) - 3;
	var newMiniShipY:Number = newY * .20;
	var newMiniShipRotation:Number = newRotation;

	TweenMax.to(updateShip.miniShip, .4, {delay:tweenDelay, ease:Power4.easeOut, x:newMiniShipX, y:newMiniShipY, rotation:newMiniShipRotation});
}

I've debugged it a dozen times and every time there's a rotation case, the newMiniShipRotation value is correct and is passed to TweenMax and that value is different than the current rotation value of updateShip.miniShip. But in the revert case, the mini-ship doesn't rotate to the passed-in value.

 

Link to comment
Share on other sites

No luck so far. I am not seeing what the difference is, only delta in the three calls is the delay and both values that we see in the three calls work, so that's not it. Otherwise it looks completely identical in the debugger even in the fail case - e.g., mini-ship rotation is 0, newMiniShipRotation is like -60, we go to tweenmax and the position of the mini-ship changes but the rotation doesn't.

 

And then I watch the exact same values get passed in but called from a different source and the min-ship rotates. ConfusedDog.jpg

Link to comment
Share on other sites

That sounds kind of strange. From looking at your code and description I'm having a hard time figuring out what might be wrong.

My only suggestion to further debug is to remove TweenMax from the equation. Instead of tweening the rotation, just set it like

updateShip.miniShip.rotation = newMiniShipRotation

Does that work?

Link to comment
Share on other sites

That sounds kind of strange. From looking at your code and description I'm having a hard time figuring out what might be wrong.

My only suggestion to further debug is to remove TweenMax from the equation. Instead of tweening the rotation, just set it like

updateShip.miniShip.rotation = newMiniShipRotation

Does that work?

 

Yeah, I should have mentioned I tried that to. When I include that after the problematic tween it always snaps to the correct rotation. So at the moment it looks like a TweenMax issue but it's so weird that that is a low confidence guess.

 

Hmm well actually I tested it with integer values not the variable, that's worth a try, but I didn't use the variable because every time I've watched it the value is right.

 

Oh also, I was wrong in the description - when a mini-ship fails to revert position a rotation is always involved, but they also do not move their x/y values either. They just stay where they were at the end of the turn phase, it's like TweenMax or something it invokes fails totally silently.

 

That gets amusing during the movement playback sequence, because ships in this condition walk backward through their moves until they intercept a theoretical mini ship moving forward, and from that point move correctly in the playback sequence. Actually they're moving correctly always in the playback sequence, that walking backward weirdness is just what happens when the ship isn't where the code thinks it should be.

 

When a rotation is not called for in the revert sequence, the mini-ships change their x/y correctly and revert to the beginning of turn position.

 

The thing about it is its consistency, I'm testing with four different scenarios with differing numbers of ships and ship types and side involved etc, (it's supposed to be a realistic simulation) and it always works the way described above no matter if it's a 1v1 ship duel or a 30 ship per side fleet engagement. It's not intermittent in any way, 100% reproducible as long as I have a functional scenario file input.

Link to comment
Share on other sites

That gets amusing during the movement playback sequence, because ships in this condition walk backward through their moves until they intercept a theoretical mini ship moving forward, and from that point move correctly in the playback sequence. Actually they're moving correctly always in the playback sequence, that walking backward weirdness is just what happens when the ship isn't where the code thinks it should be.

 

Actually not sure that makes sense, I will look at this too.

Link to comment
Share on other sites

This turned out to be another race condition, just a more subtle one; later after I call this tween I call the reposition function that moves the parent ship and then the turn switchboard, and later in the turn step transition code I was refreshing the minimap, and that would redraw the mini ships using the current locations of the parent ships, which hadn't changed before we redrew and blew away the object the tween was supposed to operate on.

 

Only odd thing here, and the reason I had ruled that out, was that earlier I thought I had tested for that by setting the tween duration to zero. But even with it set at zero, I hit the minimap refresh even though there are 50 lines and an entire function between where I call the tween and where I refresh the map. I'm sure of the cause though, edit out the map refresh and it works fine.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...