collision detection: custom class and table

so I do a shooter from top to bottom for the pleasure, but have been struggling as I am new to programming.

I have

var player: player = new Player();

enemy var: Array = new Array();

now I searched on the net, but that's what I tried to work with.

public void checkCollisionWithShip(): void {}

for (var e = Enemies.length - 1; e > = 0; e-) {}

If (Enemies [e] .hitTestObject (player)) {}

trace ([e] Enemies);

Life = 1;

updateUI();

trace ("ship collision!");

}

}

}

However, whenever my (player) ship hits an enemy, nothing ever happens.

looking forward to your answers.

Thank you very much for your time.

Unfortunately the code that you decide should be shown is not code that needs to be shown.  Which calls the function where the collision is detected?  I don't see anything for this.

Tags: Adobe Animate

Similar Questions

  • BUG: 1 D table sort isn't sorting table of Classes and table Clusters contain Classes

    the function "sort the table 1 d.

    I wanted to sort the array of Clusters [number and class]. But to my surprise, LV is not like him.

    Okay, I need sort table Classes. But maybe once in the future I will. :-)

    'Research in table 1 d' is the use of classes I do not understand why 'sort the table 1 d' does not work.

    This problem is in LabVIEW 8.2 and 8.5 2009

    I think that the search feature of table 1 d can address each element in the table as an agregate whereas sort requires access to the private data in the data from the class and carrying it even further...

    Say all the elements are in the Parent class and a tow children who both have private data that are uniqie each and not present in the class of parents...

    How they manage breaking when there are different fields to sort on?

    Ben

  • Classes and custom Assembly in flex

    Hello

    In flash I create my custom class and then secure it with a binding and call it. How do I do this in flex?

    Suffice to say that I wanted all the images for this class below. How to call the getCurrentCard method?

    Thank you.



    package myClasses
    {
    Import mx.controls.Image;

    public class moveIt extends Image
    {
    public void moveIt()
    {
    Super();
    }

    public void go (): void {}

    x = 200;
    }

    }
    }

    In response to my own question

    Create your custom class
    Import it into your script block

    Put it on the stage

    call it in your actionscript code

    myLogo.go ();

    simple!

  • To access the event listeners in the custom class

    I am a construction and film using the classes customized for the first time. I built a custom class and bound a clip in my film for her so that the color of the text in the video will change when he is overthrown. I have 10 occurrences of this clip in the film, so it saves me a lot of code. Instead of writing 10 to ROLL_OVER event listeners and 10 more for ROLL_OUT (as I have done in the past), one for each instance of the clip on the scene, I wrote now event listeners and the corresponding functions in the custom class. So far, so good, everything works fine. When I ride above and outside on one of the 10 instances of the clip on the stage it changes color. See code attached.

    However, according to what is happening in the film, that I sometimes need to turn off the headphones of events on one or more video clips. So, I wrote the code in the movie itself to remove event listeners of the instance of the clip that I need to disable. See code attached.

    But, alas, it does not work.

    I get this error:
    ReferenceError: Error #1065: Variable turnWhite is not defined.

    I thought that by the 'public' method in the custom class, I would be able to call from the film, but I do not. Any help or advice would be greatly appreciated. Thank you very much.

    Ned, thanks for your help. I was able to understand. Your code has been helpful, and I've used something similar to what you suggested.

  • Learn how to work with a custom class

    I am just learning to work with custom classes and I am writing my first real one. I want multiple instances of MovieClip on the stage at all change the color of the type when knocked down and I also want to 'finger' icon appears instead of a pointer. Everything works except the finger icon, for which I use buttonMode. Can someone tell me what I'm doing wrong here or point me in the right direction? Any ideas would be greatly appreciated. Thank you.

    package {}

    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.text.TextFormat;
    import flash.text.TextField;

    SerializableAttribute public class PlayerSongs extends Sprite {}
    public void PlayerSongs() {}
    trace ("PlayerSongs class is working!");

    var _myTextFormat:TextFormat;

    this.addEventListener (MouseEvent.ROLL_OVER, overChange);
    this.addEventListener (MouseEvent.ROLL_OUT, outChange);
    this.buttonMode = true;
    }

    function overChange(Event:MouseEvent):void {}
    trace ("TypeRollOver is working!");
    _myTextFormat = new TextFormat();
    _myTextFormat.color = 0xE30A06;
    this.myText.setTextFormat (_myTextFormat);
    }

    function outChange(Event:MouseEvent):void {}
    trace ("TypeRollOut is working!");
    _myTextFormat = new TextFormat();
    _myTextFormat.color = 0 x 000000;
    this.myText.setTextFormat (_myTextFormat);
    }
    }
    }

    turn off the members of your class mouseChildren property. (and you do not need to recreate _myTextFormat with each rollover and rollout: just declare it outside your Builder and create in your constructor, not in your overChange and methods of modificationmodificationnotifications in.)

    p.s., use the option attach code to view the code in this forum.

  • Table element collision detection

    Hello!

    This is part of my code:

    var boxArray:Array = [];
    //...
    function init():void {
        stage.addEventListener(Event.ENTER_FRAME, loop);
    }
    
    function loop(e:Event):void {
    //...
    
    if(boxArray.length == 0){
            var totalX:int=9;
            var totalY:int=8;
            var spacing:Number = 10;
            var box_mc:MovieClip;
    
            for(var i:int = 0; i < totalX; i++){
                for(var j:int = 0; j < totalY; j++){
                    box_mc = new Box();
                    boxArray[i] = box_mc;
                    box_mc.instanceName = "box"+i+j;
                    trace (box_mc.instanceName)
    
                    box_mc.x = 80 + i*(box_mc.width+spacing);
                    box_mc.y = 70 + j*(box_mc.height+spacing);
                    addChild(box_mc);
    
                    trace (boxArray.length)
                    //---------------------------------------------it works:)
                }
            }
        }
    //there i need to add collision detection for array elements with "ball". Ball is a movie clip on stage.
    //need something like that i think:
    
    function collision(){
            var target = one of array element:)
    
            if(boxArray[target].visible==true){
                if (boxArray[target].hitTestObject(ball)==true) {
                    ballSpeedY*=-1;
                    score=score+100;
                    trace ('Score= ' + score);
                    boxArray[target].visible=false;
    
                }
            }
        }
    
       collision();
    
    
    
    //...
    }//end loop
    

    If anyone can help me I will be grateful

    Greetings and sry for my English :)

    In your collisionDetector function you want to set up two loops as you did when you created them to be able to go through all.  If you were to store in a single dimension table, it would be a loop less to deal with.  If you want / can do depends on if you need to retain the knowledge where the boxes are compared to the i / j clues when it comes to the "/ / do something ' is part of the treatment.

    In order to store in a single dimension table just use the push() method of the array class instead of their assignment with the brackets [i] [j].

  • Customize the class Edittext with custom width and height

    I need a class of edittext customize where I can adjust the width and height, but I do not find such a custom class that extends the class EditField and the opportunity to set the width and height. I need to access the EditField methods also. Can we have such a class?

    I solved the problem by substituting the positioning method.

    UriField = new EditField ("", strUri, 2000, EditField.READONLY |) EditField.FIELD_LEFT | EditField.FIELD_VCENTER)
    {
    public void layout (int width, int height) {}
    Are police = getFont();
    int _fieldHeight = font.getHeight ();
    int _fieldWidth = 190;
    Super.Layout (Width, Height);
                    
    setExtent (_fieldWidth, _fieldHeight);

    }
    };

    Thank you all

  • LOV cascading if I don't have only one table with the customer name and the name of the product in the ADF.

    Hi Please help me how to use cascade, if I don't have only one table with the customer name and the name of the product in the ADF... I use Jdeveloper 11.1.

    For the client, I used customer VO with client list to fill but to populate the product that I use bind variable PrODUCT_NAME select distinct from TABLE where client_name =: bindCustomer

    so first of all, I need to set the variable of liaison on behalf of the selected customer.

    Can you please tell me how to set this variable binding in this case.

    After you set the LOV to your product attribute, correspondting VO in the LOV will appear under view accessors.

    Change the accessor of the view, you will see the variable binding. Set its value to the customer field of the parent object.

    Visit this link: https://www.youtube.com/watch?v=nXwL2_RP7AQ

    Kind regards

    Elias.

  • Properties of the label and the custom class

    I want to do the following persistent: < mx:Label useHandCursor = "true" buttonMode = "true" mouseChildren = "false" / >

    I tried to create a custom class that extends the class Label, but we can't get the syntax right.

    protected override?

    buttonMode = true;

    I don't think I want to replace a function.  It seems to me that I want to override a property or attribute of the Label class.

    Can someone give me advice?

    Hello

    As you Lable with the default property {useHandCursor = "true" buttonMode = "true" mouseChildren = "false"}

    I extend the label, you can do it directly in the constructor by setting

    -Custom label class-

    package
    {
    Import mx.controls.Label;

    SerializableAttribute public class CusLbl extends Label
    {
    public void CusLbl()
    {
    Super();
    super.buttonMode = true;
    super.useHandCursor = true;
    super.mouseChildren = false;
    }
           
    }
    }

    --------------------------------------------------------------------------------

    You can use directly in the application or in any other container with the default property;

    See attached the file if necessary.

    Regarding

    Virat Patel

  • Collision detection problem

    Hey guys,.

    I practice so the creation of a platform game. I have a movement system works, but when you try to add collision with platforms I have a problem.

    I did add each platform in a table and then check for the collision between the player and each platform, since I have just a bunch of instances without the platform symbol name on my stage. The problem with this is that my jumping code, I use a Boolean "onGround" value, which determines whether or not the player is "on the ground". And since my loop "foreach" across ALL platforms, even if the player is on a platform of some, there are other, it won't, and if it returns the onGround Boolean false.

    It's a problem with my code of jumping in general, I wonder where I get out of here. If I need to change my code from jumping, or change the collision, or what. Any ideas would be great. Here is my code:

    package  
    {
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.events.KeyboardEvent;
        import flash.display.DisplayObject;
    
        public class Main extends MovieClip
        {
    
            var arrowUp:Boolean = false;
            var arrowDown:Boolean = false;
            var arrowLeft:Boolean = false;
            var arrowRight:Boolean = false;
    
            var arrowUpReleased:Boolean = true;
            var arrowDownReleased:Boolean = true;
            var arrowLeftReleased:Boolean = true;
            var arrowRightReleased:Boolean = true;
    
            var onGround:Boolean = undefined;
            var isJumping:Boolean = undefined;
    
            var vx:Number = 0;
            var vy:Number = 0;
            var acceleration:Number = 1;
            var gravity:Number = 0.3;
            var jumpForce:Number = 7;
    
            var speedLimit:uint = 6;
    
            var platformArray:Array = new Array();
            var platformNumber:uint = 0;
    
            var thePlatform:MovieClip;
    
            public function Main() 
            {
                stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
                stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
                stage.addEventListener(Event.ENTER_FRAME, update);
    
                for (var i:uint = 0; i < numChildren; i++)
                     {
                         if(getChildAt(i) is Platform)
                         {
                             platformArray.push(getChildAt(i));
                         }
                     }
                for each (var platform:DisplayObject in platformArray)
                {
                    if (platform.hitTestPoint(player.x, player.y + 20, true))
                        {
                            vy = 0;
                            onGround = true;
                        }
                }
            }
    
            function keyPressed(event:KeyboardEvent):void
            {
                if (event.keyCode == 37)
                {
                    arrowLeft = true;
                    arrowLeftReleased = false;
                }
                if (event.keyCode == 38)
                {
                    arrowUp = true;
                    arrowUpReleased = false;
                    isJumping = true;
                }
                if (event.keyCode == 39)
                {
                    arrowRight = true;
                    arrowRightReleased = false;
                }
                if (event.keyCode == 40)
                {
                    arrowDown = true;
                    arrowDownReleased = false;
                }
    
            }
    
            function keyReleased(event:KeyboardEvent):void
            {
                if (event.keyCode == 37)
                {
                    arrowLeft = false;
                    arrowLeftReleased = true;
                }
                if (event.keyCode == 38)
                {
                    arrowUp = false;
                    arrowUpReleased = true;
                    isJumping = false;
                }
                if (event.keyCode == 39)
                {
                    arrowRight = false;
                    arrowRightReleased = true;
                }
                if (event.keyCode == 40)
                {
                    arrowDown = false;
                    arrowDownReleased = true;
                }
    
            }
    
            function update (event:Event):void
            {
    
                //ACCELERATION
                if (arrowLeft)
                {
                    if (vx > 0)
                    {
                        vx = 0;
                    }
                    if ((Math.abs(vx)) < speedLimit)
                    {
                        vx -= acceleration/2;
                        player.x += vx;
                    }
                    else
                    {
                        player.x += vx;
                    }
                }
                if (arrowRight)
                {
                    if (vx < 0)
                    {
                        vx = 0;
                    }
                    if (vx < speedLimit)
                    {
                        vx += acceleration/2;
                        player.x += vx;
                    }
                    else
                    {
                        player.x += vx;
                    }
                }
                if (arrowUp && onGround)
                {
                    vy = -jumpForce;
                }
    
                //DECELERATION
                if (arrowLeftReleased)
                {
                    if (vx < 0)
                    {
                        vx += acceleration;
                        player.x += vx;
                    }
                }
                if (arrowRightReleased)
                {
                    if (vx > 0)
                    {
                        vx -= acceleration;
                        player.x += vx;
                    }
                }
    
    
                //GRAVITY
    
                player.y += vy;
    
                if (!onGround)
                {
                    vy += gravity;
                }
                if (onGround && !isJumping)
                {
                    vy = 0;
                }
                if (vy > 0)
                {
                    onGround = false;
                }
                else
                {
                    onGround = true;
                }
    
                //COLLISION
    
                for each (var platform:MovieClip in platformArray)
                {
                    if (platform.hitTestPoint(player.x, player.y + 20, true))
                    {
                        vy = 0;
                        onGround = true;
                    }
                    else
                    {
                        onGround = false;
                    }
                }
    
                trace (onGround);
            }
    
        }
    
    }
    

    Thank you

    PS what is happening right now with that code is that the player hit the platform and stops, but onGround rest false

    Probably, there is too much code for anyone to really go. However, from what you said on your loop for:

    for each {(var plate-forme: DisplayObject dans platformArray)}

    If (platform.hitTestPoint (player.x, player.y + 20, true)) {}

    Vy = 0;

    onGround = true;

    }

    }

    I think what you want is to put a break; in there right after onGround = true; -C' is to say stop the treatment when you find a ground plan.

    Also, there are a couple of collision of good systems out there that might make this a little easier and more robust. Take a look at the Kit of detection of Collision (CDK):

    https://code.Google.com/p/collisiondetectionkit/

  • SQLite, from SQLinstructions to a custom class

    I'm working on an AIR of FB app.

    I have a file with a source main.mxml in main.as file.

    My main.as file becomes very swollen with SQLinstructions. I want to switch to a custom class, but I do not know how to proceed.

    I found an example of a package on this page: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/data/SQLConnectio n.html #begin)

    on a 3rd down.

    The example above, that's exactly what I want to do, but I do not know how to adapt it for use in my file main.as beyond to import the class and instantiate. How can I assign my values in the class file? How to use the class to load up the dataProvider, etc...

    In addition, in the example above, the class extends Sprite. This sounds like it is for a Flash application. I always extend Sprite in Flex 4? I made a couple of simple events, data transmission to the main application with the Flash.Events.Event, so using Sprite causes some confusion.

    In a previous post, Amy suggested using Robotlegs. I think I need to get a handle on the use of Flex before I explore other architectures. I'm just not that sophisticated.

    Thank you

    Kristin

    OK, a small example

    a new package called utilities, then a new called class class actionscript DatabaseManager

    package utilities
    {
         import flash.data.SQLConnection;
         import flash.data.SQLResult;
         import flash.data.SQLStatement;
         import flash.filesystem.File;
    
         import mx.collections.ArrayCollection;
    
         public class DatabaseManager
         {
              private var sqlConnection:SQLConnection;
              private var stm:SQLStatement;
    
              public function DatabaseManager()
              {
    
                   //connect to database
                   sqlConnection = new SQLConnection();
                   sqlConnection.open(File.applicationStorageDirectory.resolvePath("whatever"));
    
                   //create tables if not exist
                   stm = new SQLStatement();
                   stm.sqlConnection = sqlConnection;
                   stm.text = "create your table here";
                   stm.execute();
    
                   //create more tables
                   //...
              }
    
              public function getThings():ArrayCollection
              {
                   stm = new SQLStatement();
                   stm.sqlConnection = sqlConnection;
                   stm.text = "your query";
                   //...
              }
    
              public function addStuff(stuff:Object):int
              {
                   //...
              }
         }
    }
    

    then in your main file, you need to import

    import utilities.DatabaseManager;
    

    instantiate the class, it connects and creates tables

    private var myDB:DatabaseManager = new DatabaseManager();
    

    then to use it

    var listFromDatabase:ArrayCollection = myDB.getThings();
    
    insertid = myDB.addStuff(thingToAdd);
    

    hope that gives you an idea

  • Custom class extends HashMap - error: "does not settings.

    Hi all! This is my first post on the forum, and I chose this card because it seems to be the most active. I'm relatively new to Java, but I'm already deep enough into the language.

    I have a custom class that is declared as follows:

    public class DBFRecord extends HashMap {}

    Methods here, but no constructor

    }

    The idea was to get a custom class of the hash table with a method of extracting more precisely typed values. My understanding is that, because I don't get a constructor for the class, it defaults to the parent constructor, that is, of course, HashMap(). Where I ran into trouble was when I tried to fix a compiler warning that complained a "unchecked put." I read somewhere that this can be corrected by specifying the data type of the card to the instantiation. So, I tried this:

    DBFRecord < String, Object > record = new DBFRecord < String, Object > ();

    and the compiler, instead of being pleased, slapped me with an error:

    "type com.svcon.jdbf.DBFRecord does not settings.

    So, just to prove the point, I tried:

    HashMap < String, Object > record = new HashMap < String, Object > ();

    and it worked perfectly (although of course it has messed up the rest of the royally program.)

    So, my question is this: how we declare a class of the child (if that's the right word) as she accepts the same parameters as the parent?
    public class DBFRecord extends HashMap {
    
    public class DBFRecord extends HashMap {
    
  • How to create a class and a pointer to the Panel

    Hi all

    I'm new to Flex.  I created a dynamic group that has three children, added to it. The three children are Hbox and Vbox or an Hbox. The first Hbox with a label that should be updated every minute. I tried using getChildrenAt and it works and it seems .as Hack I'm doing like getChildrenAt (0) as Hbox, I have more than one group of experts and all the Panel must be updated values. So is it possible. I could create a class and has a pointer on the Panel and a pointer to the label, which will be called every minute and on the change of the label in the front of this update

    Thanks in advance

    Barro

    OK yes I think I understand now look to examples.  First heres my custom panel ELEMENT.

    package

    {

    Import mx.containers.Panel;

    Import mx.controls.Label;

    SerializableAttribute public class MyPanel extends Panel

    {

    private var _labelValue:String

    private var labelSet:Boolean;

    private var myLabel:Label;

    public void MyPanel()

    {

    Super();

    }

    public function set {labelValue(value:String):void}

    _labelValue = value;

    labelSet = true;

    invalidateProperties();

    invalidateSize();

    }

    public function get labelValue (): String {}

    Return _labelValue;

    }

    override protected function createChildren() (): void {}

    super.createChildren ();

    myLabel = new Sun;

    addChild (myLabel);

    }

    override protected function commitProperties (): void {}

    super.commitProperties ();

    If {(labelSet)

    MyLabel.set_Text = _labelValue;

    labelSet = false;

    }

    }

    }

    }

    Pretty basic it creates a tag in the Panel.  Opinion, he still has the labelValue public property which, when set, sets the text in the label.

    Now for the main application

    <>

    "xmlns:MX ="http://www.adobe.com/2006/mxml"

    Layout = "vertical" width = "100%" height = "100%".

    creationComplete = "createPanels ()" > "

    Used to store references to the panels when you create

    private var panelReferences:Array;

    My replacement for xml, but will work the same way.

    private var myData:Array = new Array)

    {panelName: "Group 1"},

    {panelName: "group 2"},

    ({panelName: "Group 3"});

    Look in the table (your XML and create panels

    private function createPanels (): void {}

    panelReferences = new Array();

    Create panesl and add on demand

    for (var i: int = 0; i

    var mPanel:MyPanel = new MyPanel();

    mPanel.labelValue = myData [i] .panelName;

    mPanel.width = 100;

    mPanel.height = 70;

    Add the panels also in the table of references

    panelReferences.push (mPanel);

    addChild (mPanel);

    }

    }

    private function changePanelHandler (): void {}

    Change the label of panels in the panelReferences table.

    Target group by using the index number

    panelReferences [ns.value] .labelValue = newLabel.text;

    }

    ]]>

    It loops through the data in the table that is the source for the panels.  As he does and creates a new Panel, it adds to the application, but also the reference to the panelReferences table.  Now in the demo app every time you want to set the value, you just do it on the reference in the references table and so it's a pointer property labelValue Panel Gets the value, and then updates the text in the Panel.

    I think that this covers what you want.

    With regard to the interfaces.  Tell everyone your signs accepts different types of data (they are all channels) and implemented the data in different ways.  Her you would use one interface.  This would ensure all panels used consistantly Sami methods, but might implement these different ways.

    I hope this helps

    Andrew

  • Best way to insert data into instances of the custom class

    Hello.

    I have created a custom class (mySuperClass) in an .as file, defined constructor methods, properties, and the get/set. Now in the main .fla I must declare a large number of instances of this class and complete each property. The 'proper' method, I guess, would be to:

    var super1:mySuperClass = new SuperClass();
    super1.setProperty1 ( value1_1);
    super1.setProperty2 ( value1_2);
    ...
    super1.setPropertyN ( value1_N);

    ...
    var superM:mySuperClass = new SuperClass();
    superM.setProperty1 ( valueM_1);
    ...
    superM.setProperty1 ( valueM_N);

    However, with large quantities of variables and information that share the same basic characteristics, I feel always attempted to do through a cycle of dethrone. In that case, I'd probably build tables with the properties to complete.

    So I want to know is how would you guys do it? Are there other ways to do it?

    Thanks in advance.

    Well, the example is based on an object that has a datamodel and which can be any object of course. Now, assuming that the data come Let's say an xml file, I would use a function as the code to generate a collection of objects.
    Edit: so the StoreItem instances are created on the fly and saved in the collection

  • How to add a custom class to the Style OBIEE worksheet

    Hi all

    http://gerardnico.com/wiki/dat/OBIEE/presentation_service/obiee_string_number_in_one_column

    I tried the CSS custom class with conditional formatting for my requirement given below according to the steps given in the link above

    Article AmoundSold
    ____ __________________________

    Fa__ the value is greater then: 1000
    Axe_ value is less then: 500
    Dove of the value exceeds then: 1000

    but this is not a job

    Kind regards
    Selva

    There is a good chance that the javascript solution does not work but its worth by train. It is a workaround in html to the question of the pseudo-element with IE.

    In article (http://gerardnico.com/wiki/dat/obiee/presentation_service/obiee_string_number_in_one_column), he said that you add conditional formatting to the column in your table. Did you do that. In the field of the 'use Custom CSS Class' make sure that the text matches exactly this in javascript.

    In the example, text = 'ClassIsGreater' and in my javascript, method decorateElement, text = "ClassIsGreater" so that they match.

    Then we add javascript code in a static text field. My concern is that the script will apply to the static text field and not to the rest of the html page. If we can't get the script to apply to the entire page so it's a non-starter and we admit defeat.

Maybe you are looking for