Slick Forums

Discuss the Slick 2D Library
It is currently Sat Dec 16, 2017 4:39 pm

All times are UTC




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 171 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12
Author Message
 Post subject: can't use Camera :(
PostPosted: Thu Nov 01, 2012 5:10 pm 
Offline

Joined: Wed Oct 24, 2012 2:31 pm
Posts: 17
first of all thanks a lot for this awesome library

i m trying to do a simple side scroller game test and i think it can be done through Camera class right ? i am not sure . i downloaded latest zip from github , is there any problem with camera class ?
i am using netbeans everything is working fine, character is moving also but when i try this code in GameWorld ..

Code:
setCamera(new [b]Camera[/b](this, hero, gc.getWidth(),
           gc.getHeight(), 550, 170, hero.maxSpeed));


but there is a redline in bold-ed text Camera, an Error in constructor
and i dont get it class is importing just fine i just cant get it working there is no problem i checked many times What is Wrong ? please help Thanks :(


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Thu Nov 01, 2012 11:32 pm 
Offline
Regular

Joined: Mon Dec 08, 2008 2:17 pm
Posts: 160
lavago, I've compiled the Marte engine 0.3 src for you, you can download it here:

jar
Javadoc
sources
Full distribution

and these are the changes between 0.2 and 0.3:
Changes in ResourceManager:
Quote:
Allow to define an Animation from resources.xml
Rename <int> and <float> to <param> in resources.xml
Return Font instead of AngelCodeFont from getFont
Allow to load resources in 1 line: ResourceManager.loadResources("resources.xml");

Changes in Entity:
Quote:
currentAnim is now private, use setAnim
animations is now private, use addAnimation, isCurrentAnim and getCurrentAnim
currentImage is now private use setGraphic, getCurrentImage
resume, pause, restart alarms using entity.alarms
active is false when an entity is removed(#66)
Add anim does not set the entity animation, Use setAnim to set the initial animation.
define is deprecated, use bindToKey or bindToMouse in Entity and World(#59)

Other changes:
Quote:
Control sound and music using the new SFX class
A default camera is created in the world. To follow an entity use:
camera.follow(entity, CameraFollowStyle.TOPDOWN);
see it.marteEngine.test.avatar for usage.

Split build file into 2 parts: ME distribution and game distribution.
Use a String as id in the StateManager


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Fri Nov 02, 2012 3:18 am 
Offline

Joined: Thu Aug 30, 2012 12:13 am
Posts: 43
Thank You So Much Stef! You Are A Life Saver! :D


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Fri Nov 02, 2012 6:51 am 
Offline

Joined: Thu Aug 30, 2012 12:13 am
Posts: 43
Hey, I was wondering why my player wasn't moving when press the right or left arrow keys.

Code:
package gamepackage;

import it.marteEngine.entity.*;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class PlayerFox extends Entity {
   
   public static String PFox = "pfox";
   
   Image foxsheet = new Image("Resources/Fox.png");
   Image foxleft = foxsheet.getSubImage(0, 0, 26, 18);
   Image foxright = foxsheet.getSubImage(52, 0, 26, 18);
   Image[] foxlefta = {foxsheet.getSubImage(0, 0, 26, 18), foxsheet.getSubImage(26, 0, 26, 18)};
   Image[] foxrighta = {foxsheet.getSubImage(52, 0, 26, 18), foxsheet.getSubImage(78, 0, 26, 18)};
   Animation ismovingleft = new Animation(foxlefta,300,true);
   Animation ismovingright = new Animation(foxrighta,300,true);
   
   public PlayerFox(float x, float y) throws SlickException {
      super(x, y);
      addType(PFox);
      setHitBox(0, 0, width, height);
      setGraphic(foxright);
      
   }

   public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
      super.render(gc, g);
   }

   public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException, InterruptedException {
      super.update(gc, delta);
      addAnimation("movingright", ismovingright);
      addAnimation("movingleft", ismovingleft);
      Input input = gc.getInput();
      
      if(input.isKeyPressed(Input.KEY_RIGHT)) {
         x -= (5 * delta);
         setAnim("movingright");
      }
      if(input.isKeyPressed(Input.KEY_LEFT)) {
         x += (5 * delta);
         setAnim("movingleft");
      }
      if(input.isKeyPressed(Input.KEY_SPACE)) {
         
      }
   }

}


Top
 Profile  
 
 Post subject: Woot ? it Worked :P
PostPosted: Fri Nov 02, 2012 12:34 pm 
Offline

Joined: Wed Oct 24, 2012 2:31 pm
Posts: 17
Thanks Stef :)
that new updated version worked just fine for me.
and side-scrolling is also smooth
however when i press jump and run than hero jumps smooth but when coming down camera trys to center hero and the hero goes a little back and the scence stops and ruins the smooth-ness

EDIT :: Solved ..
just had to put this line in update method
camera.follow(hero, CameraFollowStyle.TOPDOWN);

Thanks a lot for this awesome library :)


