This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
extensions:sx_joypad [2011/04/11 21:16] – [Discussion] pixelrevision | extensions:sx_joypad [2015/09/14 11:15] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ~~NOTOC~~ | ||
+ | ====== SXJoypad ====== | ||
+ | |||
+ | ---- dataentry extension ---- | ||
+ | type : extension #or ' | ||
+ | author_mail | ||
+ | description | ||
+ | lastupdate_dt : 2011-04-11 #the date you created the extension | ||
+ | compatible | ||
+ | depends | ||
+ | tags : Joypad, controller, movement #enter a few tags, separated by commas | ||
+ | homepage_url | ||
+ | download_url | ||
+ | ---- | ||
+ | |||
+ | ===== Usage ===== | ||
+ | |||
+ | This is a simple joypad implementation for sparrow to be able to just pop on the stage and move things around. | ||
+ | |||
+ | <code objc> | ||
+ | #import < | ||
+ | #import " | ||
+ | |||
+ | @interface SparrowJoypad : SPStage{ | ||
+ | SXJoypad *joypad; | ||
+ | SPQuad *quad; | ||
+ | } | ||
+ | |||
+ | @end | ||
+ | |||
+ | |||
+ | @implementation SparrowJoypad | ||
+ | |||
+ | - (id)initWithWidth: | ||
+ | self = [super initWithWidth: | ||
+ | joypad = [SXJoypad joypadWithContentsOfFile: | ||
+ | [self addChild: | ||
+ | |||
+ | quad = [SPQuad quadWithWidth: | ||
+ | [self addChild: | ||
+ | |||
+ | // [self addEventListener: | ||
+ | [self addEventListener: | ||
+ | return self; | ||
+ | } | ||
+ | |||
+ | - (void)updateJoypadWithDirection: | ||
+ | // state version | ||
+ | float speed = 1; | ||
+ | if(joypad.verticalDirection == kSXJoypadVerticleDirectionTop){ | ||
+ | quad.y -= speed; | ||
+ | }else if(joypad.verticalDirection == kSXJoypadVerticleDirectionBottom){ | ||
+ | quad.y += speed; | ||
+ | } | ||
+ | if(joypad.horizontalDirection == kSXJoypadHorizontalDirectionLeft){ | ||
+ | quad.x -= speed; | ||
+ | }else if(joypad.horizontalDirection == kSXJoypadHorizontalDirectionRight){ | ||
+ | quad.x += speed; | ||
+ | } | ||
+ | } | ||
+ | |||
+ | - (void)updateJoypadWithAngle: | ||
+ | // somewhat analog | ||
+ | float speed = 1; | ||
+ | if(joypad.recievingInput){ | ||
+ | quad.x += cos(joypad.angle) * speed; | ||
+ | quad.y += sin(joypad.angle) * speed; | ||
+ | } | ||
+ | } | ||
+ | @end | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * // | ||
+ | |||
+ | ===== Source Code ===== | ||
+ | %gist(914079)% | ||
+ | |||
+ | ===== Discussion ===== | ||
+ | |||
+ | Whoop, should have looked closed before adding. |