forked from cocos2d/cocos2d-x
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed cocos2d#538, xcode template for cocos2d-x lua project
- Loading branch information
Walzer
committed
Jun 24, 2011
1 parent
edff316
commit 5f2121e
Showing
31 changed files
with
824 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,146 @@ | ||
g_Scene = cocos2d.CCScene:node() | ||
pSprite = cocos2d.CCSprite:spriteWithFile("90001.jpg") | ||
pSprite:setPosition(cocos2d.CCPoint(300, 400)) | ||
-- create scene & layer | ||
layerFarm = cocos2d.CCLayer:node() | ||
layerFarm:setIsTouchEnabled(true) | ||
|
||
pLayer = cocos2d.CCLayer:node() | ||
pLayer:setIsTouchEnabled(true) | ||
pLayer:setAnchorPoint(cocos2d.CCPoint(0,0)) | ||
pLayer:setPosition( cocos2d.CCPoint(0, -300) ) | ||
pLayer:addChild(pSprite) | ||
g_Scene:addChild(pLayer) | ||
layerMenu = cocos2d.CCLayer:node() | ||
|
||
sceneGame = cocos2d.CCScene:node() | ||
sceneGame:addChild(layerFarm) | ||
sceneGame:addChild(layerMenu) | ||
|
||
winSize = cocos2d.CCDirector:sharedDirector():getWinSize() | ||
|
||
-- add in farm background | ||
spriteFarm = cocos2d.CCSprite:spriteWithFile("farm.jpg") | ||
spriteFarm:setPosition(cocos2d.CCPoint(winSize.width/2 + 80, winSize.height/2)) | ||
layerFarm:addChild(spriteFarm) | ||
|
||
-- touch handers | ||
pointBegin = nil | ||
|
||
function btnTouchMove(e) | ||
cocos2d.CCLuaLog("mousemove") | ||
cocos2d.CCLuaLog("btnTouchMove") | ||
if pointBegin ~= nil then | ||
local v = e[1] | ||
local pointMove = v:locationInView(v:view()) | ||
pointMove = cocos2d.CCDirector:sharedDirector():convertToGL(pointMove) | ||
local positionCurrent = layerFarm.__CCNode__:getPosition() | ||
layerFarm.__CCNode__:setPosition(cocos2d.CCPoint(positionCurrent.x + pointMove.x - pointBegin.x, positionCurrent.y + pointMove.y - pointBegin.y)) | ||
pointBegin = pointMove | ||
end | ||
end | ||
|
||
function btnTouchBegin(e) | ||
cocos2d.CCLuaLog("btnTouchBegin") | ||
for k,v in ipairs(e) do | ||
pointBegin = v:locationInView(v:view()) | ||
pointBegin = cocos2d.CCDirector:sharedDirector():convertToGL(pointBegin) | ||
cocos2d.CCLuaLog("btnTouchBegin, x= %d, y = %d", pointBegin.x, pointBegin.y) | ||
end | ||
end | ||
|
||
function btnTouchEnd(e) | ||
cocos2d.CCLuaLog("btnTouchEnd") | ||
touchStart = nil | ||
end | ||
|
||
-- regiester touch handler | ||
pLayer.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHBEGAN, "btnTouchBegin") | ||
pLayer.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHMOVED, "btnTouchMove") | ||
pLayer.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHENDED, "btnTouchEnd") | ||
|
||
-- add a menu | ||
menuItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png") | ||
menuItem:setAnchorPoint(cocos2d.CCPoint(0,0)) | ||
menuItem:setPosition( cocos2d.CCPoint(100, 200) ) | ||
menuItem:registerScriptHandler("CloseMenu") | ||
pMenu = cocos2d.CCMenu:menuWithItem(menuItem) | ||
pMenu:setPosition( cocos2d.CCPoint(1000, 200) ) | ||
g_Scene:addChild(pMenu) | ||
|
||
function CloseMenu() | ||
pMenu:setPosition(cocos2d.CCPoint(1000, 200) ) | ||
end | ||
|
||
function PopMenu() | ||
pMenu:setPosition( cocos2d.CCPoint(0, -100) ) | ||
end | ||
-- regiester touch handlers | ||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHBEGAN, "btnTouchBegin") | ||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHMOVED, "btnTouchMove") | ||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHENDED, "btnTouchEnd") | ||
|
||
pCloseItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu1.png","menu1.png") | ||
pCloseItem:setPosition( cocos2d.CCPoint(30, 40) ) | ||
pCloseItem:registerScriptHandler("PopMenu") | ||
pcloseMenu = cocos2d.CCMenu:menuWithItem(pCloseItem) | ||
pcloseMenu:setPosition( cocos2d.CCPoint(30, 40) ) | ||
g_Scene:addChild(pcloseMenu) | ||
|
||
-- add land sprite | ||
for i=0,3,1 do | ||
for j=0,1,1 do | ||
|
||
landSprite = cocos2d.CCSprite:spriteWithFile("land1.png") | ||
pLayer:addChild(landSprite) | ||
|
||
landSprite:setAnchorPoint(cocos2d.CCPoint(0,0)) | ||
landSprite:setPosition(cocos2d.CCPoint(90+j*180 - i%2*90, 200+i*95/2)) | ||
|
||
spriteLand = cocos2d.CCSprite:spriteWithFile("land.png") | ||
layerFarm:addChild(spriteLand) | ||
spriteLand:setPosition(cocos2d.CCPoint(200+j*180 - i%2*90, 10+i*95/2)) | ||
end | ||
end | ||
|
||
|
||
|
||
--crop | ||
-- add crop | ||
|
||
for i=0,3,1 do | ||
for j=0,1,1 do | ||
|
||
texturecrop = cocos2d.CCTextureCache:sharedTextureCache():addImage("crop1.png") | ||
framecrop = cocos2d.CCSpriteFrame:frameWithTexture(texturecrop, cocos2d.CCRectMake(0, 0, 105, 95)) | ||
spritecrop = cocos2d.CCSprite:spriteWithSpriteFrame(framecrop); | ||
textureCrop = cocos2d.CCTextureCache:sharedTextureCache():addImage("crop.png") | ||
frameCrop = cocos2d.CCSpriteFrame:frameWithTexture(textureCrop, cocos2d.CCRectMake(0, 0, 105, 95)) | ||
spriteCrop = cocos2d.CCSprite:spriteWithSpriteFrame(frameCrop); | ||
|
||
pLayer:addChild(spritecrop) | ||
layerFarm:addChild(spriteCrop) | ||
|
||
spritecrop:setAnchorPoint(cocos2d.CCPoint(0,0)) | ||
spritecrop:setPosition(cocos2d.CCPoint(45+90+j*180 - i%2*90, 25+200+i*95/2)) | ||
spriteCrop:setPosition(cocos2d.CCPoint(10+200+j*180 - i%2*90, 30+10+i*95/2)) | ||
|
||
end | ||
end | ||
|
||
-- add the moving dog | ||
|
||
FrameWidth = 105 | ||
FrameHeight = 95 | ||
|
||
textureDog = cocos2d.CCTextureCache:sharedTextureCache():addImage("dog.png") | ||
frame0 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(0, 0, FrameWidth, FrameHeight)) | ||
frame1 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(FrameWidth*1, 0, FrameWidth, FrameHeight)) | ||
|
||
nFrameWidth = 105 | ||
nFrameHeight = 95 | ||
|
||
texture = cocos2d.CCTextureCache:sharedTextureCache():addImage("dog1.png") | ||
frame0 = cocos2d.CCSpriteFrame:frameWithTexture(texture, cocos2d.CCRectMake(0, 0, nFrameWidth, nFrameHeight)) | ||
frame1 = cocos2d.CCSpriteFrame:frameWithTexture(texture, cocos2d.CCRectMake(nFrameWidth*1, 0, nFrameWidth, nFrameHeight)) | ||
|
||
spritedog = cocos2d.CCSprite:spriteWithSpriteFrame(frame0) | ||
spritedog:setPosition(cocos2d.CCPoint(300, 500)) | ||
pLayer:addChild(spritedog) | ||
|
||
spriteDog = cocos2d.CCSprite:spriteWithSpriteFrame(frame0) | ||
spriteDog:setPosition(cocos2d.CCPoint(0, winSize.height/4*3)) | ||
layerFarm:addChild(spriteDog) | ||
|
||
animFrames = cocos2d.CCMutableArray_CCSpriteFrame__:new(2) | ||
|
||
animFrames:addObject(frame0) | ||
animFrames:addObject(frame1) | ||
|
||
animation = cocos2d.CCAnimation:animationWithName("wait", 0.5, animFrames) | ||
|
||
animate = cocos2d.CCAnimate:actionWithAnimation(animation, false); | ||
spritedog:runAction(cocos2d.CCRepeatForever:actionWithAction(animate)) | ||
spriteDog:runAction(cocos2d.CCRepeatForever:actionWithAction(animate)) | ||
|
||
|
||
-- add a popup menu | ||
|
||
function menuCallbackClosePopup() | ||
menuPopup:setIsVisible(false) | ||
end | ||
|
||
menuPopupItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png") | ||
menuPopupItem:setPosition( cocos2d.CCPoint(0, 0) ) | ||
menuPopupItem:registerScriptHandler("menuCallbackClosePopup") | ||
menuPopup = cocos2d.CCMenu:menuWithItem(menuPopupItem) | ||
menuPopup:setPosition( cocos2d.CCPoint(winSize.width/2, winSize.height/2) ) | ||
menuPopup:setIsVisible(false) | ||
layerMenu:addChild(menuPopup) | ||
|
||
-- add the left-bottom "tools" menu to invoke menuPopup | ||
|
||
function menuCallbackOpenPopup() | ||
menuPopup:setIsVisible(true) | ||
end | ||
|
||
menuToolsItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu1.png","menu1.png") | ||
menuToolsItem:setPosition( cocos2d.CCPoint(0, 0) ) | ||
menuToolsItem:registerScriptHandler("menuCallbackOpenPopup") | ||
menuTools = cocos2d.CCMenu:menuWithItem(menuToolsItem) | ||
menuTools:setPosition( cocos2d.CCPoint(30, 40) ) | ||
layerMenu:addChild(menuTools) | ||
|
||
cocos2d.CCDirector:sharedDirector():runWithScene(g_Scene) | ||
|
||
function tick() | ||
|
||
point = cocos2d.CCPoint(300, 500); | ||
point = spritedog:getPosition(); | ||
point = spriteDog:getPosition(); | ||
|
||
if point.x > 600 then | ||
if point.x > winSize.width then | ||
point.x = 0 | ||
spritedog:setPosition(point) | ||
spriteDog:setPosition(point) | ||
else | ||
point.x = point.x + 1 | ||
spritedog:setPosition(point) | ||
spriteDog:setPosition(point) | ||
end | ||
|
||
end | ||
|
||
cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc("tick", 0.01, false) | ||
|
||
-- run | ||
|
||
cocos2d.CCDirector:sharedDirector():runWithScene(sceneGame) |
File renamed without changes
Oops, something went wrong.