Skip to content
Snippets Groups Projects
Commit 8eb8ead5 authored by INGRID HECK's avatar INGRID HECK
Browse files

Add simple button class

parent 34a2a4e2
Branches
No related tags found
1 merge request!2Resolve "Design buttons where user jumps/slides"
Pipeline #210221 passed
assets/down.png

5.9 KiB

assets/up.png

5.8 KiB

package tdt4240.netrunner package tdt4240.netrunner
import com.badlogic.gdx.ApplicationAdapter import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Texture import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.math.Vector2 import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.scenes.scene2d.Stage
import com.badlogic.gdx.scenes.scene2d.ui.Skin
import com.badlogic.gdx.utils.ScreenUtils import com.badlogic.gdx.utils.ScreenUtils
import java.util.Vector
class Netrunner : ApplicationAdapter() { class Netrunner : ApplicationAdapter() {
private lateinit var stage: Stage
private lateinit var skin: Skin
private lateinit var font: BitmapFont
private lateinit var batch: SpriteBatch private lateinit var batch: SpriteBatch
private lateinit var img: Texture private lateinit var img: Texture
private var position: Vector2 = Vector2(300f, 0f) private var position: Vector2 = Vector2(300f, 0f)
private var speed: Float = 10.0f; private var speed: Float = 10.0f
override fun create() { override fun create() {
batch = SpriteBatch() batch = SpriteBatch()
......
package tdt4240.netrunner
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.Sprite
import com.badlogic.gdx.graphics.g2d.SpriteBatch
class SimpleButton() {
private lateinit var skin: Sprite
fun SimpleButton(texture: Texture, x: Float, y: Float, width: Float, height: Float){
skin = Sprite(texture)
skin.setPosition(x, y)
skin.setSize(width, height)
}
public fun update(batch: SpriteBatch, input_x: Float, input_y: Float){
checkIfClicked(input_x, input_y);
skin.draw(batch);
}
private fun checkIfClicked(ix: Float, iy: Float) {
if (ix > skin.x && ix < skin.x + skin.width) {
if (iy > skin.y && iy < skin.y + skin.height) {
// the button was clicked, perform an action
println("Button clicked !")
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment