cocos2d-js 如何通过一个url获得图片 添加给精灵
1个回答
2015-08-21
展开全部
var HelloWorldLayer = cc.Layer.extend({
ctor:function () {
this._super();
var size = cc.director.getWinSize();
var bg = new cc.Sprite(res.background_png);
bg.x = size.width/2;
bg.y = size.height/2;
this.addChild(bg);
// 开始精灵
var startSpriteNormal = new cc.Sprite(res.start_up_png); ①
var startSpriteSelected = new cc.Sprite(res.start_down_png); ②
var startMenuItem = new cc.MenuItemSprite(
startSpriteNormal,
startSpriteSelected,
this.menuItemStartCallback, this); ③
startMenuItem.x = 700; ④
startMenuItem.y = size.height - 170; ⑤
// 设置图片菜单
var settingMenuItem = new cc.MenuItemImage(
res.setting_up_png,
res.setting_down_png,
this.menuItemSettingCallback, this); ⑥
settingMenuItem.x = 480;
settingMenuItem.y = size.height - 400;
// 帮助图片菜单
var helpMenuItem = new cc.MenuItemImage(
res.help_up_png,
res.help_down_png,
this.menuItemHelpCallback, this); ⑦
helpMenuItem.x = 860;
helpMenuItem.y = size.height - 480;
var mu = new cc.Menu(startMenuItem, settingMenuItem, helpMenuItem); ⑧
mu.x = 0;
mu.y = 0;
this.addChild(mu);
},
menuItemStartCallback:function (sender) {
cc.log("menuItemStartCallback!");
},
menuItemSettingCallback:function (sender) {
cc.log("menuItemSettingCallback!");
},
menuItemHelpCallback:function (sender) {
cc.log("menuItemHelpCallback!");
}
});
ctor:function () {
this._super();
var size = cc.director.getWinSize();
var bg = new cc.Sprite(res.background_png);
bg.x = size.width/2;
bg.y = size.height/2;
this.addChild(bg);
// 开始精灵
var startSpriteNormal = new cc.Sprite(res.start_up_png); ①
var startSpriteSelected = new cc.Sprite(res.start_down_png); ②
var startMenuItem = new cc.MenuItemSprite(
startSpriteNormal,
startSpriteSelected,
this.menuItemStartCallback, this); ③
startMenuItem.x = 700; ④
startMenuItem.y = size.height - 170; ⑤
// 设置图片菜单
var settingMenuItem = new cc.MenuItemImage(
res.setting_up_png,
res.setting_down_png,
this.menuItemSettingCallback, this); ⑥
settingMenuItem.x = 480;
settingMenuItem.y = size.height - 400;
// 帮助图片菜单
var helpMenuItem = new cc.MenuItemImage(
res.help_up_png,
res.help_down_png,
this.menuItemHelpCallback, this); ⑦
helpMenuItem.x = 860;
helpMenuItem.y = size.height - 480;
var mu = new cc.Menu(startMenuItem, settingMenuItem, helpMenuItem); ⑧
mu.x = 0;
mu.y = 0;
this.addChild(mu);
},
menuItemStartCallback:function (sender) {
cc.log("menuItemStartCallback!");
},
menuItemSettingCallback:function (sender) {
cc.log("menuItemSettingCallback!");
},
menuItemHelpCallback:function (sender) {
cc.log("menuItemHelpCallback!");
}
});
追问
我是要通过一个URL 获得一张图片直接让精灵显示出来的,有什么方法吗?
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询