mirror of https://github.com/axmolengine/axmol.git
Merge pull request #3691 from samuele3hu/developTest
Repair some lua test samples and modify handle_key_input function
This commit is contained in:
commit
1d5980db22
|
@ -394,31 +394,31 @@ static int32_t handle_touch_input(AInputEvent *event) {
|
|||
*/
|
||||
static int32_t handle_key_input(AInputEvent *event)
|
||||
{
|
||||
if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_UP)
|
||||
{
|
||||
switch (AKeyEvent_getKeyCode(event))
|
||||
{
|
||||
case AKEYCODE_BACK:
|
||||
{
|
||||
cocos2d::KeyboardEvent event;
|
||||
event._keyCode = cocos2d::KeyboardEvent::KeyCode::KEY_BACKSPACE;
|
||||
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&event);
|
||||
LOGI("AKEYCODE_BACK");
|
||||
}
|
||||
return 1;
|
||||
case AKEYCODE_MENU:
|
||||
{
|
||||
cocos2d::KeyboardEvent event;
|
||||
event._keyCode = cocos2d::KeyboardEvent::KeyCode::KEY_MENU;
|
||||
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&event);
|
||||
LOGI("AKEYCODE_MENU");
|
||||
}
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
if (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_UP)
|
||||
{
|
||||
switch (AKeyEvent_getKeyCode(event))
|
||||
{
|
||||
case AKEYCODE_BACK:
|
||||
{
|
||||
cocos2d::KeyboardEvent event;
|
||||
event._keyCode = cocos2d::KeyboardEvent::KeyCode::KEY_BACKSPACE;
|
||||
event._isPressed = false;
|
||||
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&event);
|
||||
}
|
||||
return 1;
|
||||
case AKEYCODE_MENU:
|
||||
{
|
||||
cocos2d::KeyboardEvent event;
|
||||
event._keyCode = cocos2d::KeyboardEvent::KeyCode::KEY_MENU;
|
||||
event._isPressed = false;
|
||||
cocos2d::EventDispatcher::getInstance()->dispatchEvent(&event);
|
||||
}
|
||||
return 1;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,62 +1,57 @@
|
|||
local function AccelerometerMainLayer()
|
||||
|
||||
local function title()
|
||||
return "AccelerometerTest"
|
||||
end
|
||||
local pLayer = cc.Layer:create()
|
||||
|
||||
pLayer:setAccelerometerEnabled(true)
|
||||
|
||||
local pLabel = cc.LabelTTF:create(title(), "Arial", 32)
|
||||
pLayer:addChild(pLabel, 1)
|
||||
pLabel:setPosition( cc.p(VisibleRect:center().x, VisibleRect:top().y - 50) )
|
||||
local function title()
|
||||
return "AccelerometerTest"
|
||||
end
|
||||
local layer = cc.Layer:create()
|
||||
|
||||
local pBall = cc.Sprite:create("Images/ball.png")
|
||||
pBall:setPosition(cc.p(VisibleRect:center().x, VisibleRect:center().y))
|
||||
pLayer:addChild(pBall)
|
||||
layer:setAccelerometerEnabled(true)
|
||||
|
||||
pBall:retain()
|
||||
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)
|
||||
|
||||
ball:retain()
|
||||
|
||||
local function didAccelerate(x,y,z,timestamp)
|
||||
local pDir = cc.Director:getInstance()
|
||||
|
||||
if nil == pBall then
|
||||
return
|
||||
end
|
||||
if nil == ball then
|
||||
return
|
||||
end
|
||||
|
||||
local szBall = pBall:getContentSize()
|
||||
local ptNowX,ptNowY = pBall:getPosition()
|
||||
|
||||
local ptTmp = pDir:convertToUI(cc.p(ptNowX,ptNowY))
|
||||
ptTmp.x = ptTmp.x + x * 9.81
|
||||
ptTmp.y = ptTmp.y - y * 9.81
|
||||
local szBall = ball:getContentSize()
|
||||
local ptNowX,ptNowY = ball:getPosition()
|
||||
|
||||
ptNowX = ptNowX - x
|
||||
ptNowY = ptNowY - y
|
||||
|
||||
|
||||
local ptNext = pDir:convertToGL(cc.p(ptTmp.x,ptTmp.y))
|
||||
local nMinX = math.floor(VisibleRect:left().x + szBall.width / 2.0)
|
||||
local nMaxX = math.floor(VisibleRect:right().x - szBall.width / 2.0)
|
||||
if ptNext.x < nMinX then
|
||||
ptNext.x = nMinX
|
||||
elseif ptNext.x > nMaxX then
|
||||
ptNext.x = nMaxX
|
||||
end
|
||||
|
||||
local nMinY = math.floor(VisibleRect:bottom().y + szBall.height / 2.0)
|
||||
local nMaxY = math.floor(VisibleRect:top().y - szBall.height / 2.0)
|
||||
if ptNext.y < nMinY then
|
||||
ptNext.y = nMinY
|
||||
elseif ptNext.y > nMaxY then
|
||||
ptNext.y = nMaxY
|
||||
end
|
||||
|
||||
pBall:setPosition(cc.p(ptNext.x,ptNext.y))
|
||||
|
||||
|
||||
local minX = math.floor(VisibleRect:left().x + szBall.width / 2.0)
|
||||
local maxX = math.floor(VisibleRect:right().x - szBall.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 ptNowY < minY then
|
||||
ptNowY = minY
|
||||
elseif ptNowY > maxY then
|
||||
ptNowY = maxY
|
||||
end
|
||||
|
||||
ball:setPosition(cc.p(ptNowX, ptNowY ))
|
||||
end
|
||||
|
||||
pLayer:registerScriptAccelerateHandler(didAccelerate)
|
||||
layer:registerScriptAccelerateHandler(didAccelerate)
|
||||
|
||||
return pLayer
|
||||
return layer
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -117,6 +117,11 @@ function CCMenuDeprecated.createWithItem(self,...)
|
|||
return self:create(...)
|
||||
end
|
||||
rawset(CCMenu,"createWithItem",CCMenuDeprecated.createWithItem)
|
||||
|
||||
function CCMenuDeprecated.setHandlerPriority(self)
|
||||
print("\n********** \n".."setHandlerPriority was deprecated in 3.0. \n**********")
|
||||
end
|
||||
rawset(CCMenu,"setHandlerPriority",CCMenuDeprecated.setHandlerPriority)
|
||||
--functions of CCMenu will be deprecated end
|
||||
|
||||
--functions of CCNode will be deprecated begin
|
||||
|
@ -1015,3 +1020,17 @@ function CCSpriteDeprecated.setFlipY(self,flag)
|
|||
end
|
||||
rawset(cc.Sprite, "setFlipY", CCSpriteDeprecated.setFlipY)
|
||||
--functions of Sprite will be deprecated end
|
||||
|
||||
|
||||
--functions of Layer will be deprecated begin
|
||||
local CCLayerDeprecated = {}
|
||||
function CCLayerDeprecated.setKeypadEnabled( self, enabled)
|
||||
return self:setKeyboardEnabled(enabled)
|
||||
end
|
||||
rawset(cc.Layer, "setKeypadEnabled", CCLayerDeprecated.setKeypadEnabled )
|
||||
|
||||
function CCLayerDeprecated.isKeypadEnabled(self)
|
||||
return self:isKeyboardEnabled()
|
||||
end
|
||||
rawset(cc.Layer, "isKeypadEnabled", CCLayerDeprecated.isKeypadEnabled )
|
||||
--functions of Layer will be deprecated end
|
||||
|
|
Loading…
Reference in New Issue