Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Problem with scale.  (Read 214 times)
0 Members and 1 Guest are viewing this topic.
Offline SrFurias

Senior Newbie





« Posted 2013-06-15 14:29:02 »

I have a problem with scale in box2d and libgdx, I'm trying to put a image (sprite or texture or other, the case is dot I need put a image in a body) in a body, but the image don't show correctly.

When I run the game pass this:



My class:

BaseClass.java

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
145  
146  
147  
148  
149  
150  
151  
152  
153  
154  
155  
156  
157  
158  
159  
160  
161  
162  
163  
164  
165  
166  
167  
168  
169  
170  
171  
172  
173  
174  
175  
176  
177  
178  
179  
180  
181  
182  
183  
184  
185  
186  
187  
188  
189  
190  
191  
192  
193  
194  
195  
package com.unclain.serie2.a;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.CircleShape;
import com.badlogic.gdx.physics.box2d.Fixture;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.PolygonShape;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;

public class Base implements Screen{

   private static final float QUIBBY_WIDTH = 8;
   
   private World world;
   private OrthographicCamera camera;
   private Box2DDebugRenderer renderer;
   private Body bcirculo;
   
   private Texture texture;
   private SpriteBatch sb;
   private Sprite s;
   
   private static final float MUNDO_A_BOX = 0.01f;
   private static final float BOX_DEL_MUNDO = 100f;
   
   private Vector2 quibbyModelOrigin;
   
   private Body quibby;
   
   public void render(float delta) {
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
      Gdx.gl.glClearColor(0, 0.5f, 0, 1);
     
      float tw = Gdx.graphics.getWidth();
      float th = Gdx.graphics.getHeight();
     
      camera = new OrthographicCamera(tw / 2, th / 2);
     
      renderer = new Box2DDebugRenderer();
     
      renderer.render(world, camera.combined);
     
      world.step(1/40f, 6, 6);
     
      if(Gdx.input.isKeyPressed(Keys.D)){
         bcirculo.setLinearVelocity(new Vector2(50f, 0));
      }
     
      else if(Gdx.input.isKeyPressed(Keys.A)){
         bcirculo.setLinearVelocity(new Vector2(-50f, 0));
      }
     
      else if(Gdx.input.isKeyPressed(Keys.S)){
         bcirculo.setLinearVelocity(new Vector2(0, -50f));
      }
     
      else if(Gdx.input.isKeyPressed(Keys.W)){
         bcirculo.setLinearVelocity(new Vector2(0, 50f));      
      }
     
      else if(Gdx.input.isKeyPressed(Keys.R)){
         quibby.setLinearVelocity(new Vector2(0, 50f));
         s.setRotation(0);
      }
     
      else if(Gdx.input.isKeyPressed(Keys.UP)){
         quibby.setLinearVelocity(new Vector2(0, 50f));
      }
     
      else if(Gdx.input.isKeyPressed(Keys.DOWN)){
         quibby.setLinearVelocity(new Vector2(0, -50f));
      }
     
      else if(Gdx.input.isKeyPressed(Keys.RIGHT)){
         quibby.setLinearVelocity(new Vector2(50f, 0));
      }
     
      else if(Gdx.input.isKeyPressed(Keys.LEFT)){
         quibby.setLinearVelocity(new Vector2(-50f, 0));
      }
     
      sb = new SpriteBatch();
      sb.begin();
      s.draw(sb);
      sb.end();
     
      Vector2 bottlePos = quibby.getPosition().sub(quibbyModelOrigin);
       
       s.setPosition(bottlePos.x + s.getWidth() * 2, bottlePos.y + s.getHeight() * 2);
       //s.setRegion(0, 0, 115, 135);
      s.setOrigin(quibbyModelOrigin.x, quibbyModelOrigin.y);
       s.setRotation(quibby.getAngle() * MathUtils.radiansToDegrees);
       
   }

   public void resize(int width, int height) {
     
   }

   public void show() {
      world = new World(new Vector2(0, -60), true);
      camera = new OrthographicCamera(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
     
      BodyDef bdsuelo = new BodyDef();
      bdsuelo.position.set(new Vector2(0, -70));
     
      Body bsuelo = world.createBody(bdsuelo);
     
      PolygonShape ssuelo = new PolygonShape();
      ssuelo.setAsBox((camera.viewportWidth) * 2, 10.0f);
     
      bsuelo.createFixture(ssuelo, 0.0f);
     
      ssuelo.dispose();
     
      BodyDef bdcirculo = new BodyDef();
      bdcirculo.type = BodyType.DynamicBody;
      bdcirculo.position.set(new Vector2(0, 10));
     
      bcirculo = world.createBody(bdcirculo);
     
      CircleShape scircle = new CircleShape();
      scircle.setRadius(5.4f);
     
      FixtureDef fdcircle = new FixtureDef();
      fdcircle.density = 0.6f;
      fdcircle.friction = 0.5f;
      fdcircle.restitution = 0.5f;
      fdcircle.shape = scircle;
     
      Fixture fcircle = bcirculo.createFixture(fdcircle);
     
      texture = new Texture(Gdx.files.internal("MuñecoFeo256x256.png"));
     
      s = new Sprite(texture);
     
      scircle.dispose();
     
      crearQuibby();
     
   }
   
   public void crearQuibby(){
      BodyEditorLoaderFix loader = new BodyEditorLoaderFix(Gdx.files.internal("data/Serie2b.json"));
     
      BodyDef bd = new BodyDef();
      bd.type = BodyType.DynamicBody;
     
      FixtureDef fd = new FixtureDef();
      fd.density = 1;
      fd.friction = 0.5f;
      fd.restitution = 0.3f;
     
      quibby = world.createBody(bd);
      quibby.setUserData(s);
     
      loader.attachFixture(quibby, "MuñecoFeo.png", fd, QUIBBY_WIDTH);
      quibbyModelOrigin = loader.getOrigin("MuñecoFeo.png", QUIBBY_WIDTH).cpy();
   }


   public void hide() {
     
   }

   public void pause() {
     
   }

   public void resume() {
     
   }

   public void dispose() {
     
   }
   
   
   
}


I triyed many options, but I can't put the image in the body...

My head will be exploded  Huh

Atte: A noob with Box2D.

P.D: I'm spanish.  persecutioncomplex
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (21 views)
2014-09-19 03:14:18

Dwinin (35 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (87 views)
2014-09-10 06:39:09

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!