Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
AngelWire
Visitor

Re: Display an image

Thanks RokuMarkn, that helps a lot! One last question(I hope), how do I check if a button on the remote is pressed? I've looked through the examples and documentation but I can't get anything to work.
0 Kudos
RokuMarkn
Visitor

Re: Display an image

See page 58 of the Brightscript 3.0 Reference. The roUniversalControlEvent object that you receive has a GetInt method that returns the id of the key pressed.

--Mark
0 Kudos
AngelWire
Visitor

Re: Display an image

I finally got it working, but how would I check if the button is still being held instead of just pressed?
This is what I have so far but it's not working:
while true
x = x+xto
y = y+yto
scr.setalphaenable(true)
BackGround(scr)
scr.drawobject(x, y, logo)
scr.swapbuffers()
msg = wait(0, port)
if type(msg) = "roUniversalControlEvent" then
if msg.getint()= 2
yto = -5
else if msg.getint()= 3
yto = 5
else if msg.getint()= 4
xto = -5
else if msg.getint()= 5
xto = 5
else if msg.getint()= 102
yto = 0
else if msg.getint()= 103
yto = 0
else if msg.getint()= 104
xto = 0
else if msg.getint()= 105
xto = 0
end if
end if
end while
0 Kudos
AngelWire
Visitor

Re: Display an image

"AngelWire" wrote:
I finally got it working, but how would I check if the button is still being held instead of just pressed?


Alright, I got that fixed, but now I figured out that the background is taking a ton of memory and causing the game to run super slow(from 59.9 fps to 8 ). Any suggestions?
0 Kudos
YungBlood
Streaming Star

Re: Display an image

When you press a button, you will get 2 events. First, you will get the press event (i.e. 2), then you release the button, you get the release event (i.e. 102). That allows a lot of flexibility. If you want to enforce only receiving "presses", then just set a release var when you get the press event, and clear it when you get the release event. (If you're not sure what I mean, I can give you a piece of code)

Also, I don't know if it makes a difference to roku, but I recommend making a small change to your code. Instead of using:

if msg.getint() = 2 then
...
else if msg.getint() = 3 then
...


Use this instead:

key = msg.getint()
if key = 2 then
....
else if key = 3 then
...
YungBlood

Bringing more fun to Roku!
0 Kudos
YungBlood
Streaming Star

Re: Display an image

"AngelWire" wrote:
Alright, I got that fixed, but now I figured out that the background is taking a ton of memory and causing the game to run super slow. Any suggestions?


Good question. I'm noticing that a bit on the HD version of my memory match game. I don't have the solution yet, but I am looking into speed improvements. I'll keep you posted with that I find.
YungBlood

Bringing more fun to Roku!
0 Kudos
AngelWire
Visitor

Re: Display an image

Thanks YungBlood. The problem was msg = wait(0, port), I changed it to msg = port.getmessage() and it works fine.
EDIT:
I fixed the speed issue, the problem was bg = CreateObject("roBitmap", "pkg:/images/grass.png") was in the while loop. I moved it and now it's running at 60 fps.
0 Kudos
YungBlood
Streaming Star

Re: Display an image

Good to know you got it running better. I don't have the create object in my loop, but my code runs a bit slow in HD. Could simply be the number of objects I'm drawing...
YungBlood

Bringing more fun to Roku!
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.