码迷,mamicode.com
首页 > 移动开发 > 详细

lua 四个背景移动

时间:2016-08-22 00:04:46      阅读:768      评论:0      收藏:0      [点我收藏+]

标签:

local GameBackbg = class("GameBackbg", function ( )
return display.newScene()
end)

function GameBackbg:ctor( down,mid,befor )
--背景
local bg = display.newSprite("#bgmap3.png")
bg:setAnchorPoint(cc.p(0,0))
--中间层
local mid = display.newSprite("#MapMiddle3.png")
mid:setAnchorPoint(cc.p(0,0))
--道路(英雄和敌人添加在这个下)
local r = display.newSprite("#MapGround3.png")
r:setAnchorPoint(cc.p(0,0))
--最前的植物
local befor = display.newSprite("#MapBefore3.png")
befor:setAnchorPoint(cc.p(0,0))

self.parallax = cc.ParallaxNode:create()
--添加的精灵 z值 速率 偏移
self.parallax:addChild(bg, 1 , cc.p(0.2,0),cc.p(0,0))
self.parallax:addChild(mid, 2 , cc.p(0.5,0),cc.p(0,320))
self.parallax:addChild(r, 3 , cc.p(0.8,0),cc.p(0,0))
self.parallax:addChild(befor, 4 , cc.p(0.8,0),cc.p(0,0))

self:setAnchorPoint(cc.p(0,0))
self:addChild(self.parallax)
local move = cc.MoveBy:create(10,cc.p(-1000,0));
self.parallax:runAction(move);
end

return GameBackbg

 

 

------------------------------------------


require("config")
require("cocos.init")
require("framework.init")
require("app.scenes.GameBackbg")


local MyApp = class("MyApp", cc.mvc.AppBase)

function MyApp:ctor()
MyApp.super.ctor(self)
end

function MyApp:run()
cc.FileUtils:getInstance():addSearchPath("res/")
display.addSpriteFrames("role.plist", "role.pvr.ccz")--预加载精灵帧
display.addSpriteFrames("mapRoad.plist", "mapRoad.png")
display.addSpriteFrames("mapMid.plist", "mapMid.png")
display.addSpriteFrames("mapBefore.plist", "mapBefore.png")
display.addSpriteFrames("gameLayer.plist", "gameLayer.png")

display.addSpriteFrames("mapBg.plist", "mapBg.png")

self:enterScene("GameBackbg")
end
return MyApp

lua 四个背景移动

标签:

原文地址:http://www.cnblogs.com/chuyunfei/p/5793905.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!