Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (774)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Coordinates as middle point for circles  (Read 2366 times)
0 Members and 1 Guest are viewing this topic.
Offline kovacsa

Senior Newbie





« Posted 2014-12-05 07:34:48 »

I would like to draw circles to coordinates using them as middle points of the circles. batch.draw() put circles only "near" coordinates.
Offline Chequered

Senior Newbie


Medals: 1
Exp: 2 years


I could use a cup of Java.


« Reply #1 - Posted 2014-12-05 11:42:39 »

What kind of method are you using to draw the circles?
Offline kovacsa

Senior Newbie





« Reply #2 - Posted 2014-12-05 11:51:19 »

I have added image as a new Sprite.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SHC
« Reply #3 - Posted 2014-12-05 11:55:57 »

You need to give us more details, short questions are only going to get short answers, no offence. You need to say what library are you using, how you are tackling the problem, what the problem actually is, and also, if applicable you can show some screenshots showing the problem.

From your question, I found nothing in the above list, your question is unclear, and you didn't specify what library/engine you are using. What are you trying to achieve? And what is the problem?

Offline kovacsa

Senior Newbie





« Reply #4 - Posted 2014-12-05 13:18:36 »

So, a png, a circle is defined as a Sprite.
I draw it with batch.draw(), but this function is not uses the given coordinates as middle for the texture. So it doesn't put the sprite to right place. It should be draw exactly to end of lines.

Offline Springrbua
« Reply #5 - Posted 2014-12-05 13:39:30 »

I guess, you are using Libgdx right? 
Anyway, usualy the coordinate you give a "draw()" method are the lower left or upper left of the Texture. 
In your case it seems to be the lower left of the Texture. 
So in order to draw at the right place, you need to use some offset, which is (-Texture.width/2, -Texture.heigth/2). 
This "pushes" the Texture down and left by half of its width and heigth, so that the center is at the position, where the lower, left corner was originally.
Offline Chequered

Senior Newbie


Medals: 1
Exp: 2 years


I could use a cup of Java.


« Reply #6 - Posted 2014-12-05 14:47:35 »


So in order to draw at the right place, you need to use some offset, which is (-Texture.width/2, -Texture.heigth/2). 
This "pushes" the Texture down and left by half of its width and heigth, so that the center is at the position, where the lower, left corner was originally.

Yeah, this should do the trick for you.
Offline kovacsa

Senior Newbie





« Reply #7 - Posted 2014-12-05 19:12:36 »

Yes, I am using libgdx. I tried to use this so, but is not working:

1  
batch.draw(circle, p.x, p.y, 30, 30, -25, -25);


Quote
The method draw(Texture, float, float, int, int, int, int) in the type SpriteBatch is not applicable for the arguments (Sprite, int,
 int, int, int, int, int)
Offline MrPizzaCake

Senior Devvie


Medals: 8
Exp: 3 years


Hello, another wonderful human being :)


« Reply #8 - Posted 2014-12-05 19:23:02 »

Yes, I am using libgdx. I tried to use this so, but is not working:

*code*

Quote
The method draw(Texture, float, float, int, int, int, int) in the type SpriteBatch is not applicable for the arguments (Sprite, int,
 int, int, int, int, int)

Cast p.x and p.y to a float.

How am I? Tough question, since emotions are confusing as heck Tongue
Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #9 - Posted 2014-12-05 21:29:38 »

That won't fix it, since ints are implicitly cast to floats anyway.

That Batch method expects a Texture, but a Sprite is a TextureRegion. Try one of the Batch methods that takes a TextureRegion.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lcass
« Reply #10 - Posted 2014-12-05 21:33:33 »

Centre of a square object is width/2 height /2 , so to draw at the centre of the picture you would do draw(x - (width/2),y -(height.2));
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1865 views)
2018-06-10 19:43:48

EgonOlsen (1888 views)
2018-06-10 19:43:44

EgonOlsen (1256 views)
2018-06-10 19:43:20

DesertCoockie (1688 views)
2018-05-13 18:23:11

nelsongames (1357 views)
2018-04-24 18:15:36

nelsongames (1976 views)
2018-04-24 18:14:32

ivj94 (2743 views)
2018-03-24 14:47:39

ivj94 (1945 views)
2018-03-24 14:46:31

ivj94 (3036 views)
2018-03-24 14:43:53

Solater (1088 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!