protected RGLightLayer(ccColor4B color) { super(color); this.setIsTouchEnabled(true); CGSize winSize = CCDirector.sharedDirector().displaySize(); warning = 0; isMoving = false; isRed = true; _player = CCSprite.sprite("light_runner.png"); _player.setPosition(CGPoint.ccp(_player.getContentSize().width / 2.0f, 75)); background = CCSprite.sprite("backyard_bg.png"); // background.setTag(1); background.setAnchorPoint(0, 0); addChild(background); light = CCSprite.sprite("redlight.png"); light.setPosition(CGPoint.ccp(winSize.width - 50, 100)); a = Account.getInstance(); // this.act=act; addChild(light); addChild(_player); schedule("checkFinished"); schedule("movePlayer"); schedule("changeColor", 1.5F); }
/** 显示容器 */ public void loadContainer() { chooseContainer = CCSprite.sprite("image/fight/chose/fight_choose.png"); choseContainer = CCSprite.sprite("image/fight/chose/fight_chose.png"); choseContainer.setAnchorPoint(0, 1); choseContainer.setPosition(0, winSize.height); chooseContainer.setAnchorPoint(0, 0); this.addChild(choseContainer, 0, TAG_CHOSE); // 第二个参数,0,1表示优先级 this.addChild(chooseContainer, 1); // 加载植物信息 loadPlant(); // 添加开始图片 start = CCSprite.sprite("image/fight/chose/fight_start.png"); start.setPosition(chooseContainer.getContentSize().getWidth() / 2, 40); chooseContainer.addChild(start); }
protected void initGame(boolean firstTime, Object sender) { super.initGame(firstTime, sender); super.clearFloatingSprites(); switch (mLevel) { case 1: number_of_item_type = 1; number_of_item_max = 5; break; case 2: number_of_item_type = 2; number_of_item_max = 5; break; case 3: number_of_item_type = 3; number_of_item_max = 5; break; case 4: number_of_item_type = 3; number_of_item_max = 5; break; case 5: number_of_item_type = 4; number_of_item_max = 5; break; case 6: number_of_item_type = 4; number_of_item_max = 6; break; case 7: number_of_item_type = 4; number_of_item_max = 7; break; case 8: number_of_item_type = 4; number_of_item_max = 9; break; default: number_of_item_type = 5; number_of_item_max = 9; } // make sure the number_of_item_max is less than 10 if (number_of_item_max > 9) number_of_item_max = 9; int selectedTypes[] = new int[items.size()]; for (int i = 0; i < items.size(); ++i) selectedTypes[i] = i; super.randomIt(selectedTypes, items.size()); float answerAreaWidth = szWin.width / 5; float yAnswer = yKeyboardTop; for (int i = 0; i < number_of_item_type; ++i) { number_of_item_each_type[i] = randomBetween(1, number_of_item_max); answer_of_item_each_type[i] = -1; // set as not answered yet // make sure each type is different from others item_type[i] = selectedTypes[i]; // display these items for (int j = 0; j < number_of_item_each_type[i]; ++j) { CCSprite sprite = spriteFromExpansionFile(items.get(item_type[i])); sprite.setScale(preferredContentScale(true)); float xRandom = super.nextInt((int) (szWin.width - answerAreaWidth)); if (xRandom - sprite.getContentSize().width * sprite.getScale() / 2 < 0) xRandom = sprite.getContentSize().width * sprite.getScale() / 2; else if (xRandom + sprite.getContentSize().width * sprite.getScale() / 2 > szWin.width - answerAreaWidth) xRandom = szWin.width - answerAreaWidth - sprite.getContentSize().width * sprite.getScale() / 2; float yRandom = super.nextInt((int) szWin.height); if (yRandom - sprite.getContentSize().height * sprite.getScale() / 2 < yKeyboardTop) yRandom = yKeyboardTop + sprite.getContentSize().height * sprite.getScale() / 2; else if (yRandom + sprite.getContentSize().height * sprite.getScale() / 2 > szWin.height - topOverhead()) yRandom = szWin.height - topOverhead() - sprite.getContentSize().height * sprite.getScale() / 2; sprite.setPosition(xRandom, yRandom); sprite.setTag(kTagItem); super.addChild(sprite, 1); floatingSprites.add(sprite); } // the answer for this item CCSprite sprite = spriteFromExpansionFile( "image/activities/math/numeration/enumerate/enumerate_answer.png"); sprite.setPosition( szWin.width - answerAreaWidth / 2, yAnswer + sprite.getContentSize().height / 2); sprite.setTag(kTagAnswerBg + i); super.addChild(sprite, 1); floatingSprites.add(sprite); // the icon CCSprite icon = spriteFromExpansionFile(items.get(item_type[i])); icon.setScale(sprite.getContentSize().height / icon.getContentSize().height * 0.5f); icon.setPosition( sprite.getPosition().x - sprite.getContentSize().width / 2 + 4 + icon.getContentSize().width * icon.getScale() / 2, sprite.getPosition().y); super.addChild(icon, 1); floatingSprites.add(icon); // the lable on it CCLabel label = CCLabel.makeLabel("?", super.sysFontName(), super.mediumFontSize()); label.setColor(ccColor3B.ccBLACK); label.setPosition( sprite.getPosition().x + label.getContentSize().width, sprite.getPosition().y); super.addChild(label, 3); floatingSprites.add(label); sprite.setUserData(label); // move top a little for next item answer yAnswer += sprite.getContentSize().height + 6; } answeringIndex = 0; // start to answer the first type of items this.refreshAnswers(); }