cocos-js (web端)输入框功能实现

cocos-js (web端)输入框功能实现,第1张

概述var textInputGetRect = function (node) { var rc = cc.rect(node.x, node.y, node.width, node.height); rc.x -= rc.width / 2; rc.y -= rc.height / 2; return rc;}; var InputComponent = cc.L
var @H_419_2@textinputGetRect @H_419_2@= function @H_419_2@(node@H_419_2@) {    var @H_419_2@rc = @H_419_2@cc@H_419_2@.rect@H_419_2@(node@[email protected],node@[email protected],node@[email protected],node@[email protected]);    rc.x -= @[email protected] / @H_419_2@2@H_419_2@;    rc.y -= @[email protected] / @H_419_2@2@H_419_2@;    return @H_419_2@rc;};
var @H_419_2@inputComponent @H_419_2@= @H_419_2@cc@[email protected].extend@H_419_2@({    _trackNode:null@H_419_2@,_beginPos:null@H_419_2@,ctor@H_419_2@:function @H_419_2@() {        this@H_419_2@._super();        if@H_419_2@( 'touches' @H_419_2@in @H_419_2@cc@[email protected] ){            cc@[email protected].addListener@H_419_2@({                event: @H_419_2@cc@[email protected]_ALL_AT_ONCE,ontouchesEnded: this@[email protected]            },this@H_419_2@);        } else if @H_419_2@('mouse' @H_419_2@in @H_419_2@cc@[email protected] )            cc@[email protected].addListener@H_419_2@({                event: @H_419_2@cc@[email protected],onmouseup: this@[email protected]            },this@H_419_2@);    },onClickTrackNode@H_419_2@:function @H_419_2@(clicked@H_419_2@) {    },ontouchesEnded@H_419_2@:function @H_419_2@(touches@H_419_2@,event@H_419_2@) {        var @H_419_2@target = @H_419_2@event@H_419_2@.getCurrentTarget@H_419_2@();        if @H_419_2@(!@H_419_2@target._trackNode)            return@H_419_2@;        // grab first touch@H_419_2@        @H_419_2@if@H_419_2@(touches@[email protected] == @H_419_2@0@H_419_2@)            return@H_419_2@;        var @H_419_2@touch = @H_419_2@touches@H_419_2@[0@H_419_2@];        var @H_419_2@point = @H_419_2@touch.getLocation@H_419_2@();@H_419_2@        @H_419_2@var @H_419_2@rect = @H_419_2@textinputGetRect@H_419_2@(target._trackNode);@H_419_2@        @H_419_2@target.onClickTrackNode@H_419_2@(cc@H_419_2@.rectContainsPoint@H_419_2@(rect,point));        //cc.log("----------------------------------");@H_419_2@    @H_419_2@},onmouseup@H_419_2@:function @H_419_2@(event@H_419_2@) {        var @H_419_2@target = @H_419_2@event@H_419_2@.getCurrentTarget@H_419_2@();        if @H_419_2@(!@H_419_2@target._trackNode)            return@H_419_2@;        var @H_419_2@point = @H_419_2@event@H_419_2@.getLocation@H_419_2@();@H_419_2@        @H_419_2@var @H_419_2@rect = @H_419_2@textinputGetRect@H_419_2@(target._trackNode);@H_419_2@        @H_419_2@target.onClickTrackNode@H_419_2@(cc@H_419_2@.rectContainsPoint@H_419_2@(rect,point));    }});var @H_419_2@TextFIEldTTFDefaultTest @H_419_2@= @H_419_2@inputComponent@H_419_2@.extend@H_419_2@({    _charlimit:@H_419_2@20@H_419_2@,_textFIEld:null@H_419_2@,ctor@H_419_2@:function @H_419_2@() {        this@H_419_2@._super();    },onEnter@H_419_2@:function @H_419_2@() {        this@H_419_2@._super();        var @H_419_2@winSize = @H_419_2@cc@[email protected].getWinSize@H_419_2@();        this@H_419_2@._textFIEld = new @H_419_2@cc@[email protected]("<click here for input>"@H_419_2@,"Arial"@H_419_2@,36@H_419_2@);        this@H_419_2@._textFIEld.setcolor@H_419_2@(cc@H_419_2@.color@H_419_2@(0xff0000@H_419_2@));        this@H_419_2@.addChild@H_419_2@(this@H_419_2@._textFIEld);        //this._textFIEld.setDelegate(this);@H_419_2@@H_419_2@        @H_419_2@this@H_419_2@._textFIEld.x = @[email protected] / @H_419_2@2@H_419_2@;        this@H_419_2@._textFIEld.y = @[email protected] /@H_419_2@3@H_419_2@;        this@H_419_2@._trackNode = this@H_419_2@._textFIEld;    },callbackRemoveNodeWhenDIDAction@H_419_2@:function @H_419_2@(node@H_419_2@) {        this@H_419_2@.removeChild@H_419_2@(node@H_419_2@,true@H_419_2@);    },onClickTrackNode@H_419_2@:function @H_419_2@(clicked@H_419_2@) {        var @H_419_2@textFIEld = this@H_419_2@._trackNode;        if @H_419_2@(clicked@H_419_2@) {            // TextFIEldTTFTest be clicked@H_419_2@            //cc.log("TextFIEldTTFDefaultTest:CCTextFIEldTTF attachWithIME");@H_419_2@            @H_419_2@textFIEld.attachWithIME@H_419_2@();        } else @H_419_2@{            // TextFIEldTTFTest not be clicked@H_419_2@            //cc.log("TextFIEldTTFDefaultTest:CCTextFIEldTTF detachWithIME");@H_419_2@            @H_419_2@textFIEld.detachWithIME@H_419_2@();        }    },onTextFIEldAttachWithIME@H_419_2@:function @H_419_2@(sender@H_419_2@) {        return false@H_419_2@;    },onTextFIEldDetachWithIME@H_419_2@:function @H_419_2@(sender@H_419_2@) {        return false@H_419_2@;    },onTextFIEldInsertText@H_419_2@:function @H_419_2@(sender@H_419_2@,text@H_419_2@,len@H_419_2@) {        // if insert enter,treat as default to detach with ime@H_419_2@        @H_419_2@if @H_419_2@('@H_419_2@\n@H_419_2@' @H_419_2@== @H_419_2@text@H_419_2@) {            return false@H_419_2@;        }        // if the textfIEld's char count more than m_nCharlimit,doesn't insert text anymore.@H_419_2@        @H_419_2@if @H_419_2@(sender@H_419_2@.getCharCount@H_419_2@() >= this@H_419_2@._charlimit) {            return true@H_419_2@;        }@H_419_2@        @H_419_2@return false@H_419_2@;    },onTextFIEldDeleteBackward@H_419_2@:function @H_419_2@(sender@H_419_2@,delText@H_419_2@,len@H_419_2@) {        // create a delete text sprite and do some action@H_419_2@        // var label = new cc.LabelTTF(delText,"Arial",36);@H_419_2@        // this.addChild(label);@H_419_2@        //@H_419_2@        // var winSize = cc.director.getWinSize();@H_419_2@        // var endPos = cc.p(-winSize.wIDth / 4.0,winSize.height * (0.5 + Math.random() / 2.0));@H_419_2@        //@H_419_2@        // label.x = endPos.x;@H_419_2@        // label.y = endPos.y;@H_419_2@@H_419_2@        @H_419_2@return false@H_419_2@;    },onDraw@H_419_2@:function @H_419_2@(sender@H_419_2@) {        return false@H_419_2@;    }});
总结

以上是内存溢出为你收集整理的cocos-js (web端)输入框功能实现全部内容,希望文章能够帮你解决cocos-js (web端)输入框功能实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1084167.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存