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

2018/2/7

Play charater idle animation if there aren't any keys pressed

1
2
3
4
5
6
7
LaurentiuRohan LaurentiuRohan

2018/2/18

#
Yeat, it works, I've added setPaintOrder(Puppy_Player.class); in another void, there it was the problem, thanks anyway. Now I have problem with building the levels. How can i set corectly actors postions if there is that biggest sidescrooling world. I've tried like in mario sidescrooling scenario to divide the world in 10 eqauls parts. Starting area , areatwo, areathree....endingArea like in Mace_Level, and I taught that every part will represent one part that have scrolled. For example If my world is 960 areaTwo will start from 960 to 1920, but when I add an element after i scroll manualy the world and click inspect on it shows to me that object is located >960, so I've added the object in the areaTwo, but goes to the startingArea coordinates For example the last object added in areaTwo goes to startingArea:
private void buildWorld()
    {
        startingArea();
        areaTwo();
        areaThree();
        areaFour();
        areaFive();
        areaSix();
        areaSeven();
        areaEight();
        areaNine();
        endingArea();
        addScoreboard();
        
    }
    
    private void startingArea()
    {
        addObject(new Long_Grass1(),237,551);
        addObject(new Grass_Normal_Left(),320,498);
        addObject(new Grass_Normal_Left(),379,442);
        addObject(new Grass_Normal_Center(),438,442);
        addObject(new Ground_Center(),320,557);
        addObject(new Ground_Center(),379,557);
        addObject(new Ground_Center(),379,499);
        addObject(new Ground_Right(),439,499);
        addObject(new Ground_Right(),439,557);
        addObject(new Water(),596,518);
        addObject(new Water(),849,518);
        addObject(new Coin(),123,495);
        addObject(new Coin(),177,495);
        addObject(new Coin(),232,495);
        addObject(new Coin(),325,444);
        addObject(new Coin(),415,386);
        addObject(new Grass_Normal_Left(),560,368);
        addObject(new Grass_Normal_Left(),681,308);
        addObject(new Grass_Normal_Left(),802,258);
        addObject(new Grass_Normal_Right(),923,184);

        
    }
    
    private void areaTwo()
    {

        addObject(new Long_Grass1(),719,184);
    }
    
    private void areaThree()
    {
    }
I'm a little bit confused, and probably you will don't understandwhat I want to say, I just want to know how to add easily actors and desired position to my big 9600px scrolling worlds.
danpost danpost

2018/2/18

#
I will presume that grounds will be at different heights (which is more difficult to program). When ground level can be at different heights, one cannot easily determine at what y-coordinate the player will be when making contact with it. Therefore, an adjustment in the y-coordinate of the player needs to be made when making contact with the ground object. In your case, it might be best to use half the height of both the player and the ground object as the separation and then drop the player one pixel to intersect the ground, without the added drop in location, the player will probably bobble on the ground.
LaurentiuRohan LaurentiuRohan

2018/2/18

#
danpost wrote...
I will presume that grounds will be at different heights (which is more difficult to program). When ground level can be at different heights, one cannot easily determine at what y-coordinate the player will be when making contact with it. Therefore, an adjustment in the y-coordinate of the player needs to be made when making contact with the ground object. In your case, it might be best to use half the height of both the player and the ground object as the separation and then drop the player one pixel to intersect the ground, without the added drop in location, the player will probably bobble on the ground.
Solved this one danpost, and thanks a lot, but please take a look at what I've said upper, thanks!
danpost danpost

2018/2/18

#
Since you are only side-scrolling, only the x-coordinate values need adjusting. I think you have to take into account the 'scrolledX' value. Use the 'getScrolledX()' method to get its value and subtract it from the x-coordinate you originally were placing the AreaTwo objects at. If subtracting did not work correctly, try adding instead.
LaurentiuRohan LaurentiuRohan

2018/2/18

#
danpost wrote...
Since you are only side-scrolling, only the x-coordinate values need adjusting. I think you have to take into account the 'scrolledX' value. Use the 'getScrolledX()' method to get its value and subtract it from the x-coordinate you originally were placing the AreaTwo objects at. If subtracting did not work correctly, try adding instead.
Aaa, I don't understant If I press right click on the actor and inspect, says that ScroolledX() is 0..
danpost danpost

2018/2/18

#
LaurentiuRohan wrote...
If I press right click on the actor and inspect, says that ScroolledX() is 0..
Okay. Try just adding 960 to the x-coordinate to AreaTwo actor locations. If that works, then add 960 times one less than the area number for all objects in all areas
LaurentiuRohan LaurentiuRohan

