android - Indeterminate Number of Falling Images...Display on SurfaceView HELP! -


I think I have hit a coder block here. I am writing a game where several times the pictures from the top of the screen Will be dropped and you have to catch them on the bottom. There will be an indefinite number of images, so you do not know how much will be on start time. For my life I can not understand the way to apply it. I understand the logic, but there is a problem in trucking through the orbids of Android. I tried to make my own "blossom" object, but every time I try to write anything with a bitmap inside it, then it goes out. Maybe I'm just writing the class incorrectly, I do not know. All this is being done on a SurfaceView, is there anybody who has any idea how to complete it? So my code is so far:

  The public class assigns BoardView SurfaceView SurfaceHolder.Callback {Context mContext; Bitmap Box = (Bitmapfinterator.dtd Datasource (getResources (), R.drawable.box)); Bitmap flower = (bitmapfichter.decources (), RDRYable Blossom)); Private board thread thread; Private boat box_x = 140; Private boat box_y = 378; Private float blossom_x = 0; Private float blossom_y = 0; Private flat boxwidth = box .getWidth (); Private float boxhigh = box.gethit (); Private float blossom with = blossom.jet wideth (); Private Float Blossom Heights = Blossom.GateHight (); Private random generator = new random (); Boolean mode = false; Rectifty Boxtrack = New Rectum (box_x, box_a, box_x + boxwidth, box_a + box-height); // Image View Box_View; Public Boardview (Reference Reference) {Super (Reference); // Surfaceholder provides canvas which we draw on getHolder (). AddClallback (this); // Control Dogs Thread = New BoardTrade (Together Holder (), this); // A random starting point pulls blossom on blossom_x = generator.nextInt (300); // box_view = (ImageView) findViewById (R.id.box_view); //box_view.setVisibility (ImageView.VISIBLE); / Translation animation animation = new translation animation (0,0,300,0); //anim.setDuration(500); //box_view.startAnimation(anim); // Touchscreen Touch Events Set Focusable (True); } @ Override Public Wide On Draw (Canvas Canvas) {Canvas Drey Color (Color. WHITE); // Set the Draw Box and Start Location canvas.drawBitmap (box, box_x - (boxwidth / 2), box_e - (box-hit / 2), tap); Canvas.drawBitmap (blossom, blosom_x, blosom_yy = blossom + 3 +, empty); // Detection of confrontation, currently is not working after // random execution if (blossom_y + blossomHeight == box_y) {canvas.drawBitmap (blossom, 40,100, empty); }} Override public boolean on touch event {if (event.getAction () == MotionEvent.ACTION_DOWN} {if (boxRect.contains (event.getX), event.getY ())) {mode = True; }} If (event.getAction () == MotionEvent.ACTION_MOVE) {if (boxRect.contains (event.getX), event.getY ())) {mode = true; } If (mode == true) {box_x = (int) event.getX (); Boxcrack.set (box_x, box_a, box_x + boxwidth, box_a + box-height); }} If (event.getAction () == MotionEvent.ACTION_UP} {mode = false; } Invalid (); Back true; } @ Override Public Wide Successful Changed (Surface holder holder, int format, int width, intensity height) {} @ Override made public void successful (Surfal holder holder) {thread. Starting (true); Thread.start (); } @ Override public nil surface was destroyed (ground holder holder) {thread.startRunning (wrong); Thread.stop (); }}   

I am currently using a bitmap to attract falling flowers. Instead, I started making a class for the object of flowers, which looks like this so far

  blossoming of public squares {private bitmap blossom; Public Blossom (bit) {bitmap blossom = (bitmapfactory.dicoodeResource (getResources (), R.drawable.blossom)); } Public Zero Setizes (bitmap bitmap) {// sets image for blues; Bitmap flower = bitmap; }}   

This is giving me an error telling me the resources is mandatory for the Blossom class. When I try to write a method named setImage, and setting the image in the board weave class, then he will not give me at all :( It looks like something

  public class buys { Private bitmap blossom; Public Zero set image (bitmap bitmap) sets the image to // // Blosom; bitmap blossom = bitmap;}} Can anyone see what's going wrong here? < "post-text "Itemprop =" text "> 

Since your class SurfaceView increases , getContext) .getResources ()

edit - If you use getResources in your second category If you want, you also get a context as well. Instead, instead of trying to bring your code from that data class, you can pass in your bitmap .

Comments

Popular posts from this blog

qt - switch/case statement in C++ with a QString type -

python - sqlite3.OperationalError: near "REFERENCES": syntax error - foreign key creating -

Python's equivalent for Ruby's define_method? -