0

I could use help with customization in Flash games! I am pretty new to AS3 and have a game I am building where the user can dress the character based on a few options and a color picker, then move on to a race. I cannot get the clothes that are chosen to stay, and the ones excluded leave, without all of them staying or leaving. I've tried variables, if/else conditions and switch statements, but nothing is working. I have a feeling it's a condition, but I don't know how to write it and can't find anyone in a similar boat.

I have been scouring my books (Flash CS6 Missing Manual and ActionScript 3.0 Cookbook), and I've gotten very close, but nothing works. I really could use a lot of help with this, it's a final project and the stress might be hiding the answer, but I surely don't have it.

Not sure if I did this right, I've never used this site before. Thank you in advance!


UPDATE


Here is a link to where the .swf file is currently uploaded for your input. http://yellownotebook.weebly.com/other-work.html Please ignore the DONE button at the beginning, I am working on that still. I need the clothes to be invisible on the start up, and the remaining unselected clothes after that to be discarded? Invisible? I still don't understand which way is best for this situation. I started reading something about Display Lists?

I'm also not sure what part of the code would be most helpful, so here it is.

var mcdress2 = mcdress2
var mcpants = mcpants
var mcshirt = mcshirt
var mctop = mctop
var clothes = mctop + mcpants + mcshirt + mcdress2
var fairy = clothes + mcwings + mcfay

mcfay.visible = false;
mctop.visible = false;
mcshirt.visible = false;
mcpants.visible = false;
mcdress2.visible = false;
mcwings.visible = false;
cpClothes.visible = false;

import fl.events.ColorPickerEvent;

fairybg.btnplay.addEventListener(MouseEvent.CLICK,clickPlayListener);
btndone.addEventListener(MouseEvent.CLICK,clickDoneListener);

fairybg.gotoAndStop("Game Start");

function clickPlayListener(evt:MouseEvent):void
{
    fairybg.gotoAndStop("Background Start")
    mcfay.visible = true;
    mctop.visible = true;
    mcshirt.visible = true;
    mcpants.visible = true;
    mcdress2.visible = true;
    mcwings.visible = true;
    cpClothes.visible = true;
}
//fairy.scaleY = fairy.scaleX
function clickDoneListener(evt:MouseEvent):void
{
    fairybg.gotoAndStop("Background Fly")
    fairybg.gotoAndStop("Background Fly")
    //fairy.width = 1/2
    //fairy.height = 1/2;
    //if it was this way, she would be bare when she flies, needs "if" condition?
    //mctop.visible = false;
    //mcshirt.visible = false;
    //mcpants.visible = false;
    //mcdress2.visible = false;
    cpClothes.visible = false;
    btndone.visible = false;
}
//fairy.scaleY = fairy.scaleX

mcdress2.gotoAndStop(1);

mcdress2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener);

function mouseDownListener (event:MouseEvent):void

{
    mcdress2.gotoAndStop("Dress End");
        mctop.gotoAndStop("Top Start");
mcpants.gotoAndStop("Pants Start");
    mcshirt.gotoAndStop("Shirt Start");
}

mcshirt.gotoAndStop(1);

    mcshirt.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener2);

function mouseDownListener2 (event:MouseEvent):void

{
    mcshirt.gotoAndStop("Shirt End");
    mcdress2.gotoAndStop("Dress Start");
    mctop.gotoAndStop("Top Start");
}

mcpants.gotoAndStop(1);

mcpants.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener3);

function mouseDownListener3 (event:MouseEvent):void

{
    mcpants.gotoAndStop("Pants End");
    mcdress2.gotoAndStop("Dress Start");
}

mctop.gotoAndStop(1);

mctop.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownListener4);

function mouseDownListener4 (event:MouseEvent):void

{
    mctop.gotoAndStop("Top End");
    mcshirt.gotoAndStop("Shirt Start");
    mcdress2.gotoAndStop("Dress Start");
}

//use color picker to change clothing color (all items same color)