2018/2/18

#
danpost wrote...
LaurentiuRohan wrote...
If I press right click on the actor and inspect, says that ScroolledX() is 0..
Okay. Try just adding 960 to the x-coordinate to AreaTwo actor locations. If that works, then add 960 times one less than the area number for all objects in all areas
Doesn't works, they don't go where I want, and if this would work it would take a lot of time for adding objects into 8 worlds with 9600 width. You don't have any ideea why getScrolledX doesen't works.? I don't know how that guy took the coordinates for mariosidescroller, his game worlds are bigger too, like 6000-7000px...
danpost danpost

2018/2/18

#
LaurentiuRohan wrote...
Doesn't works, they don't go where I want, and if this would work it would take a lot of time for adding objects into 8 worlds with 9600 width. You don't have any ideea why getScrolledX doesen't works.? I don't know how that guy took the coordinates for mariosidescroller, his game worlds are bigger too, like 6000-7000px...
If your horizontal scrolled amount is zero, then you should be able to place your object exactly where you want them. Maybe should should explain like exactly where it ends up, not being (719,184).
LaurentiuRohan LaurentiuRohan

2018/2/18

#
danpost wrote...
LaurentiuRohan wrote...
Doesn't works, they don't go where I want, and if this would work it would take a lot of time for adding objects into 8 worlds with 9600 width. You don't have any ideea why getScrolledX doesen't works.? I don't know how that guy took the coordinates for mariosidescroller, his game worlds are bigger too, like 6000-7000px...
If your horizontal scrolled amount is zero, then you should be able to place your object exactly where you want them. Maybe should should explain like exactly where it ends up, not being (719,184).
Oh, sory, the scrolledX is working, I was pressing right click on obj and not on background... but I still understand how should I add them like you've said upper to substract. For example scrolledX is now 1006, ,that means areaTwo, how am I supposed now to add an object to areaTwo at (344,518) coordinates ?
danpost danpost

2018/2/18

#
LaurentiuRohan wrote...
how am I supposed now to add an object to areaTwo at (344,518) coordinates ?
Add it exactly where you want it on the screen (as shown) at that point.
LaurentiuRohan LaurentiuRohan

2018/2/18

#
danpost wrote...
LaurentiuRohan wrote...
how am I supposed now to add an object to areaTwo at (344,518) coordinates ?
Add it exactly where you want it on the screen (as shown) at that point.
So I added but goes to area one coordinate, I've to use scrooledX in public void when I add them?
private void areaTwo()
    {
        addObject(new Water(),344,518)
}
danpost danpost

2018/2/18

#
Try using:
addObject(new Water(), 1304-getScrolledX(), 518);
or something like that.
LaurentiuRohan LaurentiuRohan

2018/2/19

#
danpost wrote...
Try using:
addObject(new Water(), 1304-getScrolledX(), 518);
or something like that.
Thanks a lot danpost, I found the solution with your help! Now I have another question if would you like to answer please. I want to add enemies on my world, but I want that to make different things in world if one actors is spawned 10 or more time in one world, for example : I want that Mace enemy get spawned 10 times is my world, if he is at the start of the world I just want that him to move randomly to x and y axis, but if he is between area 3 and 6 I want him to shoot something. How can I do that, use scrolledX in act method of the actor?
danpost danpost

2018/2/19

#
LaurentiuRohan wrote...
How can I do that, use scrolledX in act method of the actor?
You can. Get the value as follows:
int scrolledX = ((Scrooling_Worlds)getWorld()).getScrolledX();
LaurentiuRohan LaurentiuRohan

2018/2/20

#
danpost wrote...
LaurentiuRohan wrote...
How can I do that, use scrolledX in act method of the actor?
You can. Get the value as follows:
int scrolledX = ((Scrooling_Worlds)getWorld()).getScrolledX();
So how could I do that, for example I have Mace Enemi, and if he is added after scrool <6000 I want him move faster (-3), how should I edit the code ?
import greenfoot.*;
import java.util.List;
import java.util.ArrayList;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Mace here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Mace extends Enemies
{
    int steps = 3;
    int direction = 1;
    /**
     * Act - do whatever the Mace wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
   
    
    public void act()
{
    if ((steps == 400 && direction == 1) || (steps == 1 && direction == -1))
    { // when set to move past either end
        direction = -direction; 
    }
    setLocation(getX()+direction,getY()); 
    steps = steps + direction; 

}
}
There are more replies on the next page.
1
2
3
4
5
6
7