This site requires JavaScript, please enable it in your browser!
Greenfoot back
myheartwillgoon
myheartwillgoon wrote ...

2012/11/28

A simple question! Please answer.

myheartwillgoon myheartwillgoon

2012/11/28

#
In my "Snake" class, in the constructor, my cods look like this:
public Snake(String segment, Color color)
    {
        this.segment=segment;
        direction= "right";
        speedX=speed=15;
        speedY=0;
        length=3;
        GreenfootImage image=new GreenfootImage(22,22);
        image.setColor(color);
        image.fillOval(0,0,22,22);
        setImage(image);
    }
And in my world class, inside the constructor, my codes look like this: public SnakeEarth() { // Create a new world with 600x400 cells with a cell size of 1x1 pixels. super(900, 550, 1); Greenfoot.setSpeed(35); snake=new Snake; snake=new Snake("head",color1); snake=new Snake(); snake=new Snake(); addObject(snake, 70, 60); addObject(snake, 49, 60); addObject(snake, 29, 60); addObject(new SnakeHunter(),81,227); addObject(new SnakeHunter(), 500, 230); addObject(new SnakeHunter(), 818, 435); } Okay my questions are about these 2 lines respectively in world and snake class: World(SnakeEarth) class: Greenfoot.setSpeed(35); Snake class: speedX=speed=15; I understand that the setSpeed method set the speed(35) of snake which will be the actual speed of snake. But, in the snake class, I have an another speed value (15). (1) . What does it do? I tried by changing that value, but it does nothing with the speed, where it just increases or decreases the distance between two body segments.
Gevater_Tod4711 Gevater_Tod4711

2012/11/28

#
Set speed doesn't set the speed of only one class but of whole Greenfoot. so if you say Greenfoot.setSpeed(35); and then Greenfoot.setSpeed(15); Greenfoot will only use the second of this values. Also in the botom right of greenfoot there is a scrollbar to set Greenfoots speed.
You need to login to post a reply.