Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Netrunner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olivia Foshaug Ingvaldsen
Netrunner
Commits
d5218f04
Commit
d5218f04
authored
2 years ago
by
karinlie
Browse files
Options
Downloads
Patches
Plain Diff
fikset knapp og slik at den bevegde seg
parent
8eb8ead5
No related branches found
No related tags found
1 merge request
!2
Resolve "Design buttons where user jumps/slides"
Pipeline
#212416
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/src/tdt4240/netrunner/Netrunner.kt
+19
-2
19 additions, 2 deletions
core/src/tdt4240/netrunner/Netrunner.kt
core/src/tdt4240/netrunner/SimpleButton.kt
+48
-15
48 additions, 15 deletions
core/src/tdt4240/netrunner/SimpleButton.kt
with
67 additions
and
17 deletions
core/src/tdt4240/netrunner/Netrunner.kt
+
19
−
2
View file @
d5218f04
...
...
@@ -3,6 +3,7 @@ package tdt4240.netrunner
import
com.badlogic.gdx.ApplicationAdapter
import
com.badlogic.gdx.Gdx
import
com.badlogic.gdx.Input
import
com.badlogic.gdx.InputMultiplexer
import
com.badlogic.gdx.graphics.Texture
import
com.badlogic.gdx.graphics.g2d.BitmapFont
import
com.badlogic.gdx.graphics.g2d.SpriteBatch
...
...
@@ -20,18 +21,27 @@ class Netrunner : ApplicationAdapter() {
private
lateinit
var
img
:
Texture
private
var
position
:
Vector2
=
Vector2
(
300f
,
0f
)
private
var
speed
:
Float
=
10.0f
private
lateinit
var
buttonUp
:
SimpleButton
private
lateinit
var
buttonDown
:
SimpleButton
public
var
inputMultiplexer
=
InputMultiplexer
()
override
fun
create
()
{
Gdx
.
input
.
inputProcessor
=
inputMultiplexer
batch
=
SpriteBatch
()
img
=
Texture
(
"whiteball.png"
)
buttonUp
=
SimpleButton
(
inputMultiplexer
,
Texture
(
"up.png"
),
550f
,
100f
,
60f
,
60f
)
{
moveUp
()
}
buttonDown
=
SimpleButton
(
inputMultiplexer
,
Texture
(
"down.png"
),
550f
,
20f
,
60f
,
60f
)
{
moveDown
()
}
}
override
fun
render
()
{
ScreenUtils
.
clear
(
1f
,
0f
,
0f
,
1f
)
batch
.
begin
()
batch
.
draw
(
img
,
position
.
x
,
position
.
y
)
move
(
1.0f
)
buttonUp
.
update
(
batch
)
buttonDown
.
update
(
batch
)
batch
.
end
()
}
...
...
@@ -57,5 +67,12 @@ class Netrunner : ApplicationAdapter() {
}
}
}
fun
moveUp
()
{
position
.
y
+=
speed
}
fun
moveDown
()
{
position
.
y
-=
speed
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
core/src/tdt4240/netrunner/SimpleButton.kt
+
48
−
15
View file @
d5218f04
package
tdt4240.netrunner
import
com.badlogic.gdx.Gdx
import
com.badlogic.gdx.InputMultiplexer
import
com.badlogic.gdx.InputProcessor
import
com.badlogic.gdx.graphics.Texture
import
com.badlogic.gdx.graphics.g2d.Sprite
import
com.badlogic.gdx.graphics.g2d.SpriteBatch
class
SimpleButton
(
)
{
class
SimpleButton
(
inputMultiplexer
:
InputMultiplexer
,
texture
:
Texture
,
x
:
Float
,
y
:
Float
,
width
:
Float
,
height
:
Float
,
callback
:
()
->
Unit
)
:
InputProcessor
{
private
lateinit
var
skin
:
Sprite
private
var
sprite
=
Sprite
(
texture
)
private
var
callback
=
callback
fun
SimpleButton
(
texture
:
Texture
,
x
:
Float
,
y
:
Float
,
width
:
Float
,
height
:
Float
)
{
s
kin
=
Sprite
(
texture
)
s
kin
.
setPosition
(
x
,
y
)
skin
.
setSize
(
width
,
height
)
init
{
s
prite
.
setPosition
(
x
,
y
)
s
prite
.
setSize
(
width
,
height
)
inputMultiplexer
.
addProcessor
(
this
)
}
public
fun
update
(
batch
:
SpriteBatch
,
input_x
:
Float
,
input_y
:
Float
){
checkIfClicked
(
input_x
,
input_y
);
skin
.
draw
(
batch
);
public
fun
update
(
batch
:
SpriteBatch
)
{
sprite
.
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 !"
)
override
fun
touchDown
(
screenX
:
Int
,
screenY
:
Int
,
pointer
:
Int
,
button
:
Int
):
Boolean
{
val
fixedScreenY
=
Gdx
.
graphics
.
height
-
screenY
println
(
"$screenX,$screenY,$fixedScreenY"
)
if
(
screenX
>=
sprite
.
x
&&
screenX
<=
sprite
.
x
+
sprite
.
width
&&
fixedScreenY
>=
sprite
.
y
&&
fixedScreenY
<=
sprite
.
y
+
sprite
.
height
)
{
callback
()
return
true
}
return
false
}
override
fun
touchUp
(
screenX
:
Int
,
screenY
:
Int
,
pointer
:
Int
,
button
:
Int
):
Boolean
{
return
false
}
override
fun
touchDragged
(
screenX
:
Int
,
screenY
:
Int
,
pointer
:
Int
):
Boolean
{
return
false
}
override
fun
keyDown
(
keycode
:
Int
):
Boolean
{
return
false
}
override
fun
keyUp
(
keycode
:
Int
):
Boolean
{
return
false
}
override
fun
keyTyped
(
character
:
Char
):
Boolean
{
return
false
}
override
fun
mouseMoved
(
screenX
:
Int
,
screenY
:
Int
):
Boolean
{
return
false
}
override
fun
scrolled
(
amountX
:
Float
,
amountY
:
Float
):
Boolean
{
return
false
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment