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

custom shapes/sprites with code, where to start?

Guest
Dec 05, 2009 Dec 05, 2009

Hello,


I want to start building some prebuild shapes, like a star, cross, heart, and some more with code.


Does anyone know if there is already something like this ? A library with custom sprites or shapes?


And should i create these graphics extending the sprite or shape class? I read that shapes would
be better for performance?

Regards,
Chris.

TOPICS
ActionScript
840
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 , Dec 05, 2009 Dec 05, 2009

use google to search.

i know there is public php code for some shapes and the code's not much different for actionscript.

use shapes.  there's not much difference, if any, in performance but you won't be using any of the properties/methods of the sprite class so you may as well use the shape class.

Translate
Community Expert ,
Dec 05, 2009 Dec 05, 2009

use google to search.

i know there is public php code for some shapes and the code's not much different for actionscript.

use shapes.  there's not much difference, if any, in performance but you won't be using any of the properties/methods of the sprite class so you may as well use the shape class.

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
Guest
Dec 05, 2009 Dec 05, 2009

thanks Kglad, i did some search on this topic, but could not find

prebuild shapes in Flash. So when i want to set properties of a shape, then
it is better to use a Sprite?

var myShape:CustomArrow = new CustomArrow();

myShape.color = 0xFF0000;

myShape.arrowSize = 14;

myShape.arrowlineWidth = 200;

This is the idea of using dynamic Shapes.

Regards,
Chris.

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 ,
Dec 05, 2009 Dec 05, 2009

yes, use shapes.  but that would look more like:

package{

import flash.display.shape;

public class CustomArrow extends Shape{

//etc

var ca:CustomArrow=new CustomArrow();

//etc

// and heres an as2 start/polygon drawing function for you.  the groinRatio is the ratio of the stars groin to its radius.  if that's 1, you'll have a polygon instead of a star.

function drawPolyStar(mc:MovieClip, x1:Number, y1:Number, x2:Number, y2:Number, starPoints:Number, groinRatio:Number, lineA:Array, fillA:Array):Void {

    var piHalf:Number = Math.PI/2;
    var ang:Number = Math.PI*2/starPoints;
    var w2:Number = Math.abs(x2-x1)/2;
    var h2:Number = Math.abs(y2-y1)/2;
    var rad:Number = h2;

    if (lineA[0]) {
        mc.lineStyle(lineA[0],lineA[1],lineA[2]);
    }
    if (fillA[0]) {
        mc.beginFill(fillA[0],fillA[1]);
    }
    if (lineA == undefined && fillA == undefined) {
        mc.lineStyle(1,0x000000);
    }
   
    // start at top
    mc.moveTo(w2,0);
    for (var i:Number = 0; i<starPoints; i++) {
        var ptAng:Number = -piHalf+i*ang;
        mc.lineTo(w2+(h2*w2/h2)*Math.cos(ptAng),h2+rad*Math.sin(ptAng));
        var ptGroin:Number = ptAng+ang/2;
        mc.lineTo(w2+groinRatio*(h2*w2/h2)*Math.cos(ptGroin),h2+groinRatio*rad*Math.sin(ptGroin));
    }
    mc.endFill();
}

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
Guest
Dec 05, 2009 Dec 05, 2009

Many thanks Kglad! This is a very helpfull script!!!

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 ,
Dec 05, 2009 Dec 05, 2009
LATEST

you're welcome.

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