SneakyJoystick – Noob Question

Forums Programming Programming – Everything else SneakyJoystick – Noob Question

This topic contains 3 replies, has 3 voices, and was last updated by  sneakyness 3 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
Author Posts
Author Posts
August 13, 2010 at 7:29 pm #223966


Hi everyone,

I’m new to Cocos2D iPhone dev, and I’m still pretty fresh in terms of iPhone development. I was just reading the following tutorial which was a nice little introduction to the SneakyJoystick, and because this community seems so active, I figured I’d post a question here.

I have everything working fine with the little test layer I’ve created, except the line

[self applyJoystick:leftJoystick toNode:hero forTimeDelta:delta];

The writer of the tutorial mentions that the ‘special method’ called here is not listed because it is out of scope…

My question is how should that method appear? I have tried adding the following method to my “hero” class

-(void)applyJoystick:(SneakyJoystick *)aJoystick forTimeDelta:(float)dt;

… but obviously that isn’t working… can anyone give me a kick in the right direction?

Thanks a lot!


August 13, 2010 at 8:49 pm #294322


I had the same issue. I had to change a few things. This is what I am doing. Don’t forget to add these to the .h file as well. I also added an isActive flag to the joystick class that is very useful. Followed these instructions.

// Main loop of the application
-(void) step: (ccTime) delta
[self applyJoystick:leftJoystick toNode:sprite forTimeDelta:delta];

-(void)applyJoystick:(SneakyJoystick*)joystick toNode:(CCNode*)aNode forTimeDelta:(float)delta
// you can create a velocity specific to the node if you wanted, just supply a different multiplier
// which will allow you to do a parallax scrolling of sorts
CGPoint scaledVelocity = ccpMult(joystick.velocity, 240.0f);

if (joystick.isActive) {
// apply the scaled velocity to the position over delta
aNode.position = [self applyVelocity:scaledVelocity position:aNode.position delta:delta];
aNode.rotation = -joystick.degrees;

-(CGPoint) applyVelocity:(CGPoint)velocity position:(CGPoint)position delta:(CGFloat)delta
return CGPointMake(position.x + velocity.x * delta, position.y + velocity.y * delta);

August 15, 2010 at 1:57 pm #294323


This is great! Thanks for the help zangmobile!

August 15, 2010 at 5:24 pm #294324


I feel all warm and fuzzy inside :3

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.