Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  
  i made a sprite but how do i set up the controls? (android)  (Read 718 times)
0 Members and 1 Guest are viewing this topic.
Offline hellrazer21

Junior Member





« Posted 2013-06-01 00:55:35 »

ok so i made my sprite i have the texture atlas now how do i get some buttons on screen and set them up to control the character  is there any examples out there

only game examples i found were ones that make a character move with arrow keys on the keyboard im trying to make a game for android so i need to have buttons on screen (like left and right arrows and jump)

i know this might seem like a dumb question but this is the newbie section  Tongue


Offline HeroesGraveDev

JGO Kernel


Medals: 260
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2013-06-01 01:00:35 »

Logic should be separate from the input.

Have booleans like movingLeft, movingUp etc. and move based on that.

Then, in the input class, have pressing the key change movingX to true and releasing changing it to false.

Second part: buttons on the screen.

I've never used LibGDX, so I don't know how touchscreen input works.

However it works, if the button is touched, treat it like a key press, and use the above technique.

Offline hellrazer21

Junior Member





« Reply #2 - Posted 2013-06-01 01:25:18 »

the part about the booleans i understand. i remember i did something like this in app inventor but as far as writing the code in java how do i set everything up

do i set up the textures of the buttons as variables or something and the character sprite is that just a bunch of if and if else statements?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online Longarmx
« Reply #3 - Posted 2013-06-01 01:33:51 »

You detect if the touch is within the button's bounds, then you set the Boolean accordingly. The libGDx wiki is your friend here.

Offline ReBirth
« Reply #4 - Posted 2013-06-01 02:37:55 »

1  
2  
Gdx.input.isKeyPressed(Input.Keys.LEFT);
Gdx.input.isTouched();

Offline hellrazer21

Junior Member





« Reply #5 - Posted 2013-06-01 07:41:08 »

ok so i looked at the wiki and nothing about setting the buttons bounds

Online Longarmx
« Reply #6 - Posted 2013-06-01 12:35:34 »

I don't know if scene2d works on android but you could try it out. Else, you will have to check it like clicking a button with your mouse. You can set up a rectangle with the button dimensions and check if the touch is within with the
rect.contains(x,y);
method which return a Boolean.

Offline ReBirth
« Reply #7 - Posted 2013-06-01 12:40:41 »

Err scene2d works flawlessly on android. My MAGNET is full composed by scene2d. Yet it is not static, you can see I put some animation like move and "toggle" effect on it.

If by button bounds you mean button click, a quickest way is to register an InputListener to it and override the touchDown method. Make sure you use Stage-based on your screen for easier debug.

Offline hellrazer21

Junior Member





« Reply #8 - Posted 2013-06-01 20:43:41 »

do i use scene2d.ui.Button or scene2d.ui.ImageButton ... do i need to use an actor somewhere?

Online Jimmt
« League of Dukes »

JGO Kernel


Medals: 133
Projects: 4
Exp: 3 years



« Reply #9 - Posted 2013-06-01 20:51:01 »

do i use scene2d.ui.Button or scene2d.ui.ImageButton ... do i need to use an actor somewhere?
Button and ImageButton, man, those names are so cryptic. Roll Eyes
Use whichever you need.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #10 - Posted 2013-06-01 20:53:37 »

do i use scene2d.ui.Button or scene2d.ui.ImageButton ... do i need to use an actor somewhere?

There is Button: You can include any kind of content into a button. I know two predefined versions of the inner content:

TextButton: The inner widget is a Label. There's text on the Button.
ImageButton: The inner widget is an Image. There's an image on the Button.

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline ReBirth
« Reply #11 - Posted 2013-06-02 02:23:57 »

ImageButton? Button class sure has image through ButtonStyle.

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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (45 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (34 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!