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

2014/8/8

How to do .. When you press the text or image transfer you to another world

Al7amed Al7amed

2014/8/8

#
What I mean is not to press any where in world
if (Greenfoot.mouseClicked(this)) 
        {  
            Greenfoot.setWorld(new World1());
        }
What I want like this game Mr Flap text and Image code please ..
danpost danpost

2014/8/8

#
The only difference between detecting clicks anywhere in the world and on a specific actor is what the keyword 'this' refers to. If coded in a subclass of World, it refers to a world object; if coded in an Actor subclass, it refers to an actor object. You do not have to use 'this', either. You can replace it with the object of choice. For example, if you created a button, like this (all code in World subclass):
// using instance field
Actor startButton = new Button("Start");
// in constructor
addObject(startButton, /* wherever */);
Then, in your act method, you could have this:
if (Greenfoot.mouseClicked(startButton)) // etc.
Super_Hippo Super_Hippo

2014/8/8

#
Like danpost said, those texts in my scenario are actors. If you don't want to have extra actors for this, you can alternatively check the position of the mouse when it is clicked and if it was in a specified area, you can count this as a click on the text and change the world, but it is easier to just place an object and check if it was clicked.
Al7amed Al7amed

2014/8/8

#
thank you I leared a lot from you guys .. What I will do is to save a text in photoshop but in jpg then actor.
You need to login to post a reply.