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

2014/5/7

Get an actor to change color

1
2
3
4
danpost danpost

2014/5/10

#
anonymousse wrote...
That worked thank you. If I would change the dimensions to 'super(24, 24, 25), would that mean that my cells are in a dimension of 25 then?
Yes. The third number is the cellsize.
anonymousse anonymousse

2014/5/10

#
My arrow isn't lining up exactly with the blank tile. It is a little off. Would this just be because of my dimensions or my cell size?
danpost danpost

2014/5/10

#
anonymousse wrote...
My arrow isn't lining up exactly with the blank tile. It is a little off. Would this just be because of my dimensions or my cell size?
It might be the images themselves. How about using these:
1
2
super(8, 8, 125);
for (int y=0; y<8; y++) for (int x=0; x<8; x++)
anonymousse anonymousse

2014/5/11

#
That worked great thank you! Why is it that it works better though? 8 by 8 refers to the width and height in the number of cells. And if 125 is the cell size how are they still the same size and map with the other set? Also, I am trying to get my arrow to move and I added a public void move but this hasn't worked. Is there a different command I should use instead?
danpost danpost

2014/5/11

#
anonymousse wrote...
Why is it that it works better though? 8 by 8 refers to the width and height in the number of cells. And if 125 is the cell size how are they still the same size and map with the other set?
No matter the cell size, 1x1, 5x5, 25x25, 125x125, or whatever (in pixels), greenfoot always places the actors in the centermost pixel of the cell. So with (200, 200, 5) you had 40000 cells arranged in a square of 200x200 cells where each cell was 5x5 pixels in size. The world in total is 1000x1000 pixels in size. By using (8, 8, 125) we have 64 cells arranged in a square of 8x8 cells where each cell is 125x125 pixels in size; making up a world, still, of size 1000x1000 pixels. We basically eliminated all the possible cells that your actor was not allowed to go anyway.
Also, I am trying to get my arrow to move and I added a public void move but this hasn't worked. Is there a different command I should use instead?
If you add a 'public void move' method you will still need a 'public void act' method to call it with (otherwise it will never get executed).
anonymousse anonymousse

2014/5/11

#
Oh ok. I executed the following code based on the original crab tutorial:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public void act() {
         
        move();
    }
 
 
public void move()
    {
        move(0);
         
        if (Greenfoot.isKeyDown("left"))
        {
            move(-1);
        }
        if (Greenfoot.isKeyDown("right"))
        {
            move(1);
        }//
         
        setRotation(90); 
if (Greenfoot.isKeyDown("up")) 
  { move(-1); } 
if (Greenfoot.isKeyDown("down")) 
  { move(1); } 
setRotation(0); 
    }
 
 
}
But my arrow just goes straight to the edge of the world. How do I limit the movement to just in between tiles then?
danpost danpost

2014/5/11

#
anonymousse wrote...
But my arrow just goes straight to the edge of the world. How do I limit the movement to just in between tiles then?
This is what you posted previously:
For movement, there are little borders of white between tiles. I would like for the arrow to not be between tiles but only on top of tiles which are then eaten.
Everything since that post was based on that statement. Maybe you did not mean what you had written; but, read what is says (and go back and check it out, if you must).
anonymousse anonymousse

2014/5/11

#
I guess I wrote it wrong, my apologies. My game has 64 tiles and an arrow. The arrow can go to other tiles in its proximity and when the arrow on the keyboard is pressed once, I wanted it to move only once. But is there a way to just define movement in terms of the size of each tile all the while not changing too many other things?
danpost danpost

2014/5/11

#
anonymousse wrote...
is there a way to just define movement in terms of the size of each tile all the while not changing too many other things?
What size are your tiles?
anonymousse anonymousse

2014/5/11

#
The actual tiles are 100 by 100 pixels. Although here each cell is 125 pixels so that there is space between them.
danpost danpost

2014/5/11

#
And what size are the arrow images?
anonymousse anonymousse

2014/5/11

#
The arrow is also 100 by 100 pixels originally.
danpost danpost

2014/5/11

#
Wow. If the arrow was to be able to go between the tiles and both are 100x100, you would need a world 1700x1700 pixels big. That is huge! But, your original world was 1000x1000; so, how did you think to do this then?
anonymousse anonymousse

2014/5/11

#
I tried resizing the arrow tile to half it's size but that won't do anything. I also tried using super(17,17,100) but the movement is still jerky and inconsistent, sometimes moving to the ends, sometimes to a few tiles away. I'm kind of confused as to why it's moving like that since I was assuming if the tiles fit fine the movement would be consistent.
danpost danpost

2014/5/11

#
If you want the arrow to move once per press of an arrow key, then you should be using 'getKey' instead of 'isKeyDown':
1
2
3
4
5
6
7
8
9
10
11
public void move()
{
    String key = Greenfoot.getKey();
    int dx = 0, dy = 0; // the offsets from current location
    if ("up".equals(key)) dy--;
    if ("down".equals(key)) dy++;
    if ("left".equals(key)) dx--;
    if ("right".equals(key)) dx++;
    setLocation(getX()+dx, getY()+dy);
    // check for illegal movement here and reset location adding negative offsets
}
There are more replies on the next page.
1
2
3
4