List of usage examples for com.badlogic.gdx.graphics Texture Texture
public Texture(TextureData data)
From source file:MyGdxGame.java
License:Apache License
@Override public void create() { // load the koala frames, split them, and assign them to Animations koalaTexture = new Texture("koalio.png"); TextureRegion[] regions = TextureRegion.split(koalaTexture, 18, 26)[0]; stand = new Animation(0, regions[0]); jump = new Animation(0, regions[1]); walk = new Animation(0.15f, regions[2], regions[3], regions[4]); walk.setPlayMode(Animation.PlayMode.LOOP_PINGPONG); // figure out the width and height of the koala for collision // detection and rendering by converting a koala frames pixel // size into world units (1 unit == 16 pixels) Koala.WIDTH = 1 / 16f * regions[0].getRegionWidth(); Koala.HEIGHT = 1 / 16f * regions[0].getRegionHeight(); // load the map, set the unit scale to 1/16 (1 unit == 16 pixels) map = new TmxMapLoader().load("level1.tmx"); renderer = new OrthogonalTiledMapRenderer(map, 1 / 16f); // create an orthographic camera, shows us 30x20 units of the world camera = new OrthographicCamera(); camera.setToOrtho(false, 30, 20);/* w ww .j a v a2 s. c o m*/ camera.update(); // create the Koala we want to move around the world koala = new Koala(); koala.position.set(20, 20); }
From source file:actors.Archer.java
public Archer(float hlth, float dmg, float x, float y, float arrowTmr, Stage stg, int lvl, int pth) { notmoving = false;//w ww . j av a 2 s .c o m health = hlth; damage = dmg; stage = stg; level = lvl; path = pth; arrowTimer = arrowTmr; this.setName("archer"); texture = new Texture("archer.png"); sprite = new Sprite(texture); sprite.setScale(0.65f); setBounds(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight()); emptyHealthBar = new Sprite(new Texture("emptyBar.png")); fullHealthBar = new Sprite(new Texture("fullBar.png")); velocity = 50; assignMovement(x, y); /* init = new MoveToAction(); init.setPosition(x, y); ms = new MoveToAction(); ms.setPosition(100f,375f); ma1 = new MoveToAction(); ma1.setPosition(315f,375f); ma1.setDuration(((315-100 )/velocity)); ma2 = new MoveToAction(); ma2.setPosition(315f, 180f); ma2.setDuration((375-180)/velocity); ma3 = new MoveToAction(); ma3.setPosition(510f, 180f); ma3.setDuration((510-315)/velocity); ma4 = new MoveToAction(); ma4.setPosition(510f, 570f); ma4.setDuration((570-180)/velocity); ma5 = new MoveToAction(); ma5.setPosition(680f, 570f); ma5.setDuration((680-510)/velocity); ma6 = new MoveToAction(); ma6.setPosition(680f, 375f); ma6.setDuration((570-375)/velocity); ma7 = new MoveToAction(); ma7.setPosition(1000f, 375f); ma7.setDuration((1000-680)/velocity); SequenceAction sa1 = new SequenceAction(ms, ma1, ma2, ma3, ma4); SequenceAction sa2 = new SequenceAction(ma5, ma6, ma7); SequenceAction sa3 = new SequenceAction(ma1, ma2, ma3, ma4); SequenceAction sa4 = new SequenceAction(ma2, ma3, ma4); SequenceAction sa5 = new SequenceAction(ma3, ma4, ma5, ma6, ma7); SequenceAction sa6 = new SequenceAction(init, ma4, ma5, ma6, ma7); SequenceAction sa7 = new SequenceAction(init, ma5, ma6, ma7); SequenceAction sa8 = new SequenceAction(init, ma6, ma7); SequenceAction csa1 = new SequenceAction(sa1, sa2); SequenceAction csa2 = new SequenceAction(init, sa3, sa2); SequenceAction csa3 = new SequenceAction(init, sa4, sa2); SequenceAction csa4 = new SequenceAction(init, sa5); if((x==100)&&(y==375)) this.addAction(csa1); else if((y==375)&&(x<315)) { ma1.setDuration((315-x)/velocity); sa3 = new SequenceAction(ma1, ma2, ma3, ma4); csa2 = new SequenceAction(init, sa3, sa2); this.addAction(csa2); } else if((x==315)&&(y!=180)) { ma2.setDuration((y-180)/velocity); sa4 = new SequenceAction(ma2, ma3, ma4); csa3 = new SequenceAction(init, sa4, sa2); this.addAction(csa3); } else if((y==180)&&(x!=510)) { ma3.setDuration((510-x)/velocity); sa5 = new SequenceAction(ma3, ma4, ma5, ma6, ma7); csa4 = new SequenceAction(init, sa5); this.addAction(csa4); } else if((x==510)&&(y!=570)) { ma4.setDuration((570-y)/velocity); sa6 = new SequenceAction(init, ma4, ma5, ma6, ma7); this.addAction(sa6); } else if((y==570)&&(x!=680)) { ma5.setDuration((680-x)/velocity); sa7 = new SequenceAction(init, ma5, ma6, ma7); this.addAction(sa7); } else if((x==680)&&(y!=375)) { ma6.setDuration((y-375)/velocity); sa8 = new SequenceAction(init, ma6, ma7); this.addAction(sa8); } else if((y==375)&&(x>315)) { ma7.setDuration((1000-x)/velocity); SequenceAction sa9 = new SequenceAction(init, ma7); this.addAction(sa9); } */ }
From source file:actors.Arrow.java
public Arrow(float startX, float startY, float destX, float destY) { this.setName("arrow"); texture = new Texture("arrow.png"); sprite = new Sprite(texture); sprite.setScale(0.1f);/*from w w w . j a va 2 s.c o m*/ angle = (float) Math.toDegrees(atan((destY - startY) / (destX - startX))); System.out.println(String.valueOf(angle)); sprite.setOriginCenter(); sprite.rotate(angle + 270); //sprite.setRotation(angle); velocity = 300; init = new MoveToAction(); init.setPosition(startX, startY); distSquared = ((startX - destX) * (startX - destX) + (startY - destY) * (startY - destY)); shoot = new MoveToAction(); shoot.setPosition(destX, destY); shoot.setDuration((float) (sqrt(distSquared) / velocity)); moveOff = new MoveToAction(); moveOff.setPosition(-100f, -100f); SequenceAction sa = new SequenceAction(init, shoot, moveOff); this.addAction(sa); }
From source file:actors.BasicSkel.java
public BasicSkel(float hlth, float dmg, float x, float y, int lvl, int pth, Stage stg, PlayScreen scrn) { this.setName("skeleton"); level = lvl;/* ww w . j a va2 s.co m*/ path = pth; stage = stg; screen = scrn; health = hlth; damage = dmg; slowTimer = -1; slowed = false; reset = false; poisoned = false; notmoving = false; if (damage < 220) texture = new Texture("skelsword1.png"); if (damage < 240 && damage >= 220) texture = new Texture("skelsword2.png"); if (damage >= 240) texture = new Texture("skelsword3.png"); sprite = new Sprite(texture); sprite.setScale(0.65f); setBounds(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight()); fireEffect = new ParticleEffect(); fireEffect.load(Gdx.files.internal("fire"), Gdx.files.internal("")); fireEffect.getEmitters().first().setPosition(getX(), getY()); fireballSound = Gdx.audio.newSound(Gdx.files.internal("fireball.wav")); iceEffect = new ParticleEffect(); iceEffect.load(Gdx.files.internal("ice"), Gdx.files.internal("")); iceEffect.getEmitters().first().setPosition(getX(), getY()); poisonEffect = new ParticleEffect(); poisonEffect.load(Gdx.files.internal("poison"), Gdx.files.internal("")); poisonEffect.getEmitters().first().setPosition(getX(), getY()); emptyHealthBar = new Sprite(new Texture("emptyBar.png")); fullHealthBar = new Sprite(new Texture("fullBar.png")); ColorAction red = new ColorAction(); red.setEndColor(Color.RED); red.setDuration(1f); MoveToAction moveOff = new MoveToAction(); moveOff.setPosition(-100, -100); kill = new SequenceAction(red, moveOff); this.addListener(new ClickListener() { @Override public void clicked(InputEvent event, float x, float y) { if (health != 100000 && abs(screen.player.getX() - getX()) < screen.playerRange && abs(screen.player.getY() - getY()) < screen.playerRange) { if (screen.playerSpell == 1) { health -= screen.playerDamage; stage.addActor( new Fireball(screen.player.getX(), screen.player.getY(), getX() + 16, getY() + 16)); fireballSound.play(0.8f); fireEffect.start(); } if (screen.playerSpell == 2) { health -= screen.playerDamage * 0.75; stage.addActor( new IceBolt(screen.player.getX(), screen.player.getY(), getX() + 16, getY() + 16)); fireballSound.play(0.8f); iceEffect.start(); slowTimer = 3; if (health >= 0) slowed = true; } if (screen.playerSpell == 3) { poisoned = true; stage.addActor( new IceBolt(screen.player.getX(), screen.player.getY(), getX() + 16, getY() + 16)); fireballSound.play(0.8f); poisonEffect.start(); } } if (health <= 0) { poisoned = false; setName("dead"); health = 100000; clearActions(); addAction(kill); screen.skeletonDeath.play(1.0f); screen.addGold(5); } } }); velocity = 70; //Rectangle body = new Rectangle(getX(), getY(), getWidth(), getHeight()); //ScaleByAction sba = new ScaleByAction(); //sba.setAmount(0.25f); assignMovement(x, y); }
From source file:actors.Castle.java
public Castle(float hlth, float damage, float x, float y, Stage stage) { this.setName("castle"); texture = new Texture("castle.png"); health = hlth;//from w w w . ja v a 2s .com arrowTimer = 3; sprite = new Sprite(texture); setBounds(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight()); emptyHealthBar = new Sprite(new Texture("emptyBar.png")); fullHealthBar = new Sprite(new Texture("fullBar.png")); velocity = 70; ms = new MoveToAction(); ms.setPosition(x, y); // ms.setPosition(35f,370f); Castle.this.addAction(ms); }
From source file:actors.Fireball.java
public Fireball(float startX, float startY, float destX, float destY) { this.setName("fireball"); texture = new Texture("firearrow.png"); sprite = new Sprite(texture); sprite.setScale(0.5f);/*from ww w . jav a 2 s. c om*/ angle = (float) Math.toDegrees(atan((destY - startY) / (destX - startX))); System.out.println(String.valueOf(angle)); sprite.setOriginCenter(); sprite.rotate(angle + 270); //sprite.setRotation(angle); velocity = 500; init = new MoveToAction(); init.setPosition(startX, startY); distSquared = ((startX - destX) * (startX - destX) + (startY - destY) * (startY - destY)); shoot = new MoveToAction(); shoot.setPosition(destX, destY); shoot.setDuration((float) (sqrt(distSquared) / velocity)); moveOff = new MoveToAction(); moveOff.setPosition(-100f, -100f); SequenceAction sa = new SequenceAction(init, shoot, moveOff); this.addAction(sa); }
From source file:actors.Footman.java
public Footman(float hlth, float dmg, float x, float y, int lvl, int pth) { this.setName("footman"); damage = dmg;//from w ww .j ava 2s . c om health = hlth; level = lvl; path = pth; notmoving = false; if (damage < 400) texture = new Texture("footman0.png"); if (damage < 450 && damage >= 400) texture = new Texture("footman1.png"); if (damage < 600 && damage >= 450) texture = new Texture("footman2.png"); if (damage < 1000 && damage >= 600) texture = new Texture("champion.png"); if (damage >= 1000) texture = new Texture("footman3.png"); sprite = new Sprite(texture); sprite.setScale(0.65f); setBounds(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight()); emptyHealthBar = new Sprite(new Texture("emptyBar.png")); fullHealthBar = new Sprite(new Texture("fullBar.png")); setTouchable(Touchable.disabled); velocity = 80; inCombat = false; assignMovement(x, y); /* init = new MoveToAction(); init.setPosition(x, y); ms = new MoveToAction(); ms.setPosition(100f,375f); ma1 = new MoveToAction(); ma1.setPosition(315f,375f); ma1.setDuration(((315-100 )/velocity)); ma2 = new MoveToAction(); ma2.setPosition(315f, 180f); ma2.setDuration((375-180)/velocity); ma3 = new MoveToAction(); ma3.setPosition(510f, 180f); ma3.setDuration((510-315)/velocity); ma4 = new MoveToAction(); ma4.setPosition(510f, 570f); ma4.setDuration((570-180)/velocity); ma5 = new MoveToAction(); ma5.setPosition(680f, 570f); ma5.setDuration((680-510)/velocity); ma6 = new MoveToAction(); ma6.setPosition(680f, 375f); ma6.setDuration((570-375)/velocity); ma7 = new MoveToAction(); ma7.setPosition(1000f, 375f); ma7.setDuration((1000-680)/velocity); SequenceAction sa1 = new SequenceAction(ms, ma1, ma2, ma3, ma4); SequenceAction sa2 = new SequenceAction(ma5, ma6, ma7); SequenceAction sa3 = new SequenceAction(ma1, ma2, ma3, ma4); SequenceAction sa4 = new SequenceAction(ma2, ma3, ma4); SequenceAction sa5 = new SequenceAction(ma3, ma4, ma5, ma6, ma7); SequenceAction sa6 = new SequenceAction(init, ma4, ma5, ma6, ma7); SequenceAction sa7 = new SequenceAction(init, ma5, ma6, ma7); SequenceAction sa8 = new SequenceAction(init, ma6, ma7); SequenceAction csa1 = new SequenceAction(sa1, sa2); SequenceAction csa2 = new SequenceAction(init, sa3, sa2); SequenceAction csa3 = new SequenceAction(init, sa4, sa2); SequenceAction csa4 = new SequenceAction(init, sa5); if((x==100)&&(y==375)) this.addAction(csa1); else if((y==375)&&(x<315)) { ma1.setDuration((315-x)/velocity); sa3 = new SequenceAction(ma1, ma2, ma3, ma4); csa2 = new SequenceAction(init, sa3, sa2); this.addAction(csa2); } else if((x==315)&&(y!=180)) { ma2.setDuration((y-180)/velocity); sa4 = new SequenceAction(ma2, ma3, ma4); csa3 = new SequenceAction(init, sa4, sa2); this.addAction(csa3); } else if((y==180)&&(x!=510)) { ma3.setDuration((510-x)/velocity); sa5 = new SequenceAction(ma3, ma4, ma5, ma6, ma7); csa4 = new SequenceAction(init, sa5); this.addAction(csa4); } else if((x==510)&&(y!=570)) { ma4.setDuration((570-y)/velocity); sa6 = new SequenceAction(init, ma4, ma5, ma6, ma7); this.addAction(sa6); } else if((y==570)&&(x!=680)) { ma5.setDuration((680-x)/velocity); sa7 = new SequenceAction(init, ma5, ma6, ma7); this.addAction(sa7); } else if((x==680)&&(y!=375)) { ma6.setDuration((y-375)/velocity); sa8 = new SequenceAction(init, ma6, ma7); this.addAction(sa8); } else if((y==375)&&(x>315)) { ma7.setDuration((1000-x)/velocity); SequenceAction sa9 = new SequenceAction(init, ma7); this.addAction(sa9); } */ }
From source file:actors.IceBolt.java
public IceBolt(float startX, float startY, float destX, float destY) { this.setName("icebolt"); texture = new Texture("icearrow.png"); sprite = new Sprite(texture); sprite.setScale(0.5f);//from w w w. ja v a 2 s. c om angle = (float) Math.toDegrees(atan((destY - startY) / (destX - startX))); System.out.println(String.valueOf(angle)); sprite.setOriginCenter(); sprite.rotate(angle + 270); //sprite.setRotation(angle); velocity = 500; init = new MoveToAction(); init.setPosition(startX, startY); distSquared = ((startX - destX) * (startX - destX) + (startY - destY) * (startY - destY)); shoot = new MoveToAction(); shoot.setPosition(destX, destY); shoot.setDuration((float) (sqrt(distSquared) / velocity)); moveOff = new MoveToAction(); moveOff.setPosition(-100f, -100f); SequenceAction sa = new SequenceAction(init, shoot, moveOff); this.addAction(sa); }
From source file:actors.Necromancer.java
public Necromancer(float hlth, float damage, float x, float y, Stage stage) { this.setName("necromancer"); texture = new Texture("necromancer.png"); sprite = new Sprite(texture); setBounds(sprite.getX(), sprite.getY(), sprite.getWidth(), sprite.getHeight()); health = hlth;// w ww.j ava 2 s . c om attackTimer = 2; emptyHealthBar = new Sprite(new Texture("emptyBar.png")); fullHealthBar = new Sprite(new Texture("fullBar.png")); velocity = 70; ms = new MoveToAction(); ms.setPosition(x, y); // ms.setPosition(940f,375f); Necromancer.this.addAction(ms); /* int len = stage.size; for(i=0; i<len; i++){ Actor a = stageActors.get(i); if(a.getName().equals("myactor")){ //a is your Actor! break; */ }
From source file:actors.NecromancerAttack.java
public NecromancerAttack(float startX, float startY, float destX, float destY) { this.setName("necromancerbolt"); texture = new Texture("deathbolt.png"); sprite = new Sprite(texture); sprite.setScale(0.5f);//from w w w . j a v a 2 s . co m angle = (float) Math.toDegrees(atan((destY - startY) / (destX - startX))); System.out.println(String.valueOf(angle)); sprite.setOriginCenter(); sprite.rotate(angle + 270); //sprite.setRotation(angle); velocity = 500; init = new MoveToAction(); init.setPosition(startX, startY); distSquared = ((startX - destX) * (startX - destX) + (startY - destY) * (startY - destY)); shoot = new MoveToAction(); shoot.setPosition(destX, destY); shoot.setDuration((float) (sqrt(distSquared) / velocity)); moveOff = new MoveToAction(); moveOff.setPosition(-100f, -100f); SequenceAction sa = new SequenceAction(init, shoot, moveOff); this.addAction(sa); }