Четверг, 25 Апреля 2024, 03:34

Приветствую Вас Гость

[ Новые сообщения · Игроделы · Правила · Поиск ]
  • Страница 1 из 1
  • 1
Форум игроделов » Движки для разработки игр и сложные системы разработки » 2D-движки для создания игр » android libgdx touchpad
android libgdx touchpad
siiXthДата: Суббота, 13 Апреля 2013, 18:41 | Сообщение # 1
уже был
Сейчас нет на сайте
Делал по многим примерам, ошибок нет, но тачпад не появляется, массу вариантов пытался сделать - безрезультатно. Подскажите в чём причина. Спасибо
Код

package suvitruf.libgdxtutorial.view;

import java.util.HashMap;
import java.util.Map;

import suvitruf.libgdxtutorial.model.*;

import android.graphics.drawable.Drawable;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad.TouchpadStyle;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class WorldRenderer {
public static float CAMERA_WIDTH = 8f;
public static  float CAMERA_HEIGHT = 5f;

private World world;
public OrthographicCamera cam;
ShapeRenderer renderer = new ShapeRenderer();

private SpriteBatch spriteBatch;
Texture texture;
public  Map<String, TextureRegion> textureRegions = new HashMap<String, TextureRegion>();

public int width;
public int height;
public float ppuX;
public float ppuY;

public void setSize (int w, int h) {
this.width = w;
this.height = h;
ppuX = (float)width / CAMERA_WIDTH;
ppuY = (float)height / CAMERA_HEIGHT;
}

public void SetCamera(float x, float y){
this.cam.position.set(x, y,0);
this.cam.update();
spriteBatch.setProjectionMatrix(cam.combined);
}

public WorldRenderer(World world) {
spriteBatch=new SpriteBatch();

this.world = world;
this.cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
SetCamera(CAMERA_WIDTH / 2f, CAMERA_HEIGHT / 2f);

loadTextures();

//Create a touchpad skin

Texture touchpadTexture = new Texture(Gdx.files.internal("data/touchpad.png"));
touchpadTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegion background = new TextureRegion(touchpadTexture, 0, 0, 75, 75);
TextureRegion knob = new TextureRegion(touchpadTexture, 80, 0, 120, 120);
TextureRegionDrawable backgroundDrawable = new TextureRegionDrawable(background);
TextureRegionDrawable knobDrawable = new TextureRegionDrawable(knob);
Touchpad touchpad = new Touchpad(10, new Touchpad.TouchpadStyle(backgroundDrawable, knobDrawable));
touchpad.setBounds(15, 15, 200, 200);
world.addActor(touchpad);

//Create a touchpad skin

}
private void loadTextures() {
texture  = new Texture(Gdx.files.internal("images/atlas.png"));
TextureRegion tmp[][] = TextureRegion.split(texture, texture.getWidth() / 2, texture.getHeight() / 2);
textureRegions.put("player", tmp[0][0]);
textureRegions.put("brick1", tmp[0][1]);
textureRegions.put("brick2", tmp[1][0]);
textureRegions.put("brick3", tmp[1][1]);
}
public void render() {
SetCamera(world.getPlayer().getPosition().x*ppuX,world.getPlayer().getPosition().y*ppuX);

spriteBatch.begin();
drawBricks();
drawPlayer() ;
spriteBatch.end();
}
private void drawBricks() {
//renderer.setProjectionMatrix(cam.combined);
//renderer.begin(ShapeType.FilledRectangle);
int i=0;
for (Brick brick : world.getBricks()) {
spriteBatch.draw(textureRegions.get("brick"+(i%3+1)), brick.getPosition().x* ppuX, brick.getPosition().y * ppuY,Brick.SIZE * ppuX, Brick.SIZE * ppuY);
++i;
}

//renderer.end();
}
public void dispose() {
try{

spriteBatch.dispose();
texture.dispose();
textureRegions.clear();
}
catch(Exception e){

}
}
private void drawPlayer() {

spriteBatch.draw(textureRegions.get("player"), world.getPlayer().getPosition().x* ppuX, world.getPlayer().getPosition().y * ppuY,Player.SIZE * ppuX, Player.SIZE * ppuY);

}

}



Сообщение отредактировал siiXth - Суббота, 13 Апреля 2013, 18:41
SuvitrufДата: Суббота, 24 Августа 2013, 17:39 | Сообщение # 2
был не раз
Сейчас нет на сайте
А touchpad отрисовывать с помощью spriteBatch не надо?
Форум игроделов » Движки для разработки игр и сложные системы разработки » 2D-движки для создания игр » android libgdx touchpad
  • Страница 1 из 1
  • 1
Поиск:

Все права сохранены. GcUp.ru © 2008-2024 Рейтинг