ios - Basic Request: How to Get Text Input in Cocos2d Application -
i have thought simple task: create 2 input fields on scene , perform usual input methods on them (touch set input focus, allow text entry using on-screen keyboard, deselect field when "done" key pressed, re-establish input focus if field touched/selected again, etc.), usual functionality see in applications allow user text input.
i have looked through of relevant forums ios development, stackoverflow, , have seen incomplete code snippets , vague references, of don't exist anymore.
i thought simple task, seems think vague directions sufficient wants straight answer.
can provide complete description of needs done accomplish task?
thanks.
p.s.: after realizing didn't provide complete information, environment , tools i'm using:
library framework: cocos2d v2
development studio: xcode 5.1
target platforms: ios on iphone, ipad, , ipod touch devices (port android platforms in progress)
minimum ios required: 6.1
if using cocos2d v3, use cctextfield
text input. example:
cctextfield *entername = [cctextfield textfieldwithspriteframe:[ccspriteframe framewithimagenamed:@"textfield_background.png"]]; entername.fontsize = 16.0f; entername.contentsize = cgsizemake(100.0f, 50.0f); entername.preferredsize =cgsizemake(100.0f, 50.0f); entername.positiontype = ccpositiontypenormalized; entername.position = ccp(0.5f, 0.5f); [self addchild:entername z:5];
if using cocos2d v2, use uikit components. example:
cgsize size = [[ccdirector shareddirector] winsize]; uitextfield *textfield = [[uitextfield alloc] initwithframe:cgrectmake(size.width * 0.5, size.height* 0.1, 100, 100)]; textfield.borderstyle = uitextborderstyleroundedrect; [[[ccdirector shareddirector] view]addsubview:textfield];
as note, cocos2d v3 uses uitextfield
in ios , nstextfield
in mac.
#ifdef __cc_platform_ios /** ios: uitextfield used cctextfield. */ @property (nonatomic,readonly) uitextfield* textfield; #elif defined(__cc_platform_mac) /** mac: nstextfield used cctextfield. */ @property (nonatomic,readonly) nstextfield* textfield; #endif
Comments
Post a Comment