mirror of https://github.com/axmolengine/axmol.git
Merge pull request #5189 from samuele3hu/developNewEventDispacther
close #3822:Use the new event-dispatcher to update some lua test cases which used the old event-dispatcher
This commit is contained in:
commit
5f71d320c3
|
@ -1071,7 +1071,7 @@ bool luavals_variadic_to_array(lua_State* L,int argc, Array** ret)
|
|||
else if (lua_isuserdata(L, i + 2))
|
||||
{
|
||||
tolua_Error err;
|
||||
if (!tolua_isusertype(L, i + 2, "Object", 0, &err))
|
||||
if (!tolua_isusertype(L, i + 2, "cc.Object", 0, &err))
|
||||
{
|
||||
#if COCOS2D_DEBUG >=1
|
||||
luaval_to_native_err(L,"#ferror:",&err);
|
||||
|
|
|
@ -88,7 +88,7 @@ bool luavals_variadic_to_ccvector( lua_State* L, int argc, cocos2d::Vector<T>* r
|
|||
{
|
||||
tolua_Error err;
|
||||
//Undo check
|
||||
if (!tolua_isusertype(L, i + 2, "Object", 0, &err))
|
||||
if (!tolua_isusertype(L, i + 2, "cc.Object", 0, &err))
|
||||
{
|
||||
ok = false;
|
||||
break;
|
||||
|
|
|
@ -367,3 +367,165 @@ cc.LabelEffect =
|
|||
GLOW = 3,
|
||||
}
|
||||
|
||||
cc.KeyCode =
|
||||
{
|
||||
KEY_NONE = 0,
|
||||
KEY_PAUSE = 0x0013,
|
||||
KEY_SCROLL_LOCK = 0x1014,
|
||||
KEY_PRINT = 0x1061,
|
||||
KEY_SYSREQ = 0x106A,
|
||||
KEY_BREAK = 0x106B,
|
||||
KEY_ESCAPE = 0x001B,
|
||||
KEY_BACKSPACE = 0x0008,
|
||||
KEY_TAB = 0x0009,
|
||||
KEY_BACK_TAB = 0x0089,
|
||||
KEY_RETURN = 0x000D,
|
||||
KEY_CAPS_LOCK = 0x00E5,
|
||||
KEY_SHIFT = 0x00E1,
|
||||
KEY_CTRL = 0x00E3,
|
||||
KEY_ALT = 0x00E9,
|
||||
KEY_MENU = 0x1067,
|
||||
KEY_HYPER = 0x10ED,
|
||||
KEY_INSERT = 0x1063,
|
||||
KEY_HOME = 0x1050,
|
||||
KEY_PG_UP = 0x1055,
|
||||
KEY_DELETE = 0x10FF,
|
||||
KEY_END = 0x1057,
|
||||
KEY_PG_DOWN = 0x1056,
|
||||
KEY_LEFT_ARROW = 0x1051,
|
||||
KEY_RIGHT_ARROW = 0x1053,
|
||||
KEY_UP_ARROW = 0x1052,
|
||||
KEY_DOWN_ARROW = 0x1054,
|
||||
KEY_NUM_LOCK = 0x107F,
|
||||
KEY_KP_PLUS = 0x10AB,
|
||||
KEY_KP_MINUS = 0x10AD,
|
||||
KEY_KP_MULTIPLY = 0x10AA,
|
||||
KEY_KP_DIVIDE = 0x10AF,
|
||||
KEY_KP_ENTER = 0x108D,
|
||||
KEY_KP_HOME = 0x10B7,
|
||||
KEY_KP_UP = 0x10B8,
|
||||
KEY_KP_PG_UP = 0x10B9,
|
||||
KEY_KP_LEFT = 0x10B4,
|
||||
KEY_KP_FIVE = 0x10B5,
|
||||
KEY_KP_RIGHT = 0x10B6,
|
||||
KEY_KP_END = 0x10B1,
|
||||
KEY_KP_DOWN = 0x10B2,
|
||||
KEY_KP_PG_DOWN = 0x10B3,
|
||||
KEY_KP_INSERT = 0x10B0,
|
||||
KEY_KP_DELETE = 0x10AE,
|
||||
KEY_F1 = 0x00BE,
|
||||
KEY_F2 = 0x00BF,
|
||||
KEY_F3 = 0x00C0,
|
||||
KEY_F4 = 0x00C1,
|
||||
KEY_F5 = 0x00C2,
|
||||
KEY_F6 = 0x00C3,
|
||||
KEY_F7 = 0x00C4,
|
||||
KEY_F8 = 0x00C5,
|
||||
KEY_F9 = 0x00C6,
|
||||
KEY_F10 = 0x00C7,
|
||||
KEY_F11 = 0x00C8,
|
||||
KEY_F12 = 0x00C9,
|
||||
KEY_SPACE = ' ',
|
||||
KEY_EXCLAM = '!',
|
||||
KEY_QUOTE = '"',
|
||||
KEY_NUMBER = '#',
|
||||
KEY_DOLLAR = '$',
|
||||
KEY_PERCENT = '%',
|
||||
KEY_CIRCUMFLEX = '^',
|
||||
KEY_AMPERSAND = '&',
|
||||
KEY_APOSTROPHE = '\'',
|
||||
KEY_LEFT_PARENTHESIS = '(',
|
||||
KEY_RIGHT_PARENTHESIS = ')',
|
||||
KEY_ASTERISK = '*',
|
||||
KEY_PLUS = '+',
|
||||
KEY_COMMA = ',',
|
||||
KEY_MINUS = '-',
|
||||
KEY_PERIOD = '.',
|
||||
KEY_SLASH = '/',
|
||||
KEY_0 = '0',
|
||||
KEY_1 = '1',
|
||||
KEY_2 = '2',
|
||||
KEY_3 = '3',
|
||||
KEY_4 = '4',
|
||||
KEY_5 = '5',
|
||||
KEY_6 = '6',
|
||||
KEY_7 = '7',
|
||||
KEY_8 = '8',
|
||||
KEY_9 = '9',
|
||||
KEY_COLON = ':',
|
||||
KEY_SEMICOLON = ';',
|
||||
KEY_LESS_THAN = '<',
|
||||
KEY_EQUAL = '=',
|
||||
KEY_GREATER_THAN = '>',
|
||||
KEY_QUESTION = '?',
|
||||
KEY_AT = '@',
|
||||
KEY_CAPITAL_A = 'A',
|
||||
KEY_CAPITAL_B = 'B',
|
||||
KEY_CAPITAL_C = 'C',
|
||||
KEY_CAPITAL_D = 'D',
|
||||
KEY_CAPITAL_E = 'E',
|
||||
KEY_CAPITAL_F = 'F',
|
||||
KEY_CAPITAL_G = 'G',
|
||||
KEY_CAPITAL_H = 'H',
|
||||
KEY_CAPITAL_I = 'I',
|
||||
KEY_CAPITAL_J = 'J',
|
||||
KEY_CAPITAL_K = 'K',
|
||||
KEY_CAPITAL_L = 'L',
|
||||
KEY_CAPITAL_M = 'M',
|
||||
KEY_CAPITAL_N = 'N',
|
||||
KEY_CAPITAL_O = 'O',
|
||||
KEY_CAPITAL_P = 'P',
|
||||
KEY_CAPITAL_Q = 'Q',
|
||||
KEY_CAPITAL_R = 'R',
|
||||
KEY_CAPITAL_S = 'S',
|
||||
KEY_CAPITAL_T = 'T',
|
||||
KEY_CAPITAL_U = 'U',
|
||||
KEY_CAPITAL_V = 'V',
|
||||
KEY_CAPITAL_W = 'W',
|
||||
KEY_CAPITAL_X = 'X',
|
||||
KEY_CAPITAL_Y = 'Y',
|
||||
KEY_CAPITAL_Z = 'Z',
|
||||
KEY_LEFT_BRACKET = '[',
|
||||
KEY_BACK_SLASH = '\\',
|
||||
KEY_RIGHT_BRACKET = ']',
|
||||
KEY_UNDERSCORE = '_',
|
||||
KEY_GRAVE = '`',
|
||||
KEY_A = 'a',
|
||||
KEY_B = 'b',
|
||||
KEY_C = 'c',
|
||||
KEY_D = 'd',
|
||||
KEY_E = 'e',
|
||||
KEY_F = 'f',
|
||||
KEY_G = 'g',
|
||||
KEY_H = 'h',
|
||||
KEY_I = 'i',
|
||||
KEY_J = 'j',
|
||||
KEY_K = 'k',
|
||||
KEY_L = 'l',
|
||||
KEY_M = 'm',
|
||||
KEY_N = 'n',
|
||||
KEY_O = 'o',
|
||||
KEY_P = 'p',
|
||||
KEY_Q = 'q',
|
||||
KEY_R = 'r',
|
||||
KEY_S = 's',
|
||||
KEY_T = 't',
|
||||
KEY_U = 'u',
|
||||
KEY_V = 'v',
|
||||
KEY_W = 'w',
|
||||
KEY_X = 'x',
|
||||
KEY_Y = 'y',
|
||||
KEY_Z = 'z',
|
||||
KEY_LEFT_BRACE = '{',
|
||||
KEY_BAR = '|',
|
||||
KEY_RIGHT_BRACE = '}',
|
||||
KEY_TILDE = '~',
|
||||
KEY_EURO = 0x20AC,
|
||||
KEY_POUND = 0x00A3,
|
||||
KEY_YEN = 0x00A5,
|
||||
KEY_MIDDLE_DOT = 0x0095,
|
||||
KEY_SEARCH = 0xFFAA,
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -103,43 +103,39 @@ local function main()
|
|||
|
||||
-- handing touch events
|
||||
local touchBeginPoint = nil
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
cclog("onTouchBegan: %0.2f, %0.2f", x, y)
|
||||
touchBeginPoint = {x = x, y = y}
|
||||
local function onTouchBegan(touch, event)
|
||||
local location = touch:getLocation()
|
||||
cclog("onTouchBegan: %0.2f, %0.2f", location.x, location.y)
|
||||
touchBeginPoint = {x = location.x, y = location.y}
|
||||
spriteDog.isPaused = true
|
||||
-- CCTOUCHBEGAN event must return true
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchMoved(x, y)
|
||||
cclog("onTouchMoved: %0.2f, %0.2f", x, y)
|
||||
local function onTouchMoved(touch, event)
|
||||
local location = touch:getLocation()
|
||||
cclog("onTouchMoved: %0.2f, %0.2f", location.x, location.y)
|
||||
if touchBeginPoint then
|
||||
local cx, cy = layerFarm:getPosition()
|
||||
layerFarm:setPosition(cx + x - touchBeginPoint.x,
|
||||
cy + y - touchBeginPoint.y)
|
||||
touchBeginPoint = {x = x, y = y}
|
||||
layerFarm:setPosition(cx + location.x - touchBeginPoint.x,
|
||||
cy + location.y - touchBeginPoint.y)
|
||||
touchBeginPoint = {x = location.x, y = location.y}
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouchEnded(x, y)
|
||||
cclog("onTouchEnded: %0.2f, %0.2f", x, y)
|
||||
local function onTouchEnded(touch, event)
|
||||
local location = touch:getLocation()
|
||||
cclog("onTouchEnded: %0.2f, %0.2f", location.x, location.y)
|
||||
touchBeginPoint = nil
|
||||
spriteDog.isPaused = false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x, y)
|
||||
elseif eventType == "moved" then
|
||||
return onTouchMoved(x, y)
|
||||
else
|
||||
return onTouchEnded(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
layerFarm:registerScriptTouchHandler(onTouch)
|
||||
layerFarm:setTouchEnabled(true)
|
||||
local listener = cc.EventListenerTouchOneByOne:create()
|
||||
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
|
||||
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
|
||||
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
|
||||
local eventDispatcher = layerFarm:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layerFarm)
|
||||
|
||||
return layerFarm
|
||||
end
|
||||
|
|
|
@ -5,54 +5,60 @@ local function AccelerometerMainLayer()
|
|||
end
|
||||
local layer = cc.Layer:create()
|
||||
|
||||
layer:setAccelerometerEnabled(true)
|
||||
local function onEnter()
|
||||
layer:setAccelerometerEnabled(true)
|
||||
|
||||
local label = cc.LabelTTF:create(title(), "Arial", 32)
|
||||
layer:addChild(label, 1)
|
||||
label:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 50) )
|
||||
local label = cc.LabelTTF:create(title(), "Arial", 32)
|
||||
layer:addChild(label, 1)
|
||||
label:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 50) )
|
||||
|
||||
local ball = cc.Sprite:create("Images/ball.png")
|
||||
ball:setPosition(cc.p(VisibleRect:center().x, VisibleRect:center().y))
|
||||
layer:addChild(ball)
|
||||
local ball = cc.Sprite:create("Images/ball.png")
|
||||
ball:setPosition(cc.p(VisibleRect:center().x, VisibleRect:center().y))
|
||||
layer:addChild(ball)
|
||||
|
||||
ball:retain()
|
||||
|
||||
local function didAccelerate(x,y,z,timestamp)
|
||||
local function accelerometerListener(event,x,y,z,timestamp)
|
||||
local target = event:getCurrentTarget()
|
||||
local ballSize = target:getContentSize()
|
||||
local ptNowX,ptNowY = target:getPosition()
|
||||
ptNowX = ptNowX + x * 9.81
|
||||
ptNowY = ptNowY + y * 9.81
|
||||
|
||||
if nil == ball then
|
||||
return
|
||||
end
|
||||
|
||||
local director = cc.Director:getInstance()
|
||||
local szBall = ball:getContentSize()
|
||||
local ptNowX,ptNowY = ball:getPosition()
|
||||
local ptTemp = director:convertToUI(cc.p(ptNowX,ptNowY))
|
||||
|
||||
ptTemp.x = ptTemp.x + x * 9.81
|
||||
ptTemp.y = ptTemp.y - y * 9.81
|
||||
|
||||
local ptNext = director:convertToGL(cc.p(ptTemp.x,ptTemp.y))
|
||||
|
||||
local minX = math.floor(VisibleRect:left().x + szBall.width / 2.0)
|
||||
local maxX = math.floor(VisibleRect:right().x - szBall.width / 2.0)
|
||||
if ptNext.x < minX then
|
||||
ptNext.x = minX
|
||||
elseif ptNext.x > maxX then
|
||||
ptNext.x = maxX
|
||||
end
|
||||
local minX = math.floor(VisibleRect:left().x + ballSize.width / 2.0)
|
||||
local maxX = math.floor(VisibleRect:right().x - ballSize.width / 2.0)
|
||||
if ptNowX < minX then
|
||||
ptNowX = minX
|
||||
elseif ptNowX > maxX then
|
||||
ptNowX = maxX
|
||||
end
|
||||
|
||||
local minY = math.floor(VisibleRect:bottom().y + szBall.height / 2.0)
|
||||
local maxY = math.floor(VisibleRect:top().y - szBall.height / 2.0)
|
||||
if ptNext.y < minY then
|
||||
ptNext.y = minY
|
||||
elseif ptNext.y > maxY then
|
||||
ptNext.y = maxY
|
||||
end
|
||||
|
||||
ball:setPosition(cc.p(ptNext.x , ptNext.y))
|
||||
local minY = math.floor(VisibleRect:bottom().y + ballSize.height / 2.0)
|
||||
local maxY = math.floor(VisibleRect:top().y - ballSize.height / 2.0)
|
||||
if ptNowY < minY then
|
||||
ptNowY = minY
|
||||
elseif ptNowY > maxY then
|
||||
ptNowY = maxY
|
||||
end
|
||||
|
||||
target:setPosition(cc.p(ptNowX , ptNowY))
|
||||
end
|
||||
|
||||
local listerner = cc.EventListenerAcceleration:create(accelerometerListener)
|
||||
layer:getEventDispatcher():addEventListenerWithSceneGraphPriority(listerner,ball)
|
||||
end
|
||||
|
||||
layer:registerScriptAccelerateHandler(didAccelerate)
|
||||
|
||||
local function onExit()
|
||||
layer:setAccelerometerEnabled(false)
|
||||
end
|
||||
|
||||
local function onNodeEvent(event)
|
||||
if "enter" == event then
|
||||
onEnter()
|
||||
elseif "exit" == event then
|
||||
onExit()
|
||||
end
|
||||
end
|
||||
|
||||
layer:registerScriptHandler(onNodeEvent)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
local MAX_COUNT = 9;
|
||||
local LINE_SPACE = 40;
|
||||
local kItemTagBasic = 5432;
|
||||
local MAX_COUNT = 9
|
||||
local LINE_SPACE = 40
|
||||
local kItemTagBasic = 5432
|
||||
|
||||
local Winsize = cc.Director:getInstance():getWinSize();
|
||||
local Winsize = cc.Director:getInstance():getWinSize()
|
||||
|
||||
local testNames = {
|
||||
"Bug-350",
|
||||
|
@ -18,8 +18,8 @@ local testNames = {
|
|||
|
||||
local function CreateBugsTestBackMenuItem(pLayer)
|
||||
cc.MenuItemFont:setFontName("Arial")
|
||||
cc.MenuItemFont:setFontSize(24);
|
||||
local pMenuItemFont = cc.MenuItemFont:create("Back");
|
||||
cc.MenuItemFont:setFontSize(24)
|
||||
local pMenuItemFont = cc.MenuItemFont:create("Back")
|
||||
pMenuItemFont:setPosition(cc.p(VisibleRect:rightBottom().x - 50, VisibleRect:rightBottom().y + 25))
|
||||
local function menuCallback()
|
||||
local pScene = BugsTestMain()
|
||||
|
@ -37,9 +37,9 @@ end
|
|||
--BugTest350
|
||||
local function BugTest350()
|
||||
local pLayer = cc.Layer:create()
|
||||
local pBackground = cc.Sprite:create("Hello.png");
|
||||
pBackground:setPosition(cc.p(Winsize.width/2, Winsize.height/2));
|
||||
pLayer:addChild(pBackground);
|
||||
local pBackground = cc.Sprite:create("Hello.png")
|
||||
pBackground:setPosition(cc.p(Winsize.width/2, Winsize.height/2))
|
||||
pLayer:addChild(pBackground)
|
||||
return pLayer
|
||||
end
|
||||
|
||||
|
@ -55,7 +55,7 @@ local function BugTest422()
|
|||
print(strLog)
|
||||
end
|
||||
|
||||
pResetLayer:removeChild(pNode, false);
|
||||
pResetLayer:removeChild(pNode, false)
|
||||
|
||||
local function menuCallback(tag,pMenuItem)
|
||||
if nil ~= pMenuItem then
|
||||
|
@ -64,7 +64,7 @@ local function BugTest422()
|
|||
end
|
||||
end
|
||||
cc.MenuItemFont:setFontName("Arial")
|
||||
cc.MenuItemFont:setFontSize(24);
|
||||
cc.MenuItemFont:setFontSize(24)
|
||||
local pMenuItem1 = cc.MenuItemFont:create("One")
|
||||
pMenuItem1:registerScriptTapHandler(menuCallback)
|
||||
local pMenuItem2 = cc.MenuItemFont:create("Two")
|
||||
|
@ -90,15 +90,15 @@ local function BugTest458()
|
|||
|
||||
local function InitQuestionContainerSprite(pSprite)
|
||||
--Add label
|
||||
local pLabel = cc.LabelTTF:create("Answer 1", "Arial", 12);
|
||||
pLabel:setTag(100);
|
||||
local pLabel = cc.LabelTTF:create("Answer 1", "Arial", 12)
|
||||
pLabel:setTag(100)
|
||||
|
||||
--Add the background
|
||||
local pCorner = cc.Sprite:create("Images/bugs/corner.png");
|
||||
local nWidth = Winsize.width * 0.9 - (pCorner:getContentSize().width * 2);
|
||||
local nHeight = Winsize.height * 0.15 - (pCorner:getContentSize().height * 2);
|
||||
local pColorLayer = cc.LayerColor:create(cc.c4b(255, 255, 255, 255 * .75), nWidth, nHeight);
|
||||
pColorLayer:setPosition(cc.p(-nWidth / 2, -nHeight / 2));
|
||||
local pCorner = cc.Sprite:create("Images/bugs/corner.png")
|
||||
local nWidth = Winsize.width * 0.9 - (pCorner:getContentSize().width * 2)
|
||||
local nHeight = Winsize.height * 0.15 - (pCorner:getContentSize().height * 2)
|
||||
local pColorLayer = cc.LayerColor:create(cc.c4b(255, 255, 255, 255 * .75), nWidth, nHeight)
|
||||
pColorLayer:setPosition(cc.p(-nWidth / 2, -nHeight / 2))
|
||||
--First button is blue,Second is red,Used for testing - change later
|
||||
if (0 == nColorFlag) then
|
||||
pLabel:setColor(cc.c3b(0,0,255))
|
||||
|
@ -106,53 +106,53 @@ local function BugTest458()
|
|||
print("Color changed")
|
||||
pLabel:setColor(cc.c3b(255,0,0))
|
||||
end
|
||||
nColorFlag = nColorFlag + 1;
|
||||
pSprite:addChild(pColorLayer);
|
||||
nColorFlag = nColorFlag + 1
|
||||
pSprite:addChild(pColorLayer)
|
||||
|
||||
pCorner:setPosition(cc.p(-(nWidth / 2 + pCorner:getContentSize().width / 2), -(nHeight / 2 + pCorner:getContentSize().height / 2)));
|
||||
pSprite:addChild(pCorner);
|
||||
pCorner:setPosition(cc.p(-(nWidth / 2 + pCorner:getContentSize().width / 2), -(nHeight / 2 + pCorner:getContentSize().height / 2)))
|
||||
pSprite:addChild(pCorner)
|
||||
|
||||
local nX,nY = pCorner:getPosition()
|
||||
local pCorner2 = cc.Sprite:create("Images/bugs/corner.png");
|
||||
pCorner2:setPosition(cc.p(-nX, nY));
|
||||
pCorner2:setFlipX(true);
|
||||
pSprite:addChild(pCorner2);
|
||||
local pCorner2 = cc.Sprite:create("Images/bugs/corner.png")
|
||||
pCorner2:setPosition(cc.p(-nX, nY))
|
||||
pCorner2:setFlipX(true)
|
||||
pSprite:addChild(pCorner2)
|
||||
|
||||
local pCorner3 = cc.Sprite:create("Images/bugs/corner.png");
|
||||
pCorner3:setPosition(cc.p(nX, -nY));
|
||||
pCorner3:setFlipY(true);
|
||||
pSprite:addChild(pCorner3);
|
||||
local pCorner3 = cc.Sprite:create("Images/bugs/corner.png")
|
||||
pCorner3:setPosition(cc.p(nX, -nY))
|
||||
pCorner3:setFlipY(true)
|
||||
pSprite:addChild(pCorner3)
|
||||
|
||||
local pCorner4 = cc.Sprite:create("Images/bugs/corner.png");
|
||||
pCorner4:setPosition(cc.p(-nX, -nY));
|
||||
pCorner4:setFlipX(true);
|
||||
pCorner4:setFlipY(true);
|
||||
pSprite:addChild(pCorner4);
|
||||
local pCorner4 = cc.Sprite:create("Images/bugs/corner.png")
|
||||
pCorner4:setPosition(cc.p(-nX, -nY))
|
||||
pCorner4:setFlipX(true)
|
||||
pCorner4:setFlipY(true)
|
||||
pSprite:addChild(pCorner4)
|
||||
|
||||
local pEdge = cc.Sprite:create("Images/bugs/edge.png");
|
||||
pEdge:setScaleX(nWidth);
|
||||
pEdge:setPosition(cc.p(nX + (pCorner:getContentSize().width / 2) + (nWidth / 2), nY));
|
||||
pSprite:addChild(pEdge);
|
||||
local pEdge = cc.Sprite:create("Images/bugs/edge.png")
|
||||
pEdge:setScaleX(nWidth)
|
||||
pEdge:setPosition(cc.p(nX + (pCorner:getContentSize().width / 2) + (nWidth / 2), nY))
|
||||
pSprite:addChild(pEdge)
|
||||
|
||||
local pEdge2 = cc.Sprite:create("Images/bugs/edge.png");
|
||||
pEdge2:setScaleX(nWidth);
|
||||
pEdge2:setPosition(cc.p(nX + (pCorner:getContentSize().width / 2) + (nWidth / 2), -nY));
|
||||
pEdge2:setFlipY(true);
|
||||
pSprite:addChild(pEdge2);
|
||||
local pEdge2 = cc.Sprite:create("Images/bugs/edge.png")
|
||||
pEdge2:setScaleX(nWidth)
|
||||
pEdge2:setPosition(cc.p(nX + (pCorner:getContentSize().width / 2) + (nWidth / 2), -nY))
|
||||
pEdge2:setFlipY(true)
|
||||
pSprite:addChild(pEdge2)
|
||||
|
||||
local pEdge3 = cc.Sprite:create("Images/bugs/edge.png");
|
||||
pEdge3:setRotation(90);
|
||||
pEdge3:setScaleX(nHeight);
|
||||
pEdge3:setPosition(cc.p(nX, nY + (pCorner:getContentSize().height / 2) + (nHeight / 2)));
|
||||
pSprite:addChild(pEdge3);
|
||||
local pEdge3 = cc.Sprite:create("Images/bugs/edge.png")
|
||||
pEdge3:setRotation(90)
|
||||
pEdge3:setScaleX(nHeight)
|
||||
pEdge3:setPosition(cc.p(nX, nY + (pCorner:getContentSize().height / 2) + (nHeight / 2)))
|
||||
pSprite:addChild(pEdge3)
|
||||
|
||||
local pEdge4 = cc.Sprite:create("Images/bugs/edge.png");
|
||||
pEdge4:setRotation(270);
|
||||
pEdge4:setScaleX(nHeight);
|
||||
pEdge4:setPosition(cc.p(-nX, nY + (pCorner:getContentSize().height / 2) + (nHeight / 2)));
|
||||
pSprite:addChild(pEdge4);
|
||||
local pEdge4 = cc.Sprite:create("Images/bugs/edge.png")
|
||||
pEdge4:setRotation(270)
|
||||
pEdge4:setScaleX(nHeight)
|
||||
pEdge4:setPosition(cc.p(-nX, nY + (pCorner:getContentSize().height / 2) + (nHeight / 2)))
|
||||
pSprite:addChild(pEdge4)
|
||||
|
||||
pSprite:addChild(pLabel);
|
||||
pSprite:addChild(pLabel)
|
||||
end
|
||||
|
||||
local pQuestion1 = cc.Sprite:create()
|
||||
|
@ -165,19 +165,19 @@ local function BugTest458()
|
|||
end
|
||||
local pMenuItemSprite = cc.MenuItemSprite:create(pQuestion1,pQuestion2)
|
||||
pMenuItemSprite:registerScriptTapHandler(menuCallback)
|
||||
local pLayerColor1 = cc.LayerColor:create(cc.c4b(0,0,255,255), 100, 100);
|
||||
-- question->release();
|
||||
-- question2->release();
|
||||
local pLayerColor1 = cc.LayerColor:create(cc.c4b(0,0,255,255), 100, 100)
|
||||
-- question->release()
|
||||
-- question2->release()
|
||||
|
||||
local pLayerColor2 = cc.LayerColor:create(cc.c4b(255,0,0,255), 100, 100);
|
||||
local pMenuItemSprite2 = cc.MenuItemSprite:create(pLayerColor1, pLayerColor2);
|
||||
local pLayerColor2 = cc.LayerColor:create(cc.c4b(255,0,0,255), 100, 100)
|
||||
local pMenuItemSprite2 = cc.MenuItemSprite:create(pLayerColor1, pLayerColor2)
|
||||
pMenuItemSprite2:registerScriptTapHandler(menuCallback)
|
||||
local pMenu = cc.Menu:create(pMenuItemSprite, pMenuItemSprite2)
|
||||
pMenu:alignItemsVerticallyWithPadding(100);
|
||||
pMenu:setPosition(cc.p(Winsize.width / 2, Winsize.height / 2));
|
||||
pMenu:alignItemsVerticallyWithPadding(100)
|
||||
pMenu:setPosition(cc.p(Winsize.width / 2, Winsize.height / 2))
|
||||
|
||||
-- add the label as a child to this Layer
|
||||
pLayer:addChild(pMenu);
|
||||
pLayer:addChild(pMenu)
|
||||
|
||||
return pLayer
|
||||
end
|
||||
|
@ -189,21 +189,21 @@ local BugTest624_2_entry = nil
|
|||
local function BugTest624()
|
||||
local pLayer = cc.Layer:create()
|
||||
|
||||
local pLabel = cc.LabelTTF:create("Layer1", "Marker Felt", 36);
|
||||
pLabel:setPosition(cc.p(Winsize.width / 2, Winsize.height / 2));
|
||||
pLayer:addChild(pLabel);
|
||||
pLayer:setAccelerometerEnabled(true);
|
||||
-- schedule(schedule_selector(Bug624Layer::switchLayer), 5.0f);
|
||||
local pLabel = cc.LabelTTF:create("Layer1", "Marker Felt", 36)
|
||||
pLabel:setPosition(cc.p(Winsize.width / 2, Winsize.height / 2))
|
||||
pLayer:addChild(pLabel)
|
||||
pLayer:setAccelerometerEnabled(true)
|
||||
-- schedule(schedule_selector(Bug624Layer::switchLayer), 5.0f)
|
||||
|
||||
local function BugTest624_SwitchLayer()
|
||||
local scheduler = cc.Director:getInstance():getScheduler()
|
||||
scheduler:unscheduleScriptEntry(BugTest624_entry)
|
||||
|
||||
local pScene = cc.Scene:create();
|
||||
local pScene = cc.Scene:create()
|
||||
local pNewPlayer = BugTest624_2()
|
||||
CreateBugsTestBackMenuItem(pNewPlayer)
|
||||
pScene:addChild(pNewPlayer);
|
||||
cc.Director:getInstance():replaceScene(cc.TransitionFade:create(2.0, pScene, cc.c3b(255,255,255)));
|
||||
pScene:addChild(pNewPlayer)
|
||||
cc.Director:getInstance():replaceScene(cc.TransitionFade:create(2.0, pScene, cc.c3b(255,255,255)))
|
||||
end
|
||||
|
||||
|
||||
|
@ -228,20 +228,20 @@ end
|
|||
function BugTest624_2()
|
||||
local pLayer = cc.Layer:create()
|
||||
|
||||
local pLabel = cc.LabelTTF:create("Layer2", "Marker Felt", 36);
|
||||
pLabel:setPosition(cc.p(Winsize.width / 2, Winsize.height / 2));
|
||||
pLayer:addChild(pLabel);
|
||||
pLayer:setAccelerometerEnabled(true);
|
||||
local pLabel = cc.LabelTTF:create("Layer2", "Marker Felt", 36)
|
||||
pLabel:setPosition(cc.p(Winsize.width / 2, Winsize.height / 2))
|
||||
pLayer:addChild(pLabel)
|
||||
pLayer:setAccelerometerEnabled(true)
|
||||
|
||||
local function BugTest624_2_SwitchLayer()
|
||||
local scheduler = cc.Director:getInstance():getScheduler()
|
||||
scheduler:unscheduleScriptEntry(BugTest624_2_entry)
|
||||
|
||||
local pScene = cc.Scene:create();
|
||||
local pScene = cc.Scene:create()
|
||||
local pNewPlayer = BugTest624()
|
||||
CreateBugsTestBackMenuItem(pNewPlayer)
|
||||
pScene:addChild(pNewPlayer);
|
||||
cc.Director:getInstance():replaceScene(cc.TransitionFade:create(2.0, pScene, cc.c3b(255,0,0)));
|
||||
pScene:addChild(pNewPlayer)
|
||||
cc.Director:getInstance():replaceScene(cc.TransitionFade:create(2.0, pScene, cc.c3b(255,0,0)))
|
||||
end
|
||||
|
||||
local function BugTest624_2_OnEnterOrExit(tag)
|
||||
|
@ -294,65 +294,58 @@ end
|
|||
|
||||
--BugTest914
|
||||
local function BugTest914()
|
||||
local pLayer = cc.Layer:create()
|
||||
local layer = cc.Layer:create()
|
||||
|
||||
pLayer:setTouchEnabled(true);
|
||||
|
||||
local pLayerColor = nil
|
||||
local layerColor = nil
|
||||
|
||||
for i = 0, 4 do
|
||||
pLayerColor = cc.LayerColor:create(cc.c4b(i*20, i*20, i*20,255))
|
||||
pLayerColor:setContentSize(cc.size(i*100, i*100));
|
||||
pLayerColor:setPosition(cc.p(Winsize.width/2, Winsize.height/2))
|
||||
pLayerColor:setAnchorPoint(cc.p(0.5, 0.5));
|
||||
pLayerColor:ignoreAnchorPointForPosition(false);
|
||||
pLayer:addChild(pLayerColor, -1-i);
|
||||
layerColor = cc.LayerColor:create(cc.c4b(i*20, i*20, i*20,255))
|
||||
layerColor:setContentSize(cc.size(i*100, i*100))
|
||||
layerColor:setPosition(cc.p(Winsize.width/2, Winsize.height/2))
|
||||
layerColor:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
layerColor:ignoreAnchorPointForPosition(false)
|
||||
layer:addChild(layerColor, -1-i)
|
||||
end
|
||||
|
||||
--create and initialize a Label
|
||||
local function restart()
|
||||
local pScene = cc.Scene:create()
|
||||
local pLayer = BugTest914()
|
||||
CreateBugsTestBackMenuItem(pLayer)
|
||||
pScene:addChild(pLayer);
|
||||
cc.Director:getInstance():replaceScene(pScene)
|
||||
local scene = cc.Scene:create()
|
||||
local newLayer = BugTest914()
|
||||
CreateBugsTestBackMenuItem(newLayer)
|
||||
scene:addChild(newLayer)
|
||||
cc.Director:getInstance():replaceScene(scene)
|
||||
end
|
||||
|
||||
local label = cc.LabelTTF:create("Hello World", "Marker Felt", 64)
|
||||
--position the label on the center of the screen
|
||||
label:setPosition(cc.p( Winsize.width /2 , Winsize.height/2 ));
|
||||
pLayer:addChild(label);
|
||||
label:setPosition(cc.p( Winsize.width /2 , Winsize.height/2 ))
|
||||
layer:addChild(label)
|
||||
|
||||
local item1 = cc.MenuItemFont:create("restart")
|
||||
item1:registerScriptTapHandler(restart)
|
||||
--Bug914Layer::restart));
|
||||
|
||||
local menu = cc.Menu:create()
|
||||
menu:addChild(item1)
|
||||
menu:alignItemsVertically()
|
||||
menu:setPosition(cc.p(Winsize.width/2, 100))
|
||||
pLayer:addChild(menu)
|
||||
layer:addChild(menu)
|
||||
|
||||
-- handling touch events
|
||||
local function onTouchMoved(tableArray)
|
||||
local nCount = table.getn(tableArray)
|
||||
nCount = math.floor(nCount / 3)
|
||||
print(nCount)
|
||||
local function onTouchMoved(touches, event)
|
||||
local count = table.getn(touches)
|
||||
print("Number of touches: ",count)
|
||||
end
|
||||
local function onTouchBegan(tableArray)
|
||||
onTouchMoved(tableArray)
|
||||
local function onTouchBegan(touches, event)
|
||||
onTouchMoved(touches, event)
|
||||
end
|
||||
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
|
||||
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
|
||||
local function onTouch(eventType,tableArray)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(tableArray)
|
||||
elseif eventType == "moved" then
|
||||
return onTouchMoved(tableArray)
|
||||
end
|
||||
end
|
||||
pLayer:registerScriptTouchHandler(onTouch,true)
|
||||
return pLayer
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
--BugTest1159
|
||||
|
@ -372,25 +365,25 @@ local function BugTest1159()
|
|||
local seq = cc.Sequence:create(cc.MoveTo:create(1.0, cc.p(1024.0, 384.0)), cc.MoveTo:create(1.0, cc.p(0.0, 384.0)))
|
||||
sprite_a:runAction(cc.RepeatForever:create(seq))
|
||||
|
||||
local sprite_b = cc.LayerColor:create(cc.c4b(0, 0, 255, 255), 400, 400);
|
||||
local sprite_b = cc.LayerColor:create(cc.c4b(0, 0, 255, 255), 400, 400)
|
||||
sprite_b:setAnchorPoint(cc.p(0.5, 0.5))
|
||||
sprite_b:ignoreAnchorPointForPosition(false);
|
||||
sprite_b:setPosition(cc.p(Winsize.width/2, Winsize.height/2));
|
||||
pLayer:addChild(sprite_b);
|
||||
sprite_b:ignoreAnchorPointForPosition(false)
|
||||
sprite_b:setPosition(cc.p(Winsize.width/2, Winsize.height/2))
|
||||
pLayer:addChild(sprite_b)
|
||||
|
||||
local function menuCallback()
|
||||
local pScene = cc.Scene:create()
|
||||
local pLayer = BugTest1159()
|
||||
CreateBugsTestBackMenuItem(pLayer)
|
||||
pScene:addChild(pLayer);
|
||||
pScene:addChild(pLayer)
|
||||
cc.Director:getInstance():replaceScene(cc.TransitionPageTurn:create(1.0, pScene, false))
|
||||
end
|
||||
local label = cc.MenuItemLabel:create(cc.LabelTTF:create("Flip Me", "Helvetica", 24));
|
||||
local label = cc.MenuItemLabel:create(cc.LabelTTF:create("Flip Me", "Helvetica", 24))
|
||||
label:registerScriptTapHandler(menuCallback)
|
||||
local menu = cc.Menu:create();
|
||||
local menu = cc.Menu:create()
|
||||
menu:addChild(label)
|
||||
menu:setPosition(cc.p(Winsize.width - 200.0, 50.0));
|
||||
pLayer:addChild(menu);
|
||||
menu:setPosition(cc.p(Winsize.width - 200.0, 50.0))
|
||||
pLayer:addChild(menu)
|
||||
|
||||
local function onNodeEvent(event)
|
||||
if event == "exit" then
|
||||
|
@ -436,7 +429,7 @@ local function BugTest1174()
|
|||
local bRet = false
|
||||
|
||||
print("Test1 - Start")
|
||||
local i = 0;
|
||||
local i = 0
|
||||
for i = 0, 9999 do
|
||||
--[[
|
||||
A|b
|
||||
|
@ -490,12 +483,12 @@ local function BugTest1174()
|
|||
--------
|
||||
print("Test2 - Start")
|
||||
|
||||
p1 = cc.p(220,480);
|
||||
p2 = cc.p(304,325);
|
||||
p3 = cc.p(264,416);
|
||||
p4 = cc.p(186,416);
|
||||
s = 0.0;
|
||||
t = 0.0;
|
||||
p1 = cc.p(220,480)
|
||||
p2 = cc.p(304,325)
|
||||
p3 = cc.p(264,416)
|
||||
p4 = cc.p(186,416)
|
||||
s = 0.0
|
||||
t = 0.0
|
||||
bRet,s,t = cc.pIsLineIntersect( p1, p2, p3, p4, s, t)
|
||||
if true == bRet then
|
||||
check_for_error(p1, p2, p3, p4, s, t)
|
||||
|
@ -515,7 +508,7 @@ local function BugTest1174()
|
|||
-- c | d
|
||||
local ax = math.random() * -500
|
||||
local ay = math.random() * 500
|
||||
p1 = cc.p(ax,ay);
|
||||
p1 = cc.p(ax,ay)
|
||||
-- a | b
|
||||
-- -----
|
||||
-- c | D
|
||||
|
@ -579,7 +572,7 @@ end
|
|||
|
||||
|
||||
local function BugsTestMainLayer()
|
||||
local ret = cc.Layer:create();
|
||||
local ret = cc.Layer:create()
|
||||
|
||||
--menu callback
|
||||
local function menuCallback(tag, pMenuItem)
|
||||
|
@ -591,8 +584,8 @@ local function BugsTestMainLayer()
|
|||
end
|
||||
|
||||
-- add menu items for tests
|
||||
local pItemMenu = cc.Menu:create();
|
||||
local nTestCount = table.getn(testNames);
|
||||
local pItemMenu = cc.Menu:create()
|
||||
local nTestCount = table.getn(testNames)
|
||||
|
||||
local i = 1
|
||||
for i = 1, nTestCount do
|
||||
|
@ -605,19 +598,15 @@ local function BugsTestMainLayer()
|
|||
|
||||
pItemMenu:setPosition(cc.p(0, 0))
|
||||
ret:addChild(pItemMenu)
|
||||
ret:setTouchEnabled(true)
|
||||
|
||||
-- handling touch events
|
||||
local ptBeginPos = {x = 0, y = 0}
|
||||
local ptCurPos = {x = 0, y = 0}
|
||||
local function onTouchBegan(x, y)
|
||||
ptBeginPos = {x = x, y = y}
|
||||
-- cc.TOUCHBEGAN event must return true
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchMoved(x, y)
|
||||
local nMoveY = y - ptBeginPos.y
|
||||
|
||||
-- handling touch events
|
||||
local function onTouchMoved(touches, event)
|
||||
local touchLocation = touches[1]:getLocation()
|
||||
local nMoveY = touchLocation.y - ptBeginPos.y
|
||||
local curPosx, curPosy = pItemMenu:getPosition()
|
||||
local nextPosy = curPosy + nMoveY
|
||||
if nextPosy < 0 then
|
||||
|
@ -631,26 +620,25 @@ local function BugsTestMainLayer()
|
|||
end
|
||||
|
||||
pItemMenu:setPosition(curPosx, nextPosy)
|
||||
ptBeginPos = {x = x, y = y}
|
||||
ptBeginPos = touchLocation
|
||||
ptCurPos = {x = curPosx, y = nextPosy}
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x, y)
|
||||
elseif eventType == "moved" then
|
||||
return onTouchMoved(x, y)
|
||||
end
|
||||
local function onTouchBegan(touches, event)
|
||||
ptBeginPos = touches[1]:getLocation()
|
||||
end
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
|
||||
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
|
||||
ret:registerScriptTouchHandler(onTouch)
|
||||
local eventDispatcher = ret:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, ret)
|
||||
|
||||
return ret
|
||||
end
|
||||
function BugsTestMain()
|
||||
cclog("BugsTestMain");
|
||||
local scene = cc.Scene:create();
|
||||
scene:addChild(BugsTestMainLayer());
|
||||
scene:addChild(CreateBackMenuItem());
|
||||
return scene;
|
||||
cclog("BugsTestMain")
|
||||
local scene = cc.Scene:create()
|
||||
scene:addChild(BugsTestMainLayer())
|
||||
scene:addChild(CreateBackMenuItem())
|
||||
return scene
|
||||
end
|
||||
|
|
|
@ -17,13 +17,20 @@ local function initWithLayer()
|
|||
cc.FadeIn:create(1),
|
||||
cc.FadeOut:create(1))))
|
||||
|
||||
local function onTouchEnded(x, y)
|
||||
local function onTouchBegan(touch, event)
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchEnded(touch, event)
|
||||
|
||||
local location = touch:getLocation()
|
||||
|
||||
local s = layer:getChildByTag(kTagSprite)
|
||||
s:stopAllActions()
|
||||
s:runAction(cc.MoveTo:create(1, cc.p(x, y)))
|
||||
s:runAction(cc.MoveTo:create(1, cc.p(location.x, location.y)))
|
||||
local posX, posY = s:getPosition()
|
||||
local o = x - posX
|
||||
local a = y - posY
|
||||
local o = location.x - posX
|
||||
local a = location.y - posY
|
||||
local at = math.atan(o / a) / math.pi * 180.0
|
||||
|
||||
if a < 0 then
|
||||
|
@ -36,16 +43,11 @@ local function initWithLayer()
|
|||
s:runAction(cc.RotateTo:create(1, at))
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return true
|
||||
elseif eventType == "ended" then
|
||||
return onTouchEnded(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
layer:setTouchEnabled(true)
|
||||
layer:registerScriptTouchHandler(onTouch)
|
||||
local listener = cc.EventListenerTouchOneByOne:create()
|
||||
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
|
||||
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
|
|
@ -812,7 +812,6 @@ function TestParticleDisplay.extend(target)
|
|||
end
|
||||
|
||||
function TestParticleDisplay:onEnter()
|
||||
self:setTouchEnabled(true)
|
||||
self.animationID = 0
|
||||
|
||||
self.armature = ccs.Armature:create("robot")
|
||||
|
@ -840,19 +839,17 @@ function TestParticleDisplay:onEnter()
|
|||
bone:setScale(1.2)
|
||||
self.armature:addBone(bone, "bady-a30")
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
-- handling touch events
|
||||
local function onTouchEnded(touches, event)
|
||||
self.animationID = (self.animationID + 1) % self.armature:getAnimation():getMovementCount()
|
||||
self.armature:getAnimation():playWithIndex(self.animationID)
|
||||
return false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x,y)
|
||||
end
|
||||
end
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
|
||||
self:registerScriptTouchHandler(onTouch)
|
||||
local eventDispatcher = self:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)
|
||||
end
|
||||
|
||||
function TestParticleDisplay.create()
|
||||
|
@ -889,7 +886,6 @@ function TestUseMutiplePicture.extend(target)
|
|||
end
|
||||
|
||||
function TestUseMutiplePicture:onEnter()
|
||||
self:setTouchEnabled(true)
|
||||
self.displayIndex = 1
|
||||
|
||||
self.armature = ccs.Armature:create("Knight_f/Knight")
|
||||
|
@ -915,19 +911,17 @@ function TestUseMutiplePicture:onEnter()
|
|||
self.armature:getBone("weapon"):addDisplay(skin, i - 1)
|
||||
end
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
-- handling touch events
|
||||
local function onTouchEnded(touches, event)
|
||||
self.displayIndex = (self.displayIndex + 1) % (table.getn(weapon) - 1)
|
||||
self.armature:getBone("weapon"):changeDisplayWithIndex(self.displayIndex, true)
|
||||
return false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x,y)
|
||||
end
|
||||
end
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
|
||||
self:registerScriptTouchHandler(onTouch)
|
||||
local eventDispatcher = self:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)
|
||||
end
|
||||
|
||||
function TestUseMutiplePicture.create()
|
||||
|
@ -1012,7 +1006,6 @@ function TestArmatureNesting.extend(target)
|
|||
end
|
||||
|
||||
function TestArmatureNesting:onEnter()
|
||||
self:setTouchEnabled(true)
|
||||
self.weaponIndex = 0
|
||||
|
||||
self.armature = ccs.Armature:create("cyborg")
|
||||
|
@ -1022,20 +1015,18 @@ function TestArmatureNesting:onEnter()
|
|||
self.armature:getAnimation():setSpeedScale(0.4)
|
||||
self:addChild(self.armature)
|
||||
|
||||
local function onTouchBegan(x, y)
|
||||
-- handling touch events
|
||||
local function onTouchEnded(touches, event)
|
||||
self.weaponIndex = (self.weaponIndex + 1) % 4
|
||||
self.armature:getBone("armInside"):getChildArmature():getAnimation():playWithIndex(self.weaponIndex)
|
||||
self.armature:getBone("armOutside"):getChildArmature():getAnimation():playWithIndex(self.weaponIndex)
|
||||
return false
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x,y)
|
||||
end
|
||||
end
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
|
||||
self:registerScriptTouchHandler(onTouch)
|
||||
local eventDispatcher = self:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)
|
||||
end
|
||||
|
||||
function TestArmatureNesting.create()
|
||||
|
@ -1131,30 +1122,26 @@ function TestArmatureNesting2.extend(target)
|
|||
end
|
||||
|
||||
function TestArmatureNesting2:onEnter()
|
||||
|
||||
self:setTouchEnabled(true)
|
||||
|
||||
local function onTouchesEnded(tableArray)
|
||||
local x,y = tableArray[1],tableArray[2]
|
||||
-- handling touch events
|
||||
local function onTouchEnded(touches, event)
|
||||
local location = touches[1]:getLocation()
|
||||
local armature = self._hero._mount and self._hero._mount or self._hero
|
||||
if x < armature:getPositionX() then
|
||||
if location.x < armature:getPositionX() then
|
||||
armature:setScaleX(-1)
|
||||
else
|
||||
armature:setScaleX(1)
|
||||
end
|
||||
|
||||
local move = cc.MoveTo:create(2, cc.p(x,y))
|
||||
local move = cc.MoveTo:create(2, location)
|
||||
armature:stopAllActions()
|
||||
armature:runAction(cc.Sequence:create(move))
|
||||
end
|
||||
|
||||
local function onTouch(eventType, tableArray)
|
||||
if eventType == "ended" then
|
||||
return onTouchesEnded(tableArray)
|
||||
end
|
||||
end
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
|
||||
self:registerScriptTouchHandler(onTouch,true)
|
||||
local eventDispatcher = self:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, self)
|
||||
|
||||
local function changeMountCallback(sender)
|
||||
self._hero:stopAllActions()
|
||||
|
|
|
@ -108,7 +108,6 @@ local function CocosDenshionTest()
|
|||
m_pItmeMenu:setContentSize(cc.size(VisibleRect:getVisibleRect().width, (m_nTestCount + 1) * LINE_SPACE))
|
||||
m_pItmeMenu:setPosition(cc.p(0, 0))
|
||||
ret:addChild(m_pItmeMenu)
|
||||
ret:setTouchEnabled(true)
|
||||
|
||||
-- preload background music and effect
|
||||
AudioEngine.preloadMusic( MUSIC_FILE )
|
||||
|
@ -159,7 +158,46 @@ local function CocosDenshionTest()
|
|||
end
|
||||
end
|
||||
|
||||
ret:registerScriptTouchHandler(onTouchEvent)
|
||||
local function onTouchBegan(touch, event)
|
||||
local location = touch:getLocation()
|
||||
prev.x = location.x
|
||||
prev.y = location.y
|
||||
m_tBeginPos = location
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchMoved(touch, event)
|
||||
local location = touch:getLocation()
|
||||
local touchLocation = location
|
||||
local nMoveY = touchLocation.y - m_tBeginPos.y
|
||||
local curPosX, curPosY = m_pItmeMenu:getPosition()
|
||||
local curPos = cc.p(curPosX, curPosY)
|
||||
local nextPos = cc.p(curPos.x, curPos.y + nMoveY)
|
||||
|
||||
if nextPos.y < 0.0 then
|
||||
m_pItmeMenu:setPosition(cc.p(0, 0))
|
||||
end
|
||||
|
||||
if nextPos.y > ((m_nTestCount + 1)* LINE_SPACE - VisibleRect:getVisibleRect().height) then
|
||||
m_pItmeMenu:setPosition(cc.p(0, ((m_nTestCount + 1)* LINE_SPACE - VisibleRect:getVisibleRect().height)))
|
||||
end
|
||||
|
||||
m_pItmeMenu:setPosition(nextPos)
|
||||
m_tBeginPos.x = touchLocation.x
|
||||
m_tBeginPos.y = touchLocation.y
|
||||
|
||||
prev.x = location.x
|
||||
prev.y = location.y
|
||||
end
|
||||
|
||||
local listener = cc.EventListenerTouchOneByOne:create()
|
||||
listener:setSwallowTouches(true)
|
||||
|
||||
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
|
||||
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
|
||||
local eventDispatcher = ret:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, ret)
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
|
|
|
@ -1239,14 +1239,15 @@ local function ExtensionsMainLayer()
|
|||
layer:addChild(menu)
|
||||
|
||||
-- handling touch events
|
||||
local beginPos = {x = 0, y = 0}
|
||||
local function onTouchBegan(x, y)
|
||||
beginPos = {x = x, y = y}
|
||||
return true
|
||||
local beginPos = {x = 0, y = 0}
|
||||
local function onTouchesBegan(touches, event)
|
||||
beginPos = touches[1]:getLocation()
|
||||
end
|
||||
|
||||
local function onTouchMoved(x, y)
|
||||
local nMoveY = y - beginPos.y
|
||||
local function onTouchesMoved(touches, event)
|
||||
local location = touches[1]:getLocation()
|
||||
|
||||
local nMoveY = location.y - beginPos.y
|
||||
local curPosx, curPosy = menu:getPosition()
|
||||
local nextPosy = curPosy + nMoveY
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
|
@ -1261,20 +1262,15 @@ local function ExtensionsMainLayer()
|
|||
end
|
||||
|
||||
menu:setPosition(curPosx, nextPosy)
|
||||
beginPos = {x = x, y = y}
|
||||
beginPos = {x = location.x, y = location.y}
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x, y)
|
||||
elseif eventType == "moved" then
|
||||
return onTouchMoved(x, y)
|
||||
end
|
||||
end
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCH_MOVED )
|
||||
|
||||
layer:setTouchEnabled(true)
|
||||
|
||||
layer:registerScriptTouchHandler(onTouch)
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
|
|
@ -1,31 +1,42 @@
|
|||
local function KeypadMainLayer()
|
||||
local pLayer = cc.Layer:create()
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local label = cc.LabelTTF:create("Keypad Test", "Arial", 28)
|
||||
pLayer:addChild(label, 0)
|
||||
label:setPosition( cc.p(s.width/2, s.height-50) )
|
||||
local layer = cc.Layer:create()
|
||||
|
||||
pLayer:setKeypadEnabled(true)
|
||||
local function onEnter()
|
||||
print("come in")
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local label = cc.LabelTTF:create("Keypad Test", "Arial", 28)
|
||||
layer:addChild(label, 0)
|
||||
label:setPosition(cc.p(s.width/2, s.height-50))
|
||||
|
||||
-- create a label to display the tip string
|
||||
local pLabelTip = cc.LabelTTF:create("Please press any key...", "Arial", 22)
|
||||
pLabelTip:setPosition(cc.p(s.width / 2, s.height / 2))
|
||||
pLayer:addChild(pLabelTip, 0)
|
||||
|
||||
pLabelTip:retain()
|
||||
|
||||
local function KeypadHandler(strEvent)
|
||||
if "backClicked" == strEvent then
|
||||
pLabelTip:setString("BACK clicked!");
|
||||
elseif "menuClicked" == strEvent then
|
||||
pLabelTip:setString("MENU clicked!");
|
||||
end
|
||||
local labelTip = cc.LabelTTF:create("Please press any key...", "Arial", 22)
|
||||
labelTip:setPosition(cc.p(s.width / 2, s.height / 2))
|
||||
layer:addChild(labelTip, 0)
|
||||
|
||||
local function onKeyReleased(keyCode, event)
|
||||
local label = event:getCurrentTarget()
|
||||
if keyCode == cc.KeyCode.KEY_BACKSPACE then
|
||||
label:setString("BACK clicked!")
|
||||
elseif keyCode == cc.KeyCode.KEY_MENU then
|
||||
label:setString("MENU clicked!")
|
||||
end
|
||||
end
|
||||
|
||||
local listener = cc.EventListenerKeyboard:create()
|
||||
listener:registerScriptHandler(onKeyReleased, cc.Handler.EVENT_KEYBOARD_RELEASED )
|
||||
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, labelTip)
|
||||
end
|
||||
|
||||
pLayer:registerScriptKeypadHandler(KeypadHandler)
|
||||
|
||||
return pLayer
|
||||
|
||||
local function onNodeEvent(event)
|
||||
if event == "enter" then
|
||||
onEnter()
|
||||
end
|
||||
end
|
||||
|
||||
layer:registerScriptHandler(onNodeEvent)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -992,8 +992,6 @@ function BitmapFontMultiLineAlignment.create()
|
|||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer:setTouchEnabled(true)
|
||||
|
||||
-- ask director the the window size
|
||||
local size = cc.Director:getInstance():getWinSize()
|
||||
|
||||
|
@ -1068,7 +1066,44 @@ function BitmapFontMultiLineAlignment.create()
|
|||
layer:addChild(stringMenu)
|
||||
layer:addChild(alignmentMenu)
|
||||
layer:registerScriptHandler(BitmapFontMultiLineAlignment.onNodeEvent)
|
||||
layer:registerScriptTouchHandler(BitmapFontMultiLineAlignment.onTouchEvent)
|
||||
|
||||
local function onTouchesBegan(touches, event)
|
||||
local location = touches[1]:getLocationInView()
|
||||
if cc.rectContainsPoint(BitmapFontMultiLineAlignment._pArrowsShouldRetain:getBoundingBox(), location) then
|
||||
BitmapFontMultiLineAlignment._drag = true
|
||||
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain:setVisible(true)
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouchesMoved(touches, event)
|
||||
if BitmapFontMultiLine._drag == false then
|
||||
return
|
||||
end
|
||||
local location = touches[1]:getLocationInView()
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
BitmapFontMultiLineAlignment._pArrowsShouldRetain:setPosition(
|
||||
math.max(math.min(location.x, ArrowsMax*winSize.width), ArrowsMin*winSize.width),
|
||||
BitmapFontMultiLineAlignment._pArrowsShouldRetain:getPositionY())
|
||||
|
||||
local labelWidth = math.abs(BitmapFontMultiLineAlignment._pArrowsShouldRetain:getPositionX() - BitmapFontMultiLineAlignment._pLabelShouldRetain:getPositionX()) * 2
|
||||
|
||||
BitmapFontMultiLineAlignment._pLabelShouldRetain:setWidth(labelWidth)
|
||||
end
|
||||
|
||||
local function onTouchesEnded(touch, event)
|
||||
BitmapFontMultiLineAlignment._drag = false
|
||||
BitmapFontMultiLineAlignment.snapArrowsToEdge()
|
||||
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain:setVisible(false)
|
||||
end
|
||||
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
listener:registerScriptHandler(onTouchesEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
|
@ -1118,35 +1153,6 @@ function BitmapFontMultiLineAlignment.alignmentChanged(tag, sender)
|
|||
BitmapFontMultiLineAlignment.snapArrowsToEdge()
|
||||
end
|
||||
|
||||
function BitmapFontMultiLineAlignment.onTouchEvent(eventType, x, y)
|
||||
-- cclog("type:"..eventType.."["..x..","..y.."]")
|
||||
if eventType == "began" then
|
||||
if cc.rectContainsPoint(BitmapFontMultiLineAlignment._pArrowsShouldRetain:getBoundingBox(), cc.p(x, y)) then
|
||||
BitmapFontMultiLineAlignment._drag = true
|
||||
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain:setVisible(true)
|
||||
return true
|
||||
end
|
||||
elseif eventType == "ended" then
|
||||
BitmapFontMultiLineAlignment._drag = false
|
||||
BitmapFontMultiLineAlignment.snapArrowsToEdge()
|
||||
BitmapFontMultiLineAlignment._pArrowsBarShouldRetain:setVisible(false)
|
||||
elseif eventType == "moved" then
|
||||
if BitmapFontMultiLine._drag == false then
|
||||
return
|
||||
end
|
||||
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
BitmapFontMultiLineAlignment._pArrowsShouldRetain:setPosition(
|
||||
math.max(math.min(x, ArrowsMax*winSize.width), ArrowsMin*winSize.width),
|
||||
BitmapFontMultiLineAlignment._pArrowsShouldRetain:getPositionY())
|
||||
|
||||
local labelWidth = math.abs(BitmapFontMultiLineAlignment._pArrowsShouldRetain:getPositionX() - BitmapFontMultiLineAlignment._pLabelShouldRetain:getPositionX()) * 2
|
||||
|
||||
BitmapFontMultiLineAlignment._pLabelShouldRetain:setWidth(labelWidth)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function BitmapFontMultiLineAlignment.snapArrowsToEdge()
|
||||
BitmapFontMultiLineAlignment._pArrowsShouldRetain:setPosition(
|
||||
BitmapFontMultiLineAlignment._pLabelShouldRetain:getPositionX() + BitmapFontMultiLineAlignment._pLabelShouldRetain:getContentSize().width/2, BitmapFontMultiLineAlignment._pLabelShouldRetain:getPositionY()
|
||||
|
|
|
@ -596,9 +596,6 @@ local LabelFNTMultiLineAlignment = {
|
|||
function LabelFNTMultiLineAlignment.create()
|
||||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
|
||||
layer:setTouchEnabled(true)
|
||||
|
||||
-- ask director the the window size
|
||||
local size = cc.Director:getInstance():getWinSize()
|
||||
|
||||
|
@ -674,7 +671,46 @@ function LabelFNTMultiLineAlignment.create()
|
|||
layer:addChild(stringMenu)
|
||||
layer:addChild(alignmentMenu)
|
||||
layer:registerScriptHandler(LabelFNTMultiLineAlignment.onNodeEvent)
|
||||
layer:registerScriptTouchHandler(LabelFNTMultiLineAlignment.onTouchEvent)
|
||||
|
||||
local function onTouchesBegan(touches, event)
|
||||
local location = touches[1]:getLocationInView()
|
||||
if cc.rectContainsPoint(LabelFNTMultiLineAlignment._pArrowsShouldRetain:getBoundingBox(), cc.p(location.x, location.y)) then
|
||||
LabelFNTMultiLineAlignment._drag = true
|
||||
LabelFNTMultiLineAlignment._pArrowsBarShouldRetain:setVisible(true)
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouchesMoved(touches, event)
|
||||
if LabelFNTMultiLineAlignment._drag == false then
|
||||
return
|
||||
end
|
||||
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
local location = touches[1]:getLocationInView()
|
||||
|
||||
LabelFNTMultiLineAlignment._pArrowsShouldRetain:setPosition(
|
||||
math.max(math.min(location.x, ArrowsMax*winSize.width), ArrowsMin*winSize.width),
|
||||
LabelFNTMultiLineAlignment._pArrowsShouldRetain:getPositionY())
|
||||
|
||||
local labelWidth = math.abs(LabelFNTMultiLineAlignment._pArrowsShouldRetain:getPositionX() - LabelFNTMultiLineAlignment._pLabelShouldRetain:getPositionX()) * 2
|
||||
|
||||
LabelFNTMultiLineAlignment._pLabelShouldRetain:setWidth(labelWidth)
|
||||
end
|
||||
|
||||
local function onTouchesEnded(touch, event)
|
||||
LabelFNTMultiLineAlignment._drag = false
|
||||
LabelFNTMultiLineAlignment.snapArrowsToEdge()
|
||||
LabelFNTMultiLineAlignment._pArrowsBarShouldRetain:setVisible(false)
|
||||
end
|
||||
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
listener:registerScriptHandler(onTouchesEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
|
@ -724,35 +760,6 @@ function LabelFNTMultiLineAlignment.alignmentChanged(tag, sender)
|
|||
LabelFNTMultiLineAlignment.snapArrowsToEdge()
|
||||
end
|
||||
|
||||
function LabelFNTMultiLineAlignment.onTouchEvent(eventType, x, y)
|
||||
-- cclog("type:"..eventType.."["..x..","..y.."]")
|
||||
if eventType == "began" then
|
||||
if cc.rectContainsPoint(LabelFNTMultiLineAlignment._pArrowsShouldRetain:getBoundingBox(), cc.p(x, y)) then
|
||||
LabelFNTMultiLineAlignment._drag = true
|
||||
LabelFNTMultiLineAlignment._pArrowsBarShouldRetain:setVisible(true)
|
||||
return true
|
||||
end
|
||||
elseif eventType == "ended" then
|
||||
LabelFNTMultiLineAlignment._drag = false
|
||||
LabelFNTMultiLineAlignment.snapArrowsToEdge()
|
||||
LabelFNTMultiLineAlignment._pArrowsBarShouldRetain:setVisible(false)
|
||||
elseif eventType == "moved" then
|
||||
if LabelFNTMultiLineAlignment._drag == false then
|
||||
return
|
||||
end
|
||||
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
LabelFNTMultiLineAlignment._pArrowsShouldRetain:setPosition(
|
||||
math.max(math.min(x, ArrowsMax*winSize.width), ArrowsMin*winSize.width),
|
||||
LabelFNTMultiLineAlignment._pArrowsShouldRetain:getPositionY())
|
||||
|
||||
local labelWidth = math.abs(LabelFNTMultiLineAlignment._pArrowsShouldRetain:getPositionX() - LabelFNTMultiLineAlignment._pLabelShouldRetain:getPositionX()) * 2
|
||||
|
||||
LabelFNTMultiLineAlignment._pLabelShouldRetain:setWidth(labelWidth)
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function LabelFNTMultiLineAlignment.snapArrowsToEdge()
|
||||
LabelFNTMultiLineAlignment._pArrowsShouldRetain:setPosition(
|
||||
LabelFNTMultiLineAlignment._pLabelShouldRetain:getPositionX() + LabelFNTMultiLineAlignment._pLabelShouldRetain:getContentSize().width/2, LabelFNTMultiLineAlignment._pLabelShouldRetain:getPositionY()
|
||||
|
|
|
@ -302,8 +302,6 @@ end
|
|||
local function LayerTest1()
|
||||
local ret = createLayerDemoLayer("ColorLayer resize (tap & move)")
|
||||
|
||||
ret:setTouchEnabled(true)
|
||||
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local layer = cc.LayerColor:create( cc.c4b(0xFF, 0x00, 0x00, 0x80), 200, 200)
|
||||
|
||||
|
@ -321,15 +319,23 @@ local function LayerTest1()
|
|||
l:setContentSize( newSize )
|
||||
end
|
||||
|
||||
local function onTouchEvent(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
updateSize(x, y)
|
||||
return true
|
||||
else
|
||||
updateSize(x, y)
|
||||
end
|
||||
local function onTouchesMoved(touches, event)
|
||||
local touchLocation = touches[1]:getLocation()
|
||||
|
||||
updateSize(touchLocation.x, touchLocation.y)
|
||||
end
|
||||
ret:registerScriptTouchHandler(onTouchEvent)
|
||||
|
||||
local function onTouchesBegan(touches, event)
|
||||
onTouchesMoved(touches, event)
|
||||
end
|
||||
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
|
||||
local eventDispatcher = ret:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, ret)
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
|
@ -430,8 +436,6 @@ local function LayerGradient()
|
|||
local layer1 = cc.LayerGradient:create(cc.c4b(255,0,0,255), cc.c4b(0,255,0,255), cc.p(0.9, 0.9))
|
||||
ret:addChild(layer1, 0, kTagLayer)
|
||||
|
||||
ret:setTouchEnabled(true)
|
||||
|
||||
local label1 = cc.LabelTTF:create("Compressed Interpolation: Enabled", "Marker Felt", 26)
|
||||
local label2 = cc.LabelTTF:create("Compressed Interpolation: Disabled", "Marker Felt", 26)
|
||||
local item1 = cc.MenuItemLabel:create(label1)
|
||||
|
@ -452,22 +456,23 @@ local function LayerGradient()
|
|||
local s = cc.Director:getInstance():getWinSize()
|
||||
menu:setPosition(cc.p(s.width / 2, 100))
|
||||
|
||||
local function onTouchEvent(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return true
|
||||
elseif eventType == "moved" then
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local start = cc.p(x, y)
|
||||
local movingPos = cc.p(s.width/2,s.height/2)
|
||||
local diff = cc.p(movingPos.x - start.x, movingPos.y - start.y)
|
||||
diff = cc.pNormalize(diff)
|
||||
local function onTouchesMoved(touches, event)
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local start = touches[1]:getLocation()
|
||||
local movingPos = cc.p(s.width/2,s.height/2)
|
||||
local diff = cc.p(movingPos.x - start.x, movingPos.y - start.y)
|
||||
diff = cc.pNormalize(diff)
|
||||
|
||||
local gradient = tolua.cast(ret:getChildByTag(1), "cc.LayerGradient")
|
||||
gradient:setVector(diff)
|
||||
end
|
||||
local gradient = tolua.cast(ret:getChildByTag(1), "cc.LayerGradient")
|
||||
gradient:setVector(diff)
|
||||
end
|
||||
|
||||
ret:registerScriptTouchHandler(onTouchEvent)
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
|
||||
local eventDispatcher = ret:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, ret)
|
||||
|
||||
return ret
|
||||
end
|
||||
|
||||
|
|
|
@ -22,8 +22,6 @@ local function MenuLayerMainMenu()
|
|||
local m_disabledItem = nil
|
||||
|
||||
local ret = cc.Layer:create()
|
||||
ret:setTouchEnabled(true)
|
||||
ret:setTouchMode(cc.TOUCHES_ONE_BY_ONE )
|
||||
|
||||
-- Font Item
|
||||
local spriteNormal = cc.Sprite:create(s_MenuItem, cc.rect(0,23*2,115,23))
|
||||
|
@ -542,32 +540,32 @@ local function RemoveMenuItemWhenMove()
|
|||
|
||||
menu:setPosition(cc.p(s.width/2, s.height/2))
|
||||
|
||||
ret:setTouchEnabled(true)
|
||||
--[[
|
||||
local function onTouchBegan(touch, event)
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchMoved(touch, event)
|
||||
if item ~= nil then
|
||||
item:removeFromParent(true)
|
||||
--item:release()
|
||||
--item = nil
|
||||
end
|
||||
end
|
||||
|
||||
local listener = cc.EventListenerTouchOneByOne:create()
|
||||
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
|
||||
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
|
||||
local eventDispatcher = ret:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithFixedPriority(listener, -129)
|
||||
|
||||
local function onNodeEvent(event)
|
||||
if event == "enter" then
|
||||
cc.Director:getInstance():getTouchDispatcher():addTargetedDelegate(ret, -129, false)
|
||||
elseif event == "exit" then
|
||||
-- item:release()
|
||||
if event == "exit" then
|
||||
ret:getEventDispatcher():removeEventListener(listener)
|
||||
end
|
||||
end
|
||||
|
||||
ret:registerScriptHandler(onNodeEvent)
|
||||
]]--
|
||||
|
||||
local function onTouchEvent(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return true
|
||||
elseif eventType == "moved" then
|
||||
if item ~= nil then
|
||||
item:removeFromParent(true)
|
||||
--item:release()
|
||||
--item = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
ret:registerScriptTouchHandler(onTouchEvent,false,-129,false)
|
||||
return ret
|
||||
end
|
||||
|
||||
|
|
|
@ -106,28 +106,17 @@ local function MotionStreakTest2()
|
|||
|
||||
streak:setPosition(cc.p(s.width / 2, s.height / 2))
|
||||
|
||||
local function onTouchMoved(x, y)
|
||||
if firstTick == true then
|
||||
firstTick = false
|
||||
return
|
||||
end
|
||||
|
||||
streak:setPosition(cc.p(x, y))
|
||||
local function onTouchesMoved(touches, event)
|
||||
streak:setPosition( touches[1]:getLocation() )
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return true
|
||||
elseif eventType == "moved" then
|
||||
return onTouchMoved(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
firstTick = true
|
||||
layer:setTouchEnabled(true)
|
||||
layer:registerScriptTouchHandler(onTouch)
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
Helper.titleLabel:setString("MotionStreak test")
|
||||
|
||||
return layer
|
||||
end
|
||||
|
||||
|
|
|
@ -569,27 +569,25 @@ local function ConvertToNode()
|
|||
ConvertToNode_layer:addChild(sprite, i)
|
||||
end
|
||||
|
||||
local function onTouchEnded(x, y)
|
||||
for i = 0, 2 do
|
||||
local node = ConvertToNode_layer:getChildByTag(100 + i)
|
||||
local p1, p2
|
||||
p1 = node:convertToNodeSpaceAR(cc.p(x, y))
|
||||
p2 = node:convertToNodeSpace(cc.p(x, y))
|
||||
local function onTouchesEnded(touches, event)
|
||||
local count = table.getn(touches)
|
||||
for i = 1, count do
|
||||
local location = touches[i]:getLocation()
|
||||
for j = 1,3 do
|
||||
local node = ConvertToNode_layer:getChildByTag(100 + i - 1)
|
||||
local p1, p2
|
||||
p1 = node:convertToNodeSpaceAR(location)
|
||||
p2 = node:convertToNodeSpace(location)
|
||||
|
||||
cclog("AR: x=" .. p1.x .. ", y=" .. p1.y .. " -- Not AR: x=" .. p2.x .. ", y=" .. p2.y)
|
||||
cclog("AR: x=" .. p1.x .. ", y=" .. p1.y .. " -- Not AR: x=" .. p2.x .. ", y=" .. p2.y)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return true
|
||||
elseif eventType == "ended" then
|
||||
return onTouchEnded(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
ConvertToNode_layer:setTouchEnabled(true)
|
||||
ConvertToNode_layer:registerScriptTouchHandler(onTouch)
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
local eventDispatcher = ConvertToNode_layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, ConvertToNode_layer)
|
||||
|
||||
Helper.titleLabel:setString("Convert To Node Space")
|
||||
Helper.subtitleLabel:setString("testing convertToNodeSpace / AR. Touch and see console")
|
||||
|
|
|
@ -83,7 +83,6 @@ end
|
|||
|
||||
local function Parallax2()
|
||||
local ret = createParallaxLayer("Parallax: drag screen")
|
||||
ret:setTouchEnabled( true )
|
||||
|
||||
-- Top Layer, a simple image
|
||||
local cocosImage = cc.Sprite:create(s_Power)
|
||||
|
@ -126,25 +125,19 @@ local function Parallax2()
|
|||
-- top image is moved at a ratio of 3.0x, 2.5y
|
||||
voidNode:addChild( cocosImage, 2, cc.p(3.0,2.5), cc.p(200,1000) )
|
||||
ret:addChild(voidNode, 0, kTagNode)
|
||||
local prev = {x = 0, y = 0}
|
||||
local function onTouchEvent(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
prev.x = x
|
||||
prev.y = y
|
||||
return true
|
||||
elseif eventType == "moved" then
|
||||
local node = ret:getChildByTag(kTagNode)
|
||||
local newX = node:getPositionX()
|
||||
local newY = node:getPositionY()
|
||||
local diffX = x - prev.x
|
||||
local diffY = y - prev.y
|
||||
|
||||
node:setPosition( cc.pAdd(cc.p(newX, newY), cc.p(diffX, diffY)) )
|
||||
prev.x = x
|
||||
prev.y = y
|
||||
end
|
||||
local function onTouchesMoved(touches, event)
|
||||
local diff = touches[1]:getDelta()
|
||||
|
||||
local node = ret:getChildByTag(kTagNode)
|
||||
local currentPosX, currentPosY = node:getPosition()
|
||||
node:setPosition(cc.p(currentPosX + diff.x, currentPosY + diff.y))
|
||||
end
|
||||
ret:registerScriptTouchHandler(onTouchEvent)
|
||||
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
local eventDispatcher = ret:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, ret)
|
||||
|
||||
return ret
|
||||
end
|
||||
|
|
|
@ -147,28 +147,34 @@ local function getBaseLayer()
|
|||
local seq = cc.Sequence:create(move, move_back)
|
||||
background:runAction(cc.RepeatForever:create(seq))
|
||||
|
||||
local function onTouchEnded(x, y)
|
||||
local pos = cc.p(0, 0)
|
||||
if background ~= nil then
|
||||
pos = background:convertToWorldSpace(cc.p(0, 0))
|
||||
end
|
||||
local function onTouchesEnded(touches, event)
|
||||
local location = touches[1]:getLocation()
|
||||
local pos = cc.p(0, 0)
|
||||
if background ~= nil then
|
||||
pos = background:convertToWorldSpace(cc.p(0, 0))
|
||||
end
|
||||
|
||||
if emitter ~= nil then
|
||||
local newPos = cc.pSub(cc.p(x, y), pos)
|
||||
emitter:setPosition(newPos.x, newPos.y)
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return true
|
||||
else
|
||||
return onTouchEnded(x, y)
|
||||
if emitter ~= nil then
|
||||
local newPos = cc.pSub(location, pos)
|
||||
emitter:setPosition(newPos.x, newPos.y)
|
||||
end
|
||||
end
|
||||
|
||||
layer:setTouchEnabled(true)
|
||||
layer:registerScriptTouchHandler(onTouch)
|
||||
local function onTouchesBegan(touches, event)
|
||||
onTouchesEnded(touches, event);
|
||||
end
|
||||
|
||||
local function onTouchesMoved(touches, event)
|
||||
onTouchesEnded(touches, event);
|
||||
end
|
||||
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
listener:registerScriptHandler(onTouchesEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
layer:registerScriptHandler(baseLayer_onEnterOrExit)
|
||||
|
||||
return layer
|
||||
|
|
|
@ -1548,48 +1548,37 @@ local function runTouchesTest()
|
|||
end
|
||||
|
||||
-- handling touch events
|
||||
local function onTouchBegan(tableArray)
|
||||
if 0 == nCurCase then
|
||||
nNumberOfTouchesB = nNumberOfTouchesB + 1
|
||||
elseif 1 == nCurCase then
|
||||
nNumberOfTouchesB = nNumberOfTouchesB + table.getn(tableArray)
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouchMoved(tableArray)
|
||||
if 0 == nCurCase then
|
||||
nNumberOfTouchesM = nNumberOfTouchesM + 1
|
||||
elseif 1 == nCurCase then
|
||||
nNumberOfTouchesM = nNumberOfTouchesM + table.getn(tableArray)
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouchEnded(tableArray)
|
||||
if 0 == nCurCase then
|
||||
nNumberOfTouchesE = nNumberOfTouchesE + 1
|
||||
elseif 1 == nCurCase then
|
||||
nNumberOfTouchesE = nNumberOfTouchesE + table.getn(tableArray)
|
||||
end
|
||||
end
|
||||
|
||||
local function onTouchCancelled(tableArray)
|
||||
if 0 == nCurCase then
|
||||
nNumberOfTouchesC = nNumberOfTouchesC + 1
|
||||
elseif 1 == nCurCase then
|
||||
nNumberOfTouchesC = nNumberOfTouchesC + table.getn(tableArray)
|
||||
end
|
||||
local function onTouchEnded(touch, event)
|
||||
nNumberOfTouchesE = nNumberOfTouchesE + 1
|
||||
end
|
||||
|
||||
local function onTouch(eventType,tableArray)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(tableArray)
|
||||
elseif eventType == "moved" then
|
||||
return onTouchMoved(tableArray)
|
||||
elseif eventType == "ended" then
|
||||
return onTouchEnded(tableArray)
|
||||
elseif eventType == "cancelled" then
|
||||
return onTouchCancelled(tableArray)
|
||||
end
|
||||
local function onTouchBegan(touch, event)
|
||||
nNumberOfTouchesB = nNumberOfTouchesB + 1
|
||||
end
|
||||
|
||||
local function onTouchMoved(touch, event)
|
||||
nNumberOfTouchesM = nNumberOfTouchesM + 1
|
||||
end
|
||||
|
||||
local function onTouchCancelled(touch, event)
|
||||
nNumberOfTouchesC = nNumberOfTouchesC + 1
|
||||
end
|
||||
|
||||
|
||||
local function onTouchesEnded(touches, event)
|
||||
nNumberOfTouchesE = nNumberOfTouchesE + table.getn(touches)
|
||||
end
|
||||
|
||||
local function onTouchesBegan(touches, event)
|
||||
nNumberOfTouchesB = nNumberOfTouchesB + table.getn(touches)
|
||||
end
|
||||
|
||||
local function onTouchesMoved(touches, event)
|
||||
nNumberOfTouchesM = nNumberOfTouchesM + table.getn(touches)
|
||||
end
|
||||
|
||||
local function onTouchesCancelled(touches, event)
|
||||
nNumberOfTouchesC= nNumberOfTouchesC + table.getn(touches)
|
||||
end
|
||||
|
||||
local function InitLayer()
|
||||
|
@ -1617,9 +1606,24 @@ local function runTouchesTest()
|
|||
nNumberOfTouchesM = 0
|
||||
nNumberOfTouchesE = 0
|
||||
nNumberOfTouchesC = 0
|
||||
pLayer:setTouchEnabled(true)
|
||||
|
||||
pLayer:registerScriptTouchHandler(onTouch,true)
|
||||
|
||||
if 0 == nCurCase then
|
||||
local listener = cc.EventListenerTouchOneByOne:create()
|
||||
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
|
||||
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
|
||||
listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
|
||||
listener:registerScriptHandler(onTouchCancelled,cc.Handler.EVENT_TOUCH_CANCELLED )
|
||||
local eventDispatcher = pLayer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, pLayer)
|
||||
elseif 1 == nCurCase then
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesBegan,cc.Handler.EVENT_TOUCHES_BEGAN )
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
listener:registerScriptHandler(onTouchesEnded,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
listener:registerScriptHandler(onTouchesCancelled,cc.Handler.EVENT_TOUCHES_CANCELLED )
|
||||
local eventDispatcher = pLayer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, pLayer)
|
||||
end
|
||||
end
|
||||
|
||||
function ShowCurrentTest()
|
||||
|
|
|
@ -8,22 +8,21 @@ local function RenderTextureSave()
|
|||
local ret = createTestLayer("Touch the screen",
|
||||
"Press 'Save Image' to create an snapshot of the render texture")
|
||||
local s = cc.Director:getInstance():getWinSize()
|
||||
local m_pTarget = nil
|
||||
local m_pBrush = nil
|
||||
local m_pTarget = nil
|
||||
local target = nil
|
||||
local counter = 0
|
||||
local brushes = {}
|
||||
local function clearImage(tag, pSender)
|
||||
m_pTarget:clear(math.random(), math.random(), math.random(), math.random())
|
||||
target:clear(math.random(), math.random(), math.random(), math.random())
|
||||
end
|
||||
|
||||
local function saveImage(tag, pSender)
|
||||
local png = string.format("image-%d.png", counter)
|
||||
local jpg = string.format("image-%d.jpg", counter)
|
||||
|
||||
m_pTarget:saveToFile(png, cc.IMAGE_FORMAT_PNG)
|
||||
m_pTarget:saveToFile(jpg, cc.IMAGE_FORMAT_JPEG)
|
||||
target:saveToFile(png, cc.IMAGE_FORMAT_PNG)
|
||||
target:saveToFile(jpg, cc.IMAGE_FORMAT_JPEG)
|
||||
|
||||
local pImage = m_pTarget:newImage()
|
||||
local pImage = target:newImage()
|
||||
|
||||
local tex = cc.Director:getInstance():getTextureCache():addUIImage(pImage, png)
|
||||
|
||||
|
@ -42,8 +41,7 @@ local function RenderTextureSave()
|
|||
|
||||
local function onNodeEvent(event)
|
||||
if event == "exit" then
|
||||
m_pBrush:release()
|
||||
m_pTarget:release()
|
||||
target:release()
|
||||
cc.Director:getInstance():getTextureCache():removeUnusedTextures()
|
||||
end
|
||||
end
|
||||
|
@ -51,69 +49,58 @@ local function RenderTextureSave()
|
|||
ret:registerScriptHandler(onNodeEvent)
|
||||
|
||||
-- create a render texture, this is what we are going to draw into
|
||||
m_pTarget = cc.RenderTexture:create(s.width, s.height, cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
||||
m_pTarget:retain()
|
||||
m_pTarget:setPosition(cc.p(s.width / 2, s.height / 2))
|
||||
target = cc.RenderTexture:create(s.width, s.height, cc.TEXTURE2_D_PIXEL_FORMAT_RGB_A8888)
|
||||
target:retain()
|
||||
target:setPosition(cc.p(s.width / 2, s.height / 2))
|
||||
|
||||
-- note that the render texture is a cc.Node, and contains a sprite of its texture for convience,
|
||||
-- so we can just parent it to the scene like any other cc.Node
|
||||
ret:addChild(m_pTarget, -1)
|
||||
ret:addChild(target, -1)
|
||||
|
||||
-- create a brush image to draw into the texture with
|
||||
m_pBrush = cc.Sprite:create("Images/fire.png")
|
||||
m_pBrush:retain()
|
||||
m_pBrush:setColor(cc.c3b(255, 0, 0))
|
||||
m_pBrush:setOpacity(20)
|
||||
local function onTouchesMoved(touches, event)
|
||||
local start = touches[1]:getLocation()
|
||||
local ended = touches[1]:getPreviousLocation()
|
||||
|
||||
target:begin()
|
||||
|
||||
local prev = {x = 0, y = 0}
|
||||
local function onTouchEvent(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
prev.x = x
|
||||
prev.y = y
|
||||
return true
|
||||
elseif eventType == "moved" then
|
||||
local diffX = x - prev.x
|
||||
local diffY = y - prev.y
|
||||
local distance = cc.pGetDistance(start, ended)
|
||||
if distance > 1 then
|
||||
brushes = {}
|
||||
local d = distance
|
||||
local i = 0
|
||||
|
||||
local startP = cc.p(x, y)
|
||||
local endP = cc.p(prev.x, prev.y)
|
||||
|
||||
-- begin drawing to the render texture
|
||||
m_pTarget:begin()
|
||||
|
||||
-- for extra points, we'll draw this smoothly from the last position and vary the sprite's
|
||||
-- scale/rotation/offset
|
||||
local distance = cc.pGetDistance(startP, endP)
|
||||
if distance > 1 then
|
||||
local d = distance
|
||||
local i = 0
|
||||
for i = 0, d-1 do
|
||||
local difx = endP.x - startP.x
|
||||
local dify = endP.y - startP.y
|
||||
local delta = i / distance
|
||||
m_pBrush:setPosition(cc.p(startP.x + (difx * delta), startP.y + (dify * delta)))
|
||||
m_pBrush:setRotation(math.random(0, 359))
|
||||
local r = math.random(0, 49) / 50.0 + 0.25
|
||||
m_pBrush:setScale(r)
|
||||
|
||||
-- Use cc.RANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
|
||||
m_pBrush:setColor(cc.c3b(math.random(0, 126) + 128, 255, 255))
|
||||
-- Call visit to draw the brush, don't call draw..
|
||||
m_pBrush:visit()
|
||||
end
|
||||
for i = 0,d -1 do
|
||||
-- create a brush image to draw into the texture with
|
||||
local sprite = cc.Sprite:create("Images/fire.png")
|
||||
sprite:setColor(cc.c3b(255, 0, 0))
|
||||
sprite:setOpacity(20)
|
||||
brushes[i + 1] = sprite
|
||||
end
|
||||
|
||||
-- finish drawing and return context back to the screen
|
||||
m_pTarget:endToLua()
|
||||
for i = 0,d -1 do
|
||||
local difx = ended.x - start.x
|
||||
local dify = ended.y - start.y
|
||||
local delta = i / distance
|
||||
brushes[i + 1]:setPosition(cc.p(start.x + (difx * delta), start.y + (dify * delta)))
|
||||
brushes[i + 1]:setRotation(math.random(0, 359))
|
||||
local r = math.random(0, 49) / 50.0 + 0.25
|
||||
brushes[i + 1]:setScale(r)
|
||||
|
||||
-- Use cc.RANDOM_0_1() will cause error when loading libtests.so on android, I don't know why.
|
||||
brushes[i + 1]:setColor(cc.c3b(math.random(0, 126) + 128, 255, 255))
|
||||
-- Call visit to draw the brush, don't call draw..
|
||||
brushes[i + 1]:visit()
|
||||
end
|
||||
end
|
||||
|
||||
prev.x = x
|
||||
prev.y = y
|
||||
-- finish drawing and return context back to the screen
|
||||
target:endToLua()
|
||||
end
|
||||
|
||||
ret:setTouchEnabled(true)
|
||||
ret:registerScriptTouchHandler(onTouchEvent)
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
local eventDispatcher = ret:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, ret)
|
||||
-- Save Image menu
|
||||
cc.MenuItemFont:setFontSize(16)
|
||||
local item1 = cc.MenuItemFont:create("Save Image")
|
||||
|
|
|
@ -55,12 +55,10 @@ function Sprite1.addNewSpriteWithCoords(layer, point)
|
|||
sprite:runAction( cc.RepeatForever:create(seq) )
|
||||
end
|
||||
|
||||
function Sprite1.onTouch(event, x, y)
|
||||
if event == "began" then
|
||||
return true
|
||||
elseif event == "ended" then
|
||||
Sprite1.addNewSpriteWithCoords(Helper.currentLayer, cc.p(x,y))
|
||||
return true
|
||||
function Sprite1.onTouchesEnd(touches, event)
|
||||
for i = 1,table.getn(touches) do
|
||||
local location = touches[i]:getLocation()
|
||||
Sprite1.addNewSpriteWithCoords(Helper.currentLayer, location)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -69,8 +67,11 @@ function Sprite1.create()
|
|||
local layer = cc.Layer:create()
|
||||
Helper.initWithLayer(layer)
|
||||
Sprite1.addNewSpriteWithCoords(layer, cc.p(size.width/2, size.height/2))
|
||||
layer:setTouchEnabled(true)
|
||||
layer:registerScriptTouchHandler(Sprite1.onTouch)
|
||||
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(Sprite1.onTouchesEnd,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
Helper.titleLabel:setString("Sprite (tap screen)")
|
||||
|
||||
|
@ -115,12 +116,10 @@ function SpriteBatchNode1.addNewSpriteWithCoords(layer, point)
|
|||
sprite:runAction( cc.RepeatForever:create(seq) )
|
||||
end
|
||||
|
||||
function SpriteBatchNode1.onTouch(event, x, y)
|
||||
if event == "began" then
|
||||
return true
|
||||
elseif event == "ended" then
|
||||
SpriteBatchNode1.addNewSpriteWithCoords(Helper.currentLayer, cc.p(x,y))
|
||||
return true
|
||||
function SpriteBatchNode1.onTouchesEnd(touches,event)
|
||||
for i = 1,table.getn(touches) do
|
||||
local location = touches[i]:getLocation()
|
||||
SpriteBatchNode1.addNewSpriteWithCoords(Helper.currentLayer, location)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -132,8 +131,10 @@ function SpriteBatchNode1.create()
|
|||
|
||||
SpriteBatchNode1.addNewSpriteWithCoords(layer, cc.p(size.width/2, size.height/2))
|
||||
|
||||
layer:setTouchEnabled(true)
|
||||
layer:registerScriptTouchHandler(SpriteBatchNode1.onTouch)
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(Sprite1.onTouchesEnd,cc.Handler.EVENT_TOUCHES_ENDED )
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
Helper.titleLabel:setString("SpriteBatchNode (tap screen)")
|
||||
|
||||
|
|
|
@ -12,26 +12,18 @@ local function createTileDemoLayer(title, subtitle)
|
|||
Helper.titleLabel:setString(titleStr)
|
||||
Helper.subtitleLabel:setString(subTitleStr)
|
||||
|
||||
local prev = {x = 0, y = 0}
|
||||
local function onTouchEvent(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
prev.x = x
|
||||
prev.y = y
|
||||
return true
|
||||
elseif eventType == "moved" then
|
||||
local node = layer:getChildByTag(kTagTileMap)
|
||||
local newX = node:getPositionX()
|
||||
local newY = node:getPositionY()
|
||||
local diffX = x - prev.x
|
||||
local diffY = y - prev.y
|
||||
|
||||
node:setPosition( cc.pAdd(cc.p(newX, newY), cc.p(diffX, diffY)) )
|
||||
prev.x = x
|
||||
prev.y = y
|
||||
end
|
||||
local function onTouchesMoved(touches, event )
|
||||
local diff = touches[1]:getDelta()
|
||||
local node = layer:getChildByTag(kTagTileMap)
|
||||
local currentPosX, currentPosY= node:getPosition()
|
||||
node:setPosition(cc.p(currentPosX + diff.x, currentPosY + diff.y))
|
||||
end
|
||||
layer:setTouchEnabled(true)
|
||||
layer:registerScriptTouchHandler(onTouchEvent)
|
||||
|
||||
local listener = cc.EventListenerTouchAllAtOnce:create()
|
||||
listener:registerScriptHandler(onTouchesMoved,cc.Handler.EVENT_TOUCHES_MOVED )
|
||||
local eventDispatcher = layer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer)
|
||||
|
||||
return layer
|
||||
end
|
||||
--------------------------------------------------------------------
|
||||
|
|
|
@ -170,14 +170,15 @@ function CreateTestMenu()
|
|||
menuLayer:addChild(MainMenu)
|
||||
|
||||
-- handling touch events
|
||||
local function onTouchBegan(x, y)
|
||||
BeginPos = {x = x, y = y}
|
||||
local function onTouchBegan(touch, event)
|
||||
BeginPos = touch:getLocation()
|
||||
-- CCTOUCHBEGAN event must return true
|
||||
return true
|
||||
end
|
||||
|
||||
local function onTouchMoved(x, y)
|
||||
local nMoveY = y - BeginPos.y
|
||||
local function onTouchMoved(touch, event)
|
||||
local location = touch:getLocation()
|
||||
local nMoveY = location.y - BeginPos.y
|
||||
local curPosx, curPosy = MainMenu:getPosition()
|
||||
local nextPosy = curPosy + nMoveY
|
||||
local winSize = cc.Director:getInstance():getWinSize()
|
||||
|
@ -192,20 +193,15 @@ function CreateTestMenu()
|
|||
end
|
||||
|
||||
MainMenu:setPosition(curPosx, nextPosy)
|
||||
BeginPos = {x = x, y = y}
|
||||
BeginPos = {x = location.x, y = location.y}
|
||||
CurPos = {x = curPosx, y = nextPosy}
|
||||
end
|
||||
|
||||
local function onTouch(eventType, x, y)
|
||||
if eventType == "began" then
|
||||
return onTouchBegan(x, y)
|
||||
elseif eventType == "moved" then
|
||||
return onTouchMoved(x, y)
|
||||
end
|
||||
end
|
||||
|
||||
menuLayer:setTouchEnabled(true)
|
||||
menuLayer:registerScriptTouchHandler(onTouch)
|
||||
local listener = cc.EventListenerTouchOneByOne:create()
|
||||
listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
|
||||
listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
|
||||
local eventDispatcher = menuLayer:getEventDispatcher()
|
||||
eventDispatcher:addEventListenerWithSceneGraphPriority(listener, menuLayer)
|
||||
|
||||
return menuLayer
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue