Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zaldzbugz/ZJoystick
Cocos2D Joystick API v1.3
https://github.com/zaldzbugz/ZJoystick
Last synced: about 1 month ago
JSON representation
Cocos2D Joystick API v1.3
- Host: GitHub
- URL: https://github.com/zaldzbugz/ZJoystick
- Owner: zaldzbugz
- License: other
- Created: 2011-03-25T16:32:31.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-02-01T18:08:08.000Z (almost 13 years ago)
- Last Synced: 2023-03-26T01:47:35.024Z (over 1 year ago)
- Language: Objective-C
- Homepage: http://zframework.ph/cocos2d-zjoystick-api/
- Size: 1.13 MB
- Stars: 47
- Watchers: 3
- Forks: 6
- Open Issues: 3
-
Metadata Files:
- Readme: README
- License: LICENSE.zjoystick
Awesome Lists containing this project
- awesome - ZJoystick - Cocos2D Joystick API v1.3 (etc)
- awesome - ZJoystick - Cocos2D Joystick API v1.3 (etc)
README
-------------------------------------------------------------
//COCOS2D ZJoystick API (Version1.3)
[Version 1.3 Updates]
1.) Added new protocol method:
-(void)joystickControlDidUpdate:(id)joystick toXSpeedRatio:(CGFloat)xSpeedRatio toYSpeedRatio:(CGFloat)ySpeedRatio
This protocol method is used to acquire the ZJoystick object itself, XSpeed and YSpeed ratio.
2.) Added "joystickTag" variable; this is used to identify which joystick is controlling. Used in our new protocol method implementation.
See example below:-(void)joystickControlDidUpdate:(id)joystick toXSpeedRatio:(CGFloat)xSpeedRatio toYSpeedRatio:(CGFloat)ySpeedRatio{
//cast ZJoystick class to joystick parameter to gain actual class object
ZJoystick *zJoystick = (ZJoystick *)joystick;
//we only move this object if the joystick controlling is the 999th tagged joystick.
if (zJoystick.joystickTag == 999) {
CGFloat xPos = globalSprite.position.x;
CGFloat yPos = globalSprite.position.y;
globalSprite.position = ccp(xPos + xSpeedRatio, yPos + ySpeedRatio);
}
}
3.) Modified some methods to be more readable
4.) Updated MyJoystick example.
5.) Added MIT License
-------------------------------------------------------------
//COCOS2D ZJoystick API (Version1.2)
[Version 1.2 Updates]
1.) Updated protocol declaration
2.) Updated protocol method calls
3.) Added variable to set values for Joystick Radius
-------------------------------------------------------------
//COCOS2D ZJoystick API (Version1.1)
[Version 1.1 Updates]
1.) Updated the API to allow more than one joysticks in a screen to control object(s).
2.) Added ccTouchCancelled that calls the ccTouchEnded to allow other joysticks to work (Thanks to Joey Hengst for pointing this out)
-------------------------------------------------------------
//COCOS2D ZJoystick API (Version1.0)
//Interface and Implementation Files (REQUIRED)
ZJoystick.h - joystick interface file
ZJoystick.m - joystick implementation file//Sample Image files used in the example code below
background.png - screen background
Joystick_norm.png - (Our Joystick)
JoystickContainer_trans.png - rest state (Joystick Container, serves as the Joystick background)
JoystickContainer_norm.png - active state (Joystick Container, serves as the Joystick background)-------------------------------------------------------------
HOW TO USE1.) import Joystick header file -> #import "ZJoystick.h"
2.) Add in the interface declaration
3.) then add these codes below to any of your scenes//------------------------------------------------------START------------------------------------------------
//Controlled Object
CCSprite *controlledSprite = [CCSprite spriteWithFile:@"Joystick_norm.png"];
controlledSprite.position = ccp(winSize.width/2, winSize.height/2);
[self addChild:controlledSprite];
//Joystick
ZJoystick *_joystick = [ZJoystick joystickNormalSpriteFile:@"JoystickContainer_norm.png" selectedSpriteFile:@"JoystickContainer_trans.png" controllerSpriteFile:@"Joystick_norm.png"];
_joystick.position = ccp(_joystick.contentSize.width/2, _joystick.contentSize.height/2);
_joystick.delegate = self; //Joystick Delegate
_joystick.controlledObject = controlledSprite; //we set our controlled object which the blue circle
_joystick.speedRatio = 2.0f; //we set speed ratio, movement speed of blue circle once controlled to any direction
_joystick.joystickRadius = 50.0f; //Added in v1.2
[self addChild:_joystick];//----------------------------------------------------END----------------------------------------------------
//JoystickDelegate
//ZJoystick also has three delegate methods that you could use
-(void)joystickControlBegan;
-(void)joystickControlMoved;
-(void)joystickControlEnded;//You can implement any of these protocol methods if you want.
-------------------------------------------------------------------------------------------------------------
HERE WE GO!
//You can see the blue circle at the center and the joystick at the lower left corner
//try controlling the joystick and you can see this blue circle moving as you please.//ZIP file
Added a ZIP file there (MyJoystick.zip) which is a sample project that you could use.Check the blog post tutorial on how to use ZJoystick:
http://zaldzbugz.posterous.com/first-articleZaldzBugz
[email protected]
http://zaldzbugz.posterous.com
http://twitter.com/zaldzbugz