cocos2d-x觸控點使精靈移動到觸控點的位置
程式碼
auto target = static_cast<Sprite*>(event->getCurrentTarget());
//獲取觸控事件
Point locationInNode = target->convertToNodeSpace(touch->getLocation());
//轉換座標點
auto curveMove = MoveTo::create(0.5f,locationInNode);
//移動事件
this->getChildByTag(150)->runAction(curveMove);
//獲取精靈標籤已經賦予動作事件
相關推薦
cocos2d-x觸控點使精靈移動到觸控點的位置
程式碼 auto target = static_cast<Sprite*>(event->getCurrentTarget());//獲取觸控事件 Point locationIn
Cocos2d-x 3.2 Lua示例 ClickAndMoveTest(點選移動測試)
--[[ ClickAndMoveTest.lua 點選與移動 ]]-- -- 獲取螢幕尺寸 local size = cc.Director:getInstance():getWinSize() local layer = nil -- 層 local kTagSprite = 1 --精靈標記 loc
Cocos2d-X 3.0 ControlButton的加入以及點選事件的實現
1、在.h中加入標頭檔案 #include "extensions/cocos-ext.h" USING_NS_CC; USING_NS_CC_EXT; 新增方法: void touchUpInside(Ref* pSender,Control::EventTy
Cocos2d-x 3.0開發(三)點選互動的四種處理
1、概述 遊戲也好,程式也好,只有能與使用者互動才有意義。手機上的互動大致可以分為兩部分:點選和輸入。其中點選更為重要,幾乎是遊戲中全部的互動。在Cocos2d-x 3.0中,更改了dispatc
cocos2d-x中,多個精靈執行同樣的動作
簡而言之:雖然是“同樣”(從效果來說)的動作,但是每個精靈必須run不同的action物件 例如:需要三個精靈同時跑到一個點去,使用動作來完成。 //建立3個精靈 auto s1 = Spr
Cocos2d-x遊戲引擎開發[3]----建立錨點 (重建了一個類)
一般新建專案可以看到他是位於整個圖形介面的中心,原因是他設定了一個錨點,相當於落腳點。 因此我需要重做一個類研究這個影象在介面中的位置擺放,主要是下面這個程式碼 spr->setAnchorP
cocos2d-x實現多個精靈動畫同步播放(一)
2D遊戲經常有角色穿裝備的情況,如下圖角色手部加了一個武器.此外還有格鬥遊戲裡常有的投技: 注意角色是處在站立狀態下的,有Idle動畫,手部武器也要隨角色一起聯動。我們是不是要讓美術再畫一套加手部動畫的素材,那美術顯然不幹了,那要有腳呢,披
CocosCreator中使玩家移動到點選位置的程式碼
onLoad: function () { var that = this that._playerSpeed = 300 that.bg.on(cc.Node.EventType.TOUCH_START,function(event){
jQuery控制div層,使其移動、改變位置
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test2.html</title>
Cocos2d-x 單點觸控--讓精靈隨手指移動起來
效果圖: CCTouch類裝載了觸控點的資訊,包括觸控點的橫縱座標值和觸控點的ID號,如獲取觸控點轉GL座標: CCPoint point = pTouch->getLocationInView(); point = CCDirector::sharedD
cocos2d-x 多點觸控總結
【一】:這個和單點有啥區別1.使用上的區別。這個不用多說,有些情況下我們是需要多點觸控來實現更好的效果,比如,切水果。2.和單點的區別[1].單點使用監聽類是CCtargetedTouchDelegate,而多點使用CCtangardTouchDelegate.[2].多點觸控
cocos2d-x 顯示觸控操作(顯示水波點選效果,用於視訊演示)
昨天剛剛參加玩遊戲設計大賽, 積累了一些東西。接下去將會逐個分享出來。首先是顯示觸控操作。因為要演示我們的作品。使用試玩過程中, 如果沒辦法顯示我們的觸控操作(像錄製視訊一樣, 點選了螢幕某點, 出現紅點或者水波盪漾這樣的效果), 那樣的話演示效果不好。觀眾就無法直觀的瞭解我
Cocos2d-x 2.0 百例精講:如何讓一個精靈跟隨觸點移動
如何讓一個精靈跟隨觸點移動?本節我們以HelloCpp為例來講解一下。 第一步,我們要在場景中建立一個新的精靈。 開啟HelloWorldScene.h。我們為HelloWorld增加一個精靈類成員指標,為了方便程式碼的編寫我們可以去掉cocos2d::作用域的定義而在類定義之前加入USING_NS_CC
Cocos2d-x例項:單點觸控事件
為了讓大家掌握Cocos2d-x中的事件機制,下面我們以觸控事件為例,使用事件觸發器實現單點觸控事件。該例項如圖8-3所示,場景中有三個方塊精靈,顯示順序如圖8-3所示,拖拽它們可以移動它們,事件響應優先順序是按照它們的顯示順序。下面我們再看看具體的程式程式碼,首先看一下HelloWorldScene.h檔案
cocos2d-x-3.x吞噬點選觸控事件
使用版本是 cocos2d-x-3.1.4 彈出對話方塊,有一個背景,吞噬觸控或者點選事件,使觸控或者點選事件不被傳遞下去,將addEventListenerWithSceneGraphPriority函式裡面的this改成當前layer就可以啦 //
cocos2d-x處理單點觸控事件
這篇文章真的很菜鳥,但是出於考慮到cocos2d-x的資料真的不好查,網上又是千古文章一大抄,抄了很多還是很多的錯誤,所以還是寫一篇部落格。 cocos2d-x的觸控事件有多種方式,單點觸控最為簡單。 首先我們新建一個Cocos2d-win32 Application,轉到
cocos2d-x 3.16 ios開啟多點觸控
今天遇到坑,就是在實現多點觸控時不放幾個手指到螢幕上,獲取的觸控點得個數都是1。 最終解決方案: 找到iOS檔案RootViewController.mm,新增 [eaglView setMultipleTouchEnabled:YES] 全
cocos2d-x-lua 單點觸控事件
示例程式碼: local player = cc.Sprite:create(fileName) player:runAction(self:flyaction()) -
quick-cocos2d-x(lua) 拖動精靈使其在螢幕移動的效果實現
(1)新建類TouchLayer local TouchLayer=class("TouchLayer", function() return display.newNode() end) function TouchLayer:ctor(params)-- sel
cocos2d-x多點觸控和單點觸控同用實現
有時遊戲中有的介面要使用單點觸控,有的介面要使用多點觸控,但是單點和多點又不能同時註冊,因為同時註冊時,單點觸控的優先順序高於多點觸控,所以會響應單點觸控,多點觸控被遮蔽。 因為在寫遊戲的時候自定義層的基類中是註冊了單點觸控,所以每個繼承該基類的層都會有單點觸控