Bod MacNeil

Ranch Hand
+ Follow
since Jul 28, 2016
Bod likes ...
Mac Netbeans IDE Java
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
2
In last 30 days
0
Total given
0
Likes
Total received
4
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bod MacNeil

SOLVED!  I changed the method to get the instead of .  This took me a couple of days but glad I got it in the end.  My code isn't perfect so no doubt there will be more problems on the way.  
6 years ago
hey, I should have mentioned that I was using the framework LibGDX.  It has a built in Vector2 class, which has an x,y coordinate system for making games.  Its makes moving objects a lot simpler.   sharks is an ArrayLisst is of type Shark, which  is a class I made.  Here is the class:




I thought I had to maintain a position so I can set the bounds to that position.  I'm also updating the position every frame.  I got the bounds.intersects() working earlier but I did something to stop it again.  I think it will just take some fiddling around with.
6 years ago
Hello, I've made a small program which has shark object moving across the screen.  I want detect when the sharks touch the submarine object at the other side.  I have placed a rectangle around both objects but when I run the program its a bit buggy.  The texture no longer shows for either object and sometimes only 1 rectangle shows.  Collision detection doesn't work at all.  I've posted my code below in the hopes that someone can spot something.  thanks.  

//drawShark() method


//spriteBatch inside the render() method


//WorldUtils class that both Shark class and SUbmarine class extend
6 years ago
I have fixed the problem for now.  I changed the line from sharks.remove(current) to sharkIterator.remove()  
6 years ago
Hello all.  I'm having problems with removing items from my ArrayList;  In this program it creates a new shark object every 2 seconds and adds it to an ArrayList of Shark objects.   Once the shark reaches the end of the screen it should then remove the shark from the array list.  But I'm getting a java.util.ConcurrentModificationException.  I have posted the snipped of code I'm using for the Iterator and also the method for creating the shark.  ANy help would be great and I can post more info if required.  thanks

//Iterator in render() method;


//createShark() method
6 years ago
Fixed!  I never set my working directory to the assets folder folder!
7 years ago
Hello all.  I hope I'm just missing something simple but AS can't find a file thats in my Android assets folder.  

Here is the code:



And below is a pic of the error message and a screenshot of my assets folder to show the picture is there and spelt correctly.  any idea?

 

7 years ago
FIXED!  

I put the loop around here:


And moved my random number to inside here:


Now onto making the rest of it work
7 years ago
Hi all.  I'm trying to make a simple game where the user has to press the screen when the background colour turns red.  So far I'm just trying to get the background colour to change.

I'm new to Threads and even newer to handlers so i'm getting a bit lost with this little bit of code.  I want to loop the code so the colour changes every 0.3 seconds.  Making it very difficult for the user to press at the right time.  Are threads and handlers the right approach to this, or are there simpler ways?  I'm also lost on where my loop should go?  

Any comments about my code are appreciated.  Good or bad



Thank you
7 years ago
Sorry for the constant posts.  But I fixed the problem by putting them in onCreate().  If anyone could explain why this works that would be good

7 years ago
The code works ok when I comment out these :


Its weird that it only happens at run time.  Any ideas?
7 years ago
I've tried commenting out line 19 but when I re-run the program the error moved to line 20 and so on.  Its just going thought my instant variables.  Has it anything to do with where I'm putting them?
7 years ago
I missed out the package name when I posted the code here so its a little off.  line 19 is for rock2 on my Android Studio.  I was thinking maybe there is a problem which is triggering this which I haven't spotted yet?
7 years ago
hmmm that means this line is causing the problem:
I've just looked and there is a rock2 ImageView in my XML:


above is code from the activity_rock__paper__scissor.xml which has been added to my activity

7 years ago


12-14 10:02:54.690 21533-21533/macson.fifteendaysofjava E/AndroidRuntime: FATAL EXCEPTION: main
                                                                         java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{macson.fifteendaysofjava/macson.fifteendaysofjava.Rock_Paper_Scissor}: java.lang.NullPointerException
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
                                                                             at android.app.ActivityThread.access$600(ActivityThread.java:123)
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
                                                                             at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                             at android.os.Looper.loop(Looper.java:137)
                                                                             at android.app.ActivityThread.main(ActivityThread.java:4424)
                                                                             at java.lang.reflect.Method.invokeNative(Native Method)
                                                                             at java.lang.reflect.Method.invoke(Method.java:511)
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
                                                                             at dalvik.system.NativeStart.main(Native Method)
                                                                          Caused by: java.lang.NullPointerException
                                                                             at android.app.Activity.findViewById(Activity.java:1794)
                                                                             at macson.fifteendaysofjava.Rock_Paper_Scissor.<init>(Rock_Paper_Scissor.java:19)
                                                                             at java.lang.Class.newInstanceImpl(Native Method)
                                                                             at java.lang.Class.newInstance(Class.java:1319)
                                                                             at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
                                                                             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871)
                                                                             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 
                                                                             at android.app.ActivityThread.access$600(ActivityThread.java:123) 
                                                                             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) 
                                                                             at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                             at android.os.Looper.loop(Looper.java:137) 
                                                                             at android.app.ActivityThread.main(ActivityThread.java:4424) 
                                                                             at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                             at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 
                                                                             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 
                                                                             at dalvik.system.NativeStart.main(Native Method) 

7 years ago