2017년 8월 23일 수요일

Rectangle extension.


I just wonder, is it possible to create a rectangle extension in AI2?  Can one modify the ball.java file, and based on that create a rectangle instead?
Is this a complicated thing to do?

From the ball.java code:

protected void onDraw(Canvas canvas) {
    if (visible) {
      float correctedXLeft = (float)(xLeft * form.deviceDensity());
      float correctedYTop =  (float)(yTop * form.deviceDensity());
      float correctedRadius = radius * form.deviceDensity();
      canvas.drawCircle(correctedXLeft + correctedRadius, correctedYTop +
          correctedRadius, correctedRadius, paint);
    }
  }

Is there any kind of canvas.drawRectangle?

--
Next time search the gallery:



--
So I know I haven't explained exactly what I want.  To create a function like this is no probelm (that I've already done)

But I want to add events to my rectangle.  For the ball component you have:

When ball1 collide with

When ball1 dragged
When  ball1 edge reached
when ball1 flung
when ball1 toucdown

and so on.  I don't think thats possible with this solution?

--
A ball is really a sprite, so, you can make a sprite with the image of a rectangle, give it any width and height you need, since pixelation or distortion doesn't matter in this case and that's it. You have a "rectangular ball"!

--
But isn't your rectangle just a Sprite with a very boring rectangular image?

--
Sure, one can use an image of a rectangle.  So if one would change the colour of this rectangle, you have to add a new image.  
Ok, thats a workable solution, but not the most elegant......

--
You can draw a rectangle of any color possible, save the canvas as a file, then use that file as the sprite picture.

--
Not sure how to save a canvas..... BUT: I have created 2 images (png) with size 100X100 px.  And I am able to change picture and then colour of the rectnagle!!
If I change height  or wdith of the imagesprite it will work as long as it is less than 100X100px.  Thanks for your adivse,  I guess this is much easier than creating an extension:)

--

댓글 없음:

댓글 쓰기