axmol/samples/TestJavascript/Resources/oldjs/test-nodes.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

var director = cc.Director.sharedDirector();
var scene = new cc.Scene();
2012-04-18 03:43:08 +08:00
scene.init();
// our test sprite
var sprite = new cc.Sprite();
2012-04-18 03:43:08 +08:00
sprite.initWithFile("Icon.png");
var pt = new cc.Point();
2012-04-27 02:04:11 +08:00
pt.x = 160;
pt.y = 240;
2012-04-18 03:43:08 +08:00
sprite.position = pt;
// will call "update" every frame if there's an update property
2012-04-27 02:04:11 +08:00
//sprite.scheduleUpdate();
sprite.speed = new cc.Point();
2012-04-18 03:43:08 +08:00
sprite.speed.x = Math.random() * 10 - 5;
sprite.speed.y = Math.random() * 10 - 5;
// the actual update function
sprite.update = function () {
var curPos = this.position;
curPos.x += this.speed.x;
curPos.y += this.speed.y;
this.position = curPos;
2012-04-27 02:04:11 +08:00
if (curPos.x >= 320 || curPos.x <= 0) this.speed.x *= -1;
if (curPos.y >= 480 || curPos.y <= 0) this.speed.y *= -1;
2012-04-18 03:43:08 +08:00
};
// adds the sprite to the scene
scene.addChild(sprite);
2012-04-27 02:04:11 +08:00
// add a menu
var item = new cc.MenuItemImage();//Sprite();
//var normal = new cc.Sprite(); normal.initWithFile("CloseNormal.png");
//var selected = new cc.Sprite(); selected.initWithFile("CloseSelected.png");
//item.initWithNormalSprite(normal, selected);
2012-04-27 02:04:11 +08:00
item.initFromNormalImage("CloseNormal.png", "CloseSelected.png");
item.action = function () {
cc.log("action");
2012-04-27 02:04:11 +08:00
};
cc.log("normal image: " + item.normalImage);
2012-04-27 02:04:11 +08:00
pt.x = 20;
pt.y = 20;
item.position = pt;
var menu = new cc.Menu();
2012-04-27 02:04:11 +08:00
menu.init();
menu.addChild(item);
pt.x = 0;
pt.y = 0;
menu.position = pt;
scene.addChild(menu, 1);
2012-04-18 03:43:08 +08:00
// let the games begin
director.runWithScene(scene);