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

2014/11/18

can someone explain this code?

Erdrag1 Erdrag1

2014/11/18

#
if(getX() < 10 || getX() > getWorld().getWidth() - 10) return true; can someone explain this code in words, i know what it does, but what does the "<10" and "-10" mean? and the "getWorld and width" is that the world you play in?
Super_Hippo Super_Hippo

2014/11/18

#
It returns true if the x-coordinate of the actor is either smaller than 10 or greater than 10 subtracted from the width of the world (the actor is in right now). So in other words, if the actor is at a range of 10 of either the left or the right side of the world. The method 'getWorld' returns the world object in which the actor is right now (or null if it wasn't added or already removed from the world). 'getWidth' returns the width of the world, so the value which was added as the first parameter when creating the world (the x in 'super(x,y,cs)').
You need to login to post a reply.