Top
 Profile  
 
 Post subject: Re: MarteEngine
PostPosted: Wed Feb 19, 2014 10:17 am 
Offline

Joined: Tue Feb 18, 2014 5:05 pm
Posts: 1
Hi all. Im following the tutorials on the ME wiki and Im stuck at the input tutorial - it doesnt work for me in the Player and Level class - it only works in the HelloWorld Class using the slick2d methods for input. Can you point out my mistake ? Here are my classes following the tutorials.
[code]
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

/**
* Launch Hello World example
**/
public class HelloWorldTest extends StateBasedGame {

public HelloWorldTest(String title) {
super(title);
}

@Override
public void initStatesList(GameContainer container) throws SlickException {
// add HelloWorld to current game with id 1
addState(new HelloWorld(1, container));
}

public static void main(String[] argv) {
try {
AppGameContainer container = new AppGameContainer(new HelloWorldTest(
"Hello World Marte Engine"));
container.setDisplayMode(800, 600, false);
container.setTargetFrameRate(60);
container.start();

} catch (SlickException e) {
e.printStackTrace();
}
}

}
========
import it.randomtower.engine.World;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

//import it.randomtower.engine.World;

//slick input works

public class HelloWorld extends World {
private Image img;
private boolean one = false;
public HelloWorld(int id, GameContainer container) throws SlickException {
super(id, container);

img = new Image("data/Alien.png");
}


@Override
public void render(GameContainer container, StateBasedGame stateBasedGame, Graphics g)
throws SlickException {
super.render(container,stateBasedGame,g);

g.drawString("Hello World", 300, 200);
img.draw(100, 100, 0.2f);
// if (one) g.drawString("one pressed", 100, 100);
}


@Override
public void init(GameContainer container, StateBasedGame game)
throws SlickException {
// TODO Auto-generated method stub
super.init(container, game);

}


@Override
public void update(GameContainer arg0, StateBasedGame arg1, int arg2)
throws SlickException {
// TODO Auto-generated method stub
super.update(arg0, arg1, arg2);
Input in = container.getInput();
// if(in.isKeyDown(Input.KEY_1)) one = true;
// if(in.isKeyDown(Input.KEY_4)) System.out.println("4 pressed");

}

}
============
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;

import it.randomtower.engine.entity.Entity;

//no input works

public class Player extends Entity {

/**
* @param x, x coordinate on screen where Player starts
* @param y, y coordinate on screen where Player starts
* @throws SlickException
*/


public Player(float x, float y) throws SlickException {
super(x, y);
// load Image from disk and associate it as player image
Image img = new Image("data/Alien.png");
setGraphic(img);

// define a command to handle input
define("RIGHT", Input.KEY_RIGHT);
}

@Override
public void update(GameContainer container, int delta) throws SlickException {
// TODO Auto-generated method stub
super.update(container, delta);
// check if a key is down
if(check("RIGHT")){
// do anything you like, for example:
x = x+10;
System.out.println("right pressed!");

}

// Input in = container.getInput();


// if(in.isKeyDown(Input.KEY_2)) System.out.println("2 is pressed!");

}


@Override
public void render(GameContainer arg0, Graphics arg1) throws SlickException {
// TODO Auto-generated method stub
super.render(arg0, arg1);
}



}
==========
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.StateBasedGame;

import it.randomtower.engine.ME;
import it.randomtower.engine.World;

import it.randomtower.engine.entity.Entity;

//slick input not working

public class Level extends World {
private boolean five = false;
/**
* @param id, unique identifier for World
* @param container, container for World
*/
public Level(int id, GameContainer container) {
super(id, container);
// TODO Auto-generated constructor stub


}

@Override
public void add(Entity e) {
// TODO Auto-generated method stub
super.add(e);
}

@Override
public void init(GameContainer container, StateBasedGame game)
throws SlickException {
super.init(container, game);

Player player = new Player(100,100);
add(player) ;// cant resolve World.GAME as in the tutorial


}

@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
super.update(container, game, delta);
Input in = container.getInput();

if(in.isKeyDown(Input.KEY_5)) {
five = true;
}
}

@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException {
super.render(container, game, g);
if(five) System.out.println("five!");
}



}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 171 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group