Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

chess in action script

New Here ,
Apr 19, 2011 Apr 19, 2011

hey there 🙂

i got a small problem with actionscript. i want to let my chess board fade from low transparency to 100% transparency and i need to do this in action script...i've already tried several ways via greensock etc. can anyone help me? thank you here's my code:

import com.greensock.*;

import com.greensock.plugins.*;

TweenPlugin.activate([TintPlugin]);

var Schachbrett:Array = new Array();

for(var i:int = 0; i < 4; i++)

{

    Schachbrett.push(new Array(1,0,1,0,1,0,1,0));

    Schachbrett.push(new Array(0,1,0,1,0,1,0,1));

}

var unitSize:int = 60;

function baueSchachbrett():void

{

    for(var i:int = 0; i < Schachbrett.length; i++)

    {

        for(var j:int = 0; j < Schachbrett.length; j++)

        {

            var tile:Sprite = new Sprite();

            var tileColor:int = Schachbrett * 0xffffff;

            tile.graphics.beginFill(tileColor);

            tile.graphics.drawRect(0, 0, unitSize, unitSize);

            tile.graphics.endFill();

            tile.name = ("tile__" + i + "_" + j + "_sp");

        tile.addEventListener(MouseEvent.CLICK, klick);

            tile.x = j * unitSize;

            tile.y = i * unitSize;

            addChild(tile);

        }

    }

}

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 19, 2011 Apr 19, 2011

import com.greensock.*;

import com.greensock.plugins.*;

TweenPlugin.activate([TintPlugin]);

var schachbrett:Sprite=new Sprite();

addChild(schachbrett);

schachbrett.alpha=0;

var Schachbrett:Array = new Array();

for(var i:int = 0; i < 4; i++)

{

    Schachbrett.push(new Array(1,0,1,0,1,0,1,0));

    Schachbrett.push(new Array(0,1,0,1,0,1,0,1));

}

var unitSize:int = 60;

function baueSchachbrett():void

{

    for(var i:int = 0; i < Schachbrett.length; i++)

    {

        for(var j:int = 0; j < Schachbrett.length; j++)

 

...
Translate
Community Expert ,
Apr 19, 2011 Apr 19, 2011

if your board's reference is board, use:

var speed:Number=1;

board.alpha=.1;

TweenLite.to(board,speed,{alpha:1});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2011 Apr 19, 2011

I don't see any tweening code here.

Also it would generally be better if all your individual tiles for each square were added to a parent sprite (or what have you) so then you could just fade up that one thing.

Currently your are just doing:

addChild(tile)

something like

schachbrett.addChild(tile)

would probably be a better strategy. Then you could just tween in the parent clip.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2011 Apr 19, 2011

thanks for your quick replay   regrettably actionscript is completely new for me...can you tell me what exactely i have to change in my code? where do i have to put schachbrett.addChild(tile)?

the tweening code should look like this i think:

new TweenLite(???, 3, {tint:0xff0000});

so what do i have to put in for the three "?"?

thanks again

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 19, 2011 Apr 19, 2011

Exactly. What will you put for the ????

Just like in real life all the little tile squares on a chessboard belong to the chessboard and if you throw it across the room they all go. If they were all individuals it would be much more difficult to throw them all across the room 1 by 1.

So first create your chessboard.

var schachbrett:Sprite=new Sprite();

addChild(schachbrett)

Then make all your tiles with the loop and code you have except instead of

addChild(tile)

you would use

schachbrett.addChild(tile)

And then you would use the Tween syntax given by kglad above, that is assuming you wanted to do an alpha fade.

var speed:Number=1;

schachbrett.alpha=.1;

TweenLite.to(schachbrett,speed,{alpha:1});

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 19, 2011 Apr 19, 2011

import com.greensock.*;

import com.greensock.plugins.*;

TweenPlugin.activate([TintPlugin]);

var schachbrett:Sprite=new Sprite();

addChild(schachbrett);

schachbrett.alpha=0;

var Schachbrett:Array = new Array();

for(var i:int = 0; i < 4; i++)

{

    Schachbrett.push(new Array(1,0,1,0,1,0,1,0));

    Schachbrett.push(new Array(0,1,0,1,0,1,0,1));

}

var unitSize:int = 60;

function baueSchachbrett():void

{

    for(var i:int = 0; i < Schachbrett.length; i++)

    {

        for(var j:int = 0; j < Schachbrett.length; j++)

        {

            var tile:Sprite = new Sprite();

            var tileColor:int = Schachbrett * 0xffffff;

            tile.graphics.beginFill(tileColor);

            tile.graphics.drawRect(0, 0, unitSize, unitSize);

            tile.graphics.endFill();

            tile.name = ("tile__" + i + "_" + j + "_sp");

        tile.addEventListener(MouseEvent.CLICK, klick);

            tile.x = j * unitSize;

            tile.y = i * unitSize;

            schachbrett.addChild(tile);

        }

    }

TweenLite.to(schachbrett,1,{alpha:1});

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2011 Apr 19, 2011
LATEST

many many thanks you are the best ones! worked fine... 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines