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

2013/12/18

Hot to get the screen track the object?

Victor0409 Victor0409

2013/12/18

#
Can anyone help me with suggestions for how to get the object in the center of the screen if you have a world of 5000 x 5000 pixels?
MikeItOrNot69 MikeItOrNot69

2013/12/18

#
You can put addObject( new your object(), 2500, 2500); in the world class under the Act() method
danpost danpost

2013/12/18

#
1
addObject(objectReference, getWidth()/2, getHeight()/2);
'getWidth' and 'getHeight' will return the width and height of the screen whatever the size is. Taking half of those values will always get the coordinates of the center of the screen. This is presuming your cell size is one.
Victor0409 Victor0409

2013/12/19

#
I know how to place an object in the centre but I mean that your vieuwing window is like 600 x 600 pixels. and that your vieuwing window stays600 x 600 but it moves over the world
danpost danpost

2013/12/19

#
Background information that may be required are: (1) the bounded state of the world (are you using 'super(int, int, int, false);' in world constructor) (2) the value of the scrolled amount ( zero or '(scrollWidth-worldWidth)/2' or something else ) If (1) unbounded and (2) zero, then the line that MikeItOrNot69 suggested will work; however, that line should not be placed in the 'act' method; instead, it should go in the world constructor or a method it calls (like 'prepare').
Victor0409 Victor0409

2013/12/23

#
I understand how I have to put in an object but I’m asking how I create the scrolling affect that follows the character?
danpost danpost

2013/12/23

#
Using horizontal and vertical offset fields to track and control the amount of scrolling of the background image, you can code in the world class act a scrolling system that constantly returns the character to the center of the screen, moving all the scrollable actors and the background the same way (basically shifting everything in your world to keep your character in the center).
Victor0409 Victor0409

2013/12/23

#
But can’t it be done more easily than „creating” the world every time you take a step?
danpost danpost

2013/12/23

#
Victor0409 wrote...
But can’t it be done more easily than „creating” the world every time you take a step?
If 'creating' the world means updating the background image of the world and moving all the scrollable actors in the world, then, not really.
Victor0409 Victor0409

2013/12/23

#
okay and there is no other way?
danpost danpost

2013/12/23

#
If you can think of one, please let me know!
Victor0409 Victor0409

2013/12/23

#
I will
Victor0409 Victor0409

2013/12/23

#
Well if anyone can tell me how to create a window that is smaller than the world? Than I can probably find an solution
You need to login to post a reply.