Setting zRotation in DidBeginContact

General discussion about iOS development - a great place to ask questions about iOS or help out others. For discussion of the official tutorials, see the Official Tutorials forum.

Setting zRotation in DidBeginContact

Postby esael » Fri Jan 24, 2014 4:30 am

Hi,

Why doesn't setting zRotation of a SpriteNode work in DidBeginContact. I don't understand.

_bednode.zRotation = 0.5; // this doesn't work
_bednode.alpha = 0.5; // This works!

Why?
esael
Baby Hacker
 
Posts: 9
Joined: Sun Jul 10, 2011 6:29 am
Has thanked: 0 time
Been thanked: 0 time

Re: Setting zRotation in DidBeginContact

Postby Elliott » Fri Jan 24, 2014 5:00 am

When you set the zRotation property it doesn't add any degrees to the current rotation value, if the alpha changes as you stated on contact and you see no new rotation value then it must already have a value of 0.5. If you want the node's angle to spin on contact then you need to define an iVar or a static local variable that increments or multiples its value such as - "theRotation += 0.5;" and then set the node.zPosition to the variable "theRotation".
User avatar
Elliott
Uber Haxx0r
 
Posts: 454
Joined: Sun Jan 02, 2011 10:34 pm
Location: UK
Has thanked: 4 times
Been thanked: 112 times

Re: Setting zRotation in DidBeginContact

Postby esael » Fri Jan 24, 2014 5:10 am

Elliott wrote:When you set the zRotation property it doesn't add any degrees to the current rotation value, if the alpha changes as you stated on contact and you see no new rotation value then it must already have a value of 0.5. If you want the node's angle to spin on contact then you need to define an iVar or a static local variable that increments or multiples its value such as - "theRotation += 0.5;" and then set the node.zPosition to the variable "theRotation".


I was doing the Cat tutorial. At the start, I set _bedNode zRotation to 0.5 and I can see the bed slanted at an angle. At DidBeginContact, I set _bedNode alpha to 0.5 and _bedNode to 0. The bed faded to 0.5 but it doesn't lie flat on the floor but keeps the slant. Shouldn't the bed lies flat now?
esael
Baby Hacker
 
Posts: 9
Joined: Sun Jul 10, 2011 6:29 am
Has thanked: 0 time
Been thanked: 0 time

Re: Setting zRotation in DidBeginContact

Postby Elliott » Fri Jan 24, 2014 5:18 am

Yes it should indeed. You have an issue I can't see, can you paste the code maybe?
User avatar
Elliott
Uber Haxx0r
 
Posts: 454
Joined: Sun Jan 02, 2011 10:34 pm
Location: UK
Has thanked: 4 times
Been thanked: 112 times

Re: Setting zRotation in DidBeginContact

Postby esael » Fri Jan 24, 2014 5:23 am

Hi.... details below.

- (void)addCatAtPosition:(CGPoint)pos
{
........
_bedNode.zRotation = 0.5; // bed appears slanted
}


- (void)didBeginContact:(SKPhysicsContact *)contact
{
NSLog(@"bednode rotation is %f",_bedNode.zRotation);

_bedNode.alpha = 0.5;
_bedNode.zRotation = 0;
NSLog(@"bednode rotation is %f",_bedNode.zRotation);
....
}

Below is the NSLog when cat bounces on the floor
2014-01-24 13:20:08.174 CatNap[3001:70b] bednode rotation is 0.500000
2014-01-24 13:20:08.175 CatNap[3001:70b] bednode rotation is 0.000000
2014-01-24 13:20:08.207 CatNap[3001:70b] bednode rotation is 0.500000
2014-01-24 13:20:08.207 CatNap[3001:70b] bednode rotation is 0.000000
2014-01-24 13:20:08.241 CatNap[3001:70b] bednode rotation is 0.500000
2014-01-24 13:20:08.241 CatNap[3001:70b] bednode rotation is 0.000000
2014-01-24 13:20:08.307 CatNap[3001:70b] bednode rotation is 0.500000
2014-01-24 13:20:08.307 CatNap[3001:70b] bednode rotation is 0.000000
2014-01-24 13:20:08.574 CatNap[3001:70b] bednode rotation is 0.500000
2014-01-24 13:20:08.574 CatNap[3001:70b] bednode rotation is 0.000000
2014-01-24 13:20:08.674 CatNap[3001:70b] bednode rotation is 0.500000
2014-01-24 13:20:08.674 CatNap[3001:70b] bednode rotation is 0.000000
2014-01-24 13:20:08.707 CatNap[3001:70b] bednode rotation is 0.500000
2014-01-24 13:20:08.707 CatNap[3001:70b] bednode rotation is 0.000000
2014-01-24 13:20:08.807 CatNap[3001:70b] bednode rotation is 0.500000
2014-01-24 13:20:08.807 CatNap[3001:70b] bednode rotation is 0.000000
esael
Baby Hacker
 
Posts: 9
Joined: Sun Jul 10, 2011 6:29 am
Has thanked: 0 time
Been thanked: 0 time

Re: Setting zRotation in DidBeginContact

Postby esael » Fri Jan 24, 2014 5:24 am

Hi, I further did this:

- (void) didEndContact:(SKPhysicsContact *)contact
{
_bedNode.alpha = 1;
_bedNode.zRotation = 0;
}

I can see the bed flashing but no rotation at all.

I'm getting madder than the cat.
esael
Baby Hacker
 
Posts: 9
Joined: Sun Jul 10, 2011 6:29 am
Has thanked: 0 time
Been thanked: 0 time

Re: Setting zRotation in DidBeginContact

Postby Elliott » Fri Jan 24, 2014 5:27 am

Haha! I know the feeling, please post the project and I will be able to see everything.
User avatar
Elliott
Uber Haxx0r
 
Posts: 454
Joined: Sun Jan 02, 2011 10:34 pm
Location: UK
Has thanked: 4 times
Been thanked: 112 times


Return to General Discussion

Who is online

Users browsing this forum: Bing [Bot] and 8 guests