logo
down
shadow

Move the circle in as3


Move the circle in as3

Content Index :

Move the circle in as3
Tag : actionscript-3 , By : ZsA
Date : November 23 2020, 12:01 PM

With these it helps I already have the graphic with image on the screen and I wanted to it to move when I pressed the arrows on keyboard. , You need to add it to stage like so,
stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
public function GameManager():void 
{
      addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

private function onAddedToStage(e:Event):void
{
      circle = new Sprite();
      imgLoader = new Loader();
      imgLoader.load(new URLRequest("../lib/fira_front.png"));
      imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, drawImage);
      stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); //This line is modified

      removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

Make circle and then move circle on mouse dragged event


Tag : java , By : Gazza
Date : March 29 2020, 07:55 AM
it helps some times How to draw circle on mouse dragged event, and then how to move that circle on mouse dragged event in Java? , Something along those lines works nicely for me:
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.geom.Ellipse2D;

import javax.swing.JFrame;
import javax.swing.JPanel;

class DragCircle extends JPanel {

    private final class MouseDrag extends MouseAdapter {
        private boolean dragging = false;
        private Point last;

        @Override
        public void mousePressed(MouseEvent m) {
            last = m.getPoint();
            dragging = isInsideEllipse(last);
            if (!dragging) {
                x = last.x;
                y = last.y;
                width = 0;
                height = 0;
            }
            repaint();
        }

        @Override
        public void mouseReleased(MouseEvent m) {
            last = null;
            dragging = false;
            repaint();
        }

        @Override
        public void mouseDragged(MouseEvent m) {
            int dx = m.getX() - last.x;
            int dy = m.getY() - last.y;
            if (dragging) {
                x += dx;
                y += dy;
            } else {
                width += dx;
                height += dy;
            }
            last = m.getPoint();
            repaint();
        }
    }

    private int x;
    private int y;
    private int width;
    private int height;

    private MouseDrag mouseDrag;

    public DragCircle() {
        setBackground(Color.WHITE);
        mouseDrag = new MouseDrag();
        addMouseListener(mouseDrag);
        addMouseMotionListener(mouseDrag);
    }

    public boolean isInsideEllipse(Point point) {
        return new Ellipse2D.Float(x, y, width, height).contains(point);
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawOval(x, y, width, height);
    }

    public static void main(String[] args) {
        JFrame jFrame = new JFrame();
        jFrame.setSize(300, 300);
        jFrame.add(new DragCircle());
        jFrame.setVisible(true);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

Wanted to make an object bounce inside a circle, ended up making the object move along the rim of the circle


Tag : java , By : Heals1ic
Date : March 29 2020, 07:55 AM
it should still fix some issue This is what I've got, and I'm going to share my findings to all of you.
public void calculate() {
    // Center of circle is at (250, 250). Radius is 40.
    //THIS ALGORITHM IS PROVEN TO BE BETTER THAN I FEARED...

    /*      What it does:
     *          Moves object around in a circle, if object is 
     *              inside of circle.
     *          Does not move the object towards the center, 
     *              nor outwards. This is crucial.
     *          Object always stays on the rim of the circle, 
     *              if the collision detection allows it to.
     * 
     *      Algorithm I used. (DOES WORK, NOT EXPECTING THIS THOUGH.):
     *          N is normalized vector. 
     *          R = -2*(V dot N)*N + V
     */



    double nx = x - 250;
    double ny = y - 250;
    double nd = Math.hypot(nx, ny);
    if (nd < 40){
        vx += Accelero.X * 0.1;
        vy += Accelero.Y * 0.1;
        x -= vx;
        y -= vy;
        vx *= 0.9;
        vy *= 0.9;
        return;
    }

    vx += Accelero.X * 0.1;
    vy += Accelero.Y * 0.1;


    if (nd == 0)
        nd = 1;
    nx /= nd;
    ny /= nd;
    double dotProduct = vx * nx + vy * ny;
    vx += (float) (-2 * dotProduct * nx);
    vy += (float) (-2 * dotProduct * ny);
    x -= vx * 2;
    y -= vy * 2;
    vx *= 0.99;
    vy *= 0.99;
}

Multiple animations in Raphael (move line and circle plus transform the circle)


Tag : javascript , By : Hadley
Date : March 29 2020, 07:55 AM
Any of those help As there seems no possibility to run multiple animations at once in raphael, you are probably forced to cut your animation into pieces. this is not an elegant solution, but the result might be what you want to achieve.
fiddle: http://jsfiddle.net/75ZFU/
var paper = Raphael(0, 0, 500, 500);
var circle = paper.circle(8, 8, 1).attr({ stroke: '#fff', fill: '#f00' });

var anim1 = Raphael.animation({ transform: "s3 T 33,33"}, 500, "linear", function() {         circle.transform("s1 T 33,33").animate(anim2)});
var anim2 = Raphael.animation({ transform: "s3 T 66,66"}, 500, "linear", function() {     circle.transform("s1 T 66,66").animate(anim3)});  
var anim3 = Raphael.animation({ transform: "s3 T 100,100"}, 500, "linear", function() { circle.transform("s1 T 0,0").animate(anim1)});
circle.animate(anim1);

var line = paper.path('M 0,8 l 5,0 M 8,0 l 0,5 M 11,8 l 5,0 M 8,11 l 0,5 z');
line.attr('stroke', 'red');

var anim4 = Raphael.animation({ transform: "T 33, 33 R 120"}, 500, "linear", function() { line.transform("T 33, 33 R 120").animateWith(circle, anim2, anim5)});
var anim5 = Raphael.animation({ transform: "T 66, 66 R 240"}, 500, "linear", function() { line.transform("T 66, 66 R 240").animateWith(circle, anim3, anim6)});
var anim6 = Raphael.animation({ transform: "T 100, 100 R 360"}, 500, "linear", function() { line.transform("T 0, 0 R 0").animateWith(circle, anim1, anim4)});
line.animateWith(circle, anim1, anim4);

Objective c - Move Small Circle inside a larger Circle


Tag : ios , By : Vitalik
Date : March 29 2020, 07:55 AM
seems to work fine Larme thank you, the small circle inside the large circle is working now:
-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
        if (isJoystickToggle) {


        CGPoint location = [touch locationInView: [touch view]];
        location = [[CCDirector sharedDirector] convertToGL:location];

        float posY = joystickContainer.position.y;
        float posX = joystickContainer.position.x;
        float y = location.y;
        float x = location.x;

        double dx = (x-posX);
        double dy = (y-posY);
        double dist = sqrt(dx*dx + dy*dy);

        NSLog(@"%f",dist);

        if (dist < 60) {

            joystickToggle.position = location;

        }

        if(dist >= 60){
            float angle = atan2f( y - posY , x - posX);

            float newx = (cos(angle) * 60) + posX;
            float newy = (sin(angle) * 60) + posY;

            location = ccp(newx, newy);
            joystickToggle.position = location;

        }

        }
    }

D3js, circle inside a circle (arc), unable to move inner circle using cx and cy


Tag : javascript , By : hlpimfalling
Date : March 29 2020, 07:55 AM
this one helps. So, I found the problem. It was actually inheriting the parent's position. If you check the index.html there is a part where it is setting the circle's position (all the classes). So, I added the attribute class to the children circles and now I just need to add the position specifying the class:
d3.selectAll("circle.children").attr("cx", function (d) {
                        return d.x;
                    })
                    .attr("cy", function (d) {
                        return d.y;
                    });
shadow
Privacy Policy - Terms - Contact Us © scrbit.com