cpClothes.addEventListener(ColorPickerEvent.CHANGE,changeColorPicker);
function changeColorPicker(evt:ColorPickerEvent):void
{
    var myColorTransform = new ColorTransform ();
    myColorTransform.color = evt.color;
    mcdress2.transform.colorTransform = myColorTransform;
    mctop.transform.colorTransform = myColorTransform;
    mcshirt.transform.colorTransform = myColorTransform;
    mcpants.transform.colorTransform = myColorTransform;
    //trace ("color changed")
    //trace (evt.color)
    //trace (mcdress.color)
    //opaqueBackground = evt.color;
}

cpClothes.colors =
[0xF7977A,0xFFF79A,0x6ECFF6,0xF49AC2];

switch (clothes) {
    case "Dress End" :
            mcshirt.visible = false;
    mctop.visible = false;
    mcpants.visible = false;
break;
case "Top End" :
    mcshirt.visible = false;
    mcdress2.visible = false;
    mcpants.visible = false;
break;
case "Shirt End" :
    mctop.visible = false;
    mcdress2.visible = false;
    mcpants.visible = false;
break;
default :
    //mcdress2.gotoAndStop("Dress Start")
    //mctop.gotoAndStop("Top Start")
    //mcshirt.gotoAndStop("Shirt Start")
    //mcpants.gotoAndStop("Pants Start")
    mcdress2.visible = true;
    mctop.visible = true;
    mcshirt.visible = true;
    mcpants.visible = true;
}

/*if (clickDoneListener==true) {
fairy.width = .5
fairy.height = .5;
}*/

//trace ("it works!")

//var _mcpants:mcpants;

//function newmcpants(e:MouseEvent):void
//{
    //if (_mcpants)
    //  return
    //_mcpants = new mcpants();
    //_mcpants.x = 263.35;
    //_mcpants.y = 270.40;

    //addChild(_mcpants);
//}

//function deletemcpants(e:MouseEvent):void;
//{
    //if (_mcpants && contains(_mcpants))
    //removeChild(_mcpants);

    //_mcpants = null;


//displayText("Deleted mcpants successfully!");
//}

As you can see, I have a lot of code commented out, I have been trying everything I can find for it to work. I also am trying to scale her down 50% after the DONE button is clicked and the game is started, but I have not figured out a way for that one either. Thank you so so much for any help!

4

1 回答 1

0

您必须在系统中添加有关已选择哪些衣服的信息。你是对的,它是关于条件的,但你的条件将需要信息来作为选择的基础。我认为有3种选择:

  1. 管理穿上的衣服的集合
  2. 制作具有属性的衣服对象,cloth.weared = true 或 false
  3. 为您的衣服设置插槽:上身、下身等,并在那里分配选定的衣服:上身 = somecloth;

我做了 1. 作为你的一个简单的例子。希望你能明白!可能不是最优雅的解决方案,但确实有效,非常简单,我认为逻辑非常接近您已经拥有的:http: //jsfiddle.net/n37qx/

var selected = [];

var SHIRT = "shirt";
var DRESS = "dress";
var TROUSERS = "trousers";
var all = [SHIRT, DRESS, TROUSERS];

//logic
function putOn(cloth) {
    if (arraycontains(selected, cloth)) {
        return;
    }

    //replace check
    if (cloth === SHIRT) {
        removeIfContains(selected, DRESS);
    } else if (cloth === DRESS) {
        removeIfContains(selected, SHIRT);
        removeIfContains(selected, TROUSERS);
    }

    selected.push(cloth);
}

function hideNotSelected() {
    for (var i=0; i < all.length; i++) {
        var cloth = all[i];
        if (arraycontains(selected, cloth)) {
            log("wearing - not hiding: " + cloth)
        } else {
            log("hide: " + cloth);
        }
    }
}

//test flow - code instead of UI actions
log("1. Put on shirt + trousers, dress should get hidden:");
putOn(SHIRT)
putOn(TROUSERS);
hideNotSelected();

log("---");
log("2. Put on dress - trousers and shirt should get hidden:");
putOn(DRESS);
hideNotSelected();

//utilities
...

那是Javascript。Actionscript 基本上是带有扩展的 Javascript (ECMAScript)。你已经有了很好的数组助手,所以不需要我添加到底部的那些。http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/ArrayList.html

于 2014-05-04T04:38:12.607 回答