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

2013/10/23

Need an object fixed to the screen, not the map.

1
2
3
4
Tavi Tavi

2013/10/25

#
Tavi wrote...
I've made a short video guys :) i thought that would be best !! When i start the game, you can see the platforms match my background , but when i move... the background "skips" and all my game is messed up .. I Can also fall out of my screen :( If you guy's like the video to explain problems, i'd be glad to use it more often :) Thanks in advance :)
Tavi wrote...
I've made a short video guys :) i thought that would be best !! When i start the game, you can see the platforms match my background , but when i move... the background "skips" and all my game is messed up .. I Can also fall out of my screen :( If you guy's like the video to explain problems, i'd be glad to use it more often :) Thanks in advance :)
Tavi Tavi

2013/10/25

#
Tavi wrote...
Here's the video , can't seem to post it
Tavi Tavi

2013/10/25

#
http://www.youtube.com/watch?v=1lwB_3jpKYs
Tavi Tavi

2013/10/25

#
Anyone ?
danpost danpost

2013/10/25

#
If the re-drawing of the background while scrolling does not completely fill the window, you will end up getting a 'smeared' effect along the edge not being drawn on. Is that what you are getting?
Tavi Tavi

2013/10/25

#
That's one of the issues in some of the maps yeah, but my biggest issue is shown here : http://www.youtube.com/watch?v=1lwB_3jpKYs When i start the game, you can see the platforms match my background , but when i move... the background "skips" and all my game is messed up .. I Can also fall out of my screen :(
danpost danpost

2013/10/25

#
I could not say what is causing the 'skips'. But you need to add code to your main character to detect the bottom edge of the world and restart the level or something when your character is at that edge.
SPower SPower

2013/10/26

#
Well, the actors seem to behave quite properly, except for some small things. The problem with the background is caused due to the fact that my Scrolling World 'engine' was made to have a background smaller than the entire map, and repeat that. If you want a background with the size of the entire map, then you'll have to change something. I've already done this myself for some small, non-finished projects, and this is what you'll have to change:
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// all in ScrollWorld:
// under the constructor:
/**
     * Sets the background of the world. This will also initialize
     * everything to make the background scroll, something the
     * normal {@link setBackground} method doesn't.
     */
    public void setNewBackground(GreenfootImage background)
    {
        bigBackground.clear();
        if (background.getWidth() == bigBackground.getWidth() &&
            background.getHeight() == bigBackground.getHeight()) {
            bigBackground.drawImage(background, 0,0);
            back.clear();
            back.drawImage(bigBackground, scrollPosX,scrollPosY);
            return;
        }
         
        bigBackground.drawImage(background, 0,0);
        bigBackground.drawImage(background, background.getWidth(),0);
        bigBackground.drawImage(background, 0,background.getHeight());
        bigBackground.drawImage(background, background.getWidth(),background.getHeight());
         
        back.clear();
        back.drawImage(bigBackground, scrollPosX,scrollPosY);
    }
 
 
// at the bottom:
/**
     * All the honor for this goes to Busch2207 from
     * greenfoot.org
     */
    private void moveBackgroundUp(int amount)
    {
        if (amount == 0) return;
        int height = getHeight();
        scrollPosY -= amount;
        /*while (scrollPosY < 0)
            scrollPosY += height;
        scrollPosY %= height;*/
        if (scrollPosY < -fullHeight) {
            scrollPosY = -fullHeight;
        }
        getBackground().drawImage(bigBackground, scrollPosX,scrollPosY);
    }
     
    /**
     * All the honor for this goes to Busch2207 from
     * greenfoot.org
     */
    private void moveBackgroundRight(int amount)
    {
        if (amount == 0) return;
        int width = getWidth();
        scrollPosX -= amount;
        /*while (scrollPosX < 0)
            scrollPosX += width;
        scrollPosX %= width;*/
        if (scrollPosX < -fullWidth) {
            scrollPosX = -fullWidth;
        }
        getBackground().drawImage(bigBackground, scrollPosX,scrollPosY);
    }
Try that out, and tell me if that will work.
SPower SPower

2013/10/26

#
And change the camera movement code to this:
1
getWorld().setCameraLocation(getGlobalX(), getGlobalY());
which causes the camera to follow the player all the time.
SPower SPower

2013/10/27

#
Please forget the 'new' code about the camera movement: I realised it won't work.
Tavi Tavi

2013/10/27

#
Thank you so much :)!! Nearly solved my problems, just some minor issues now .. The background can shift left and right, but it wont shift up and down, which means if i want to go down(or up ), i still go out of my screen. another small issue is that i have to spawn my char at 0,0 , and that means i cannot walk to my left at the beginning, i could adjust the background images for this though.. so my only issue now is that my camera isnt moving up and down with my character. Also i hope my last video cleared things up, danpost and SPower you guys are real troopers, thanks for sticking with me on this issue, it's a tough one !
SPower SPower

2013/10/27

#
The problem that you can't walk left at the beginning is that the camera must always have it's viewport filled with the world's context: it can't move past the edges. So, it starts at the top left corner, but it's global x and y are half width and half height of the viewport. To be able to walk you need some more sophiticated code, I guess something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// new movement to the left:
if (getCameraX() == 0) { // if in the middle of the screen
    int cx = getWorld().getCameraX();
    getWorld().moveCamera(-MOVE_AMOUNT);
 
    // if the camera couldn't move:
    if (getWorld().getCameraX() == cx) {
        move(-MOVE_AMOUNT);
    }
} else {
    // not in the middle of the screen, so we need to move back to the middle
    // and don't move the camera
    move(-MOVE_AMOUNT);
}
// the same applies for moving to the right,
// but entering MOVE_AMOUNT instead of -MOVE_AMOUNT of course
this isn't tested (just made up), so beware its possible bugs.
Tavi Tavi

2013/10/27

#
Thanks :) I'm sure with a little tinkering i can make this work :) .. ( at this point it says "cannot find symbol - method getWorld() " ) The biggest issue however is making the camera move up and down (which it wont at this point) , or do i need to use thesame code for it and replacing X with Y ? EDIT : This code was tested in the class ScrollWorld !
SPower SPower

2013/10/27

#
Btw, the code was meant for a subclass of ScrollActor, probably that solves the error. And, watching at your video, the player already falls and the camera doesn't move (it can't go further), so what is wrong with that?
Tavi Tavi

2013/10/28

#
It now says Cannot find symbol - method getCameraX ( placed the code in my Rogue class, to act as a move left command).. This however, is a problem i could just fix with expanding my background, right ? The my biggest issue now is that my screen will move left and right, but not up and down. ( i should be able to climb and go higher, or jump a few platforms down )
There are more replies on the next page.
1
2
3
4