1. <small id='16QcM'></small><noframes id='16QcM'>

      <i id='16QcM'><tr id='16QcM'><dt id='16QcM'><q id='16QcM'><span id='16QcM'><b id='16QcM'><form id='16QcM'><ins id='16QcM'></ins><ul id='16QcM'></ul><sub id='16QcM'></sub></form><legend id='16QcM'></legend><bdo id='16QcM'><pre id='16QcM'><center id='16QcM'></center></pre></bdo></b><th id='16QcM'></th></span></q></dt></tr></i><div id='16QcM'><tfoot id='16QcM'></tfoot><dl id='16QcM'><fieldset id='16QcM'></fieldset></dl></div>
      <legend id='16QcM'><style id='16QcM'><dir id='16QcM'><q id='16QcM'></q></dir></style></legend>

      <tfoot id='16QcM'></tfoot>
      • <bdo id='16QcM'></bdo><ul id='16QcM'></ul>

      在 Cocos2d for iPhone 中随时获取当前触摸位置

      时间:2024-08-12

        <tbody id='LXnvM'></tbody>
    2. <small id='LXnvM'></small><noframes id='LXnvM'>

      • <legend id='LXnvM'><style id='LXnvM'><dir id='LXnvM'><q id='LXnvM'></q></dir></style></legend>
            <bdo id='LXnvM'></bdo><ul id='LXnvM'></ul>
            <i id='LXnvM'><tr id='LXnvM'><dt id='LXnvM'><q id='LXnvM'><span id='LXnvM'><b id='LXnvM'><form id='LXnvM'><ins id='LXnvM'></ins><ul id='LXnvM'></ul><sub id='LXnvM'></sub></form><legend id='LXnvM'></legend><bdo id='LXnvM'><pre id='LXnvM'><center id='LXnvM'></center></pre></bdo></b><th id='LXnvM'></th></span></q></dt></tr></i><div id='LXnvM'><tfoot id='LXnvM'></tfoot><dl id='LXnvM'><fieldset id='LXnvM'></fieldset></dl></div>

              1. <tfoot id='LXnvM'></tfoot>
                本文介绍了在 Cocos2d for iPhone 中随时获取当前触摸位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我一直在使用以下方法来检测触摸何时开始以及位置是什么:

                I have been using the following method to detect when a touch began and what the location is:

                -(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{
                
                    CGPoint touchLocation = [touch locationInView: [touch view]];
                    touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
                
                    touchLocation = [self convertToNodeSpace:touchLocation];
                
                    return YES;
                }
                

                但如果我的手指仍在屏幕上,我也想知道如何随时获取当前位置.有谁知道怎么做?谢谢.

                But I would also like to know how to get the current location anytime of my touch if my finger is still on the screen. Anyone know how? Thanks.

                编辑

                我想我会尽快将其发布为答案,但这就是我所做的:

                I'll post this as an answer in a bit I think, but this is what I did:

                我只是在我所有方法之外定义的 ccTime 方法中不断转换变量:

                I just kept converting a variable in a ccTime method defined outside of all my methods:

                - (void)update:(ccTime)dt {
                heroMoveEndLoc = [self convertToNodeSpace:heroMoveEndLoc];
                }
                

                推荐答案

                试试这样...

                - (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
                
                    UITouch *touch = [touches anyObject];
                    CGPoint location = [touch locationInView:[touch view]];
                    location = [[CCDirector sharedDirector] convertToGL:location];
                    x_point = location.x;
                    y_point  = location.y;
                    [self schedule:@selector(updateFunction)];
                }
                
                -(void)updateFunction
                {
                    NSLog(@"Location is %0.02f %0.02f",x_point,y_point);
                }
                - (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
                    [self unschedule:@selector(updateFunction)];
                
                }
                

                这篇关于在 Cocos2d for iPhone 中随时获取当前触摸位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:使用 Cocos2d 在我的 iPhone 应用程序中使用多个声音 下一篇:在 cocos2d 中如何实现 touch hash code 并在后面引用呢?

                相关文章

                <legend id='jFPCe'><style id='jFPCe'><dir id='jFPCe'><q id='jFPCe'></q></dir></style></legend>
                <i id='jFPCe'><tr id='jFPCe'><dt id='jFPCe'><q id='jFPCe'><span id='jFPCe'><b id='jFPCe'><form id='jFPCe'><ins id='jFPCe'></ins><ul id='jFPCe'></ul><sub id='jFPCe'></sub></form><legend id='jFPCe'></legend><bdo id='jFPCe'><pre id='jFPCe'><center id='jFPCe'></center></pre></bdo></b><th id='jFPCe'></th></span></q></dt></tr></i><div id='jFPCe'><tfoot id='jFPCe'></tfoot><dl id='jFPCe'><fieldset id='jFPCe'></fieldset></dl></div>
                  • <bdo id='jFPCe'></bdo><ul id='jFPCe'></ul>
                1. <small id='jFPCe'></small><noframes id='jFPCe'>

                    <tfoot id='jFPCe'></tfoot>