Sprite position changes lead to crash

Hullo folks,
I'm having some trouble with my current code. I'm trying to have a book item spawn in my minigame and I want it to move from it's original position (on the bottom side of the screen) to the top side of the screen. The code I wrote for this is simple enough and can be found below;
public void fireWeapon() throws IOException
          bookWeapon.setPosition(player.getX(), player.getY()-4); // Spawns the book near the player
          for(int i=0; i<160; i++)
               int currentX = bookWeapon.getX( );
               int newY = bookWeapon.getY( ) - WEAPON_SPEED;
               if (newY <= 1)
                    bookWeapon.setVisible(false);
               else
                    bookWeapon.setPosition(currentX, newY);
     }So what is this bookWeapon, you might wonder? Well it's instantiated earlier in the code;
Image imgBook = Image.createImage("/book.png");
Sprite bookWeapon = new Sprite(imgBook);
bookWeapon.setPosition(80, 150);
mLayerManager = new LayerManager();
mLayerManager.append(bookWeapon);So what I'm basically trying to do is as follows; Have the game create the book and add it to the layermanager at a position somewhere in the gamefield. (Or GameCanvas, if you will.) Then, when the player presses the fire button, the fireWeapon(); method is called and that sets the position of the book from whereever the player is standing. After this, the book is moved upwards using a negative Y value (WEAPON_SPEED). Then the if/else statement checks if the book has gone off the screen. If so, then it's removed, if not, then its new position is set.
Simple fact is; it doesn't work. Whenever I try to either get the position of the book in the form of getX() or getY() or try to set its position using setPosition() the game hangs with a nullPointerException.
I've tried all sorts of things but it doesn't work so, ideas, anyone?
One last note; the fireWeapon() method is started after the player presses the fire button in the input method. However, I assume most here know what an input method looks like, so I didn't deem it important enough to warrant inclusion in this code example.

Sprite bookWeapon = new Sprite(imgBook);is obviously inside a method and the variable reference bookWeapon goes out of scope when the method returns. You need to declare the variable as an instance fieldprivate Sprite bookWeapon;at the class level and initialize it before calling any method on it withbookWeapon = new Sprite(imgBook);Read more on scope of variables at
{color:#0000ff}http://home.cogeco.ca/~ve3ll/jatutor2.htm#st{color}
Problem solved?
db

Similar Messages

  • Custom fields position change in srm 7.0 in Purchase Order on WebDynpro

    Hi Experts,
    We are upgrading to SRM 5.0 to SRM 7.0
    In Purchase order screen,under account assignment,we want to see the acocunt assignment detailed view as the default view under tab "ACCOUNT ASSIGNMENT".Click on the DETAILS button and then the details show up in the bottom part of the screen.
    Can anyone advise how do we change the postion of fields in the account assignment tab which are created dynamically.
    My requirement is :
    Rahmenkostenstelle field should come below Bahnstelle field
    WebDynpro Component:   /SAPSRM/WDC_UI_DO_ACC
    View:  V_DO_ACCOUNT_DETAIL
    Thanks,
    Aarthi.

    Hi,
    Did you manage to solve the issue? I've tried to define customizing point "Configure Generic Field Display on User Interface" with no luck.
    I've even tried to enhance the corresponding WD Component for SC items detail. Field position is correct in the layout editor, but position changes when fields are rendered in runtime.
    Does anybody have any idea regarding related OSS? what am I missing?
    Regards

  • Placed image position change

    I have a few images placed into my website.  The positioning changes between chrome, firefox, and the biggest change in IE.  Is there any way to avoid this?  www.jarminlaw.com  the bottom quote marks under testimonials.
    Thanks!

    I have checked the home page on all the three browsers that you mentioned and they all look same to me.
    If you still see the issue with the image placing, I will suggest that you group them together with the text or content above or below it. Grouping usually fixes most of the alignment issues.
    - Abhishek Maurya

  • Position change clarification

    we have one derived business update type DBT_E001 and one update type SAM3010 (commission payment) in cash flow IFRS report, but these two are not appeared in "assign update type to position change category", is this correct?
    regarding to position change category, pls find attached.
    what does "post negative purchase value" 1010 mean? for MM1100+, it is used in borrowing of a fixed term deposit.
    in SE2000, it is incoming payment, which is payment inflow, why it is position outflow? what does position inflow mean?
    should we assign update type interest payment in position change category?

    Dear, Jolin.
    I suggest you not to change anything in configuration "Set the effectsof the update types on the position components" as it already configured for all simple and standart processes.
    If you want to uderstand how it could help you - play with configuration in sandbox.
    In order to know what Position Change Category does - see this table TRLTS_PMCAT. There you can find:
    Position change category - which you assign to update type.
    Two components - which can be changed by Position change category
    Rules - that tell you what components are changed and how.
    Discription and other fields.
    As concerns update type DBT_E001 ans similar Derived business transactions update types - you won't see any configuration as position change category is predefined - see the table above - position change category E001.
    in SE2000, it is incoming payment, which is payment inflow, why it is position outflow? what does position inflow mean?
    Incoming payment means - money inflow because you sell your security. Position outflow means - your security is sold
    what does "post negative purchase value" 1010 mean? for MM1100+, it is used in borrowing of a fixed term deposit.
    negative means you owe somebody. somebody gave you money and you have to return it some day.
    positive means you gave somebody money.

  • HT201269 In Iphone5 while Mail is reviewed and transfered to folder, for next mail folder list position changes. How to fix this error

    In Iphone5 while Mail is reviewed and transfered to folder, for next mail folder list position changes. How to fix this error

    In Iphone5 while Mail is reviewed and transfered to folder, for next mail folder list position changes. How to fix this error

  • Not here! Region Tie Regions by Position Change (Logic9)

    I have just upgraded to Logic9 and am looking though the new style instruction manual.
    On the 'Adding or Removing Arrangement Passages' page at the 'remove gaps between regions' part it says Choose Region > Tie Regions by Position Change (or use the Tie Regions by Position Change key command).
    The thing is, that the 'Tie Regions by Position Change' is not under the local menu Region and the KC
    is no where to be found either. Has anybody else seen this at all.
    There is the option 'Trim Regions etc' under Regions though no Tie Regions.
    Thanks
    Message was edited by: ekaton
    Message was edited by: ekaton

    Must be Region > Shuffle Regions left within selection then

  • Changed Key command - Tie Regions By Position Change

    This is my 3rd post - Is there no one else here who depended on "Tie Regions By Position Change" & finds the new version "Shuffle regions left within selection" unpredictable & unusable, with regions that shouldn't jumping to the right ?

    It doesnt work as expected for me, with 5 or 6 regions it does but when i want to buffer 40 or so regions , up against each other, several have jumped to unpredictable positions . (i'm doing lots of editing of interviews )

  • Bug: Front Panel objects relative position change when placing merge VI onto Block Diagram

    I've posted a bug report on LAVA, here:
    http://forums.lavag.org/Front-Panel-objects-relati​ve-position-change-when-placing-merge-VI-onto-Bloc​...
    If someone at NI can reproduce, can I please get a CAR #?
    Thanks,
    -Jim
    Solved!
    Go to Solution.

    Donovan B wrote:
    Hi Jim,
    After my previous post, I also saw this behavior, so I decided to do another test.  If there are no decorations in the VI set to “Merge VI” (“Place VI Contents” for LabVIEW 8.5 and later) the controls and indicators are still not selected when dropping the VI from the Functions palette.  I checked this behavior back to LabVIEW 7.1 and it is consistent throughout that controls and indicators are not selected.  (Consequently, so is the fact that when decorations are present they don’t maintain the relative position).
    I am not sure if this would be better suited as a CAR or product suggestion since it has been this way that long, but it does not appear to be related to the fact that decorations are present in the Merge VI.  It does seem strange that the decorations are selected though.  Looks like the best way to work around this is to drop the VI from the Controls palette.  Hopefully, it’s not too much of a hassle.
    Hi  Donovan,
    Thanks for checking in.
    >  I checked this behavior back to LabVIEW 7.1 and it
    is consistent throughout that controls and indicators are not
    selected.  (Consequently, so is the fact that when decorations are
    present they don’t maintain the relative position).
    This just means that not many people use this feature.  However, now that VIPM Professional makes it so easy to edit the palettes, I'm sure that others will start complaining that this doesn't work as they expect.
    > I am not sure if this would be better suited as a CAR or product suggestion
    since it has been this way that long, but it does not appear to be
    related to the fact that decorations are present in the Merge VI.
     Just look up the functional specifications for this feature and see if all objects are supposed to be selected.
    But seriously, is there a reason that only the FP decorations are selected?  Surely this would be documented somewhere, if there was a good reason for this current (IMO, buggy) behavior.
    > It
    does seem strange that the decorations are selected though.  Looks like
    the best way to work around this is to drop the VI from the Controls
    palette.  Hopefully, it’s not too much of a hassle.
    That's not a reasonably work-around, IMO.  It doesn't make sense to drop Block Diagram components onto the Front Panel.  For example, this bug affects the JKI State Machine.  It doesn't make sense to drop a State Machine onto the Front Panel.
    So, I'd file it as a CAR/bug, and then wait to see how LV R&D feels about it.  If they can find some valid reason for why Controls and Indicators shouldn't be selected, then that's fine (and hopefully someone will explain it to me).
    Thanks,
    -Jim

  • Buttons set as "free position" change back to default

    In iDVD 6, if you move a button to free position and then save it, when you re-open the project the button position changes back to the default position. I am using the iDVD 6 theme "Reflection Black" and positioned the button in the gray pane at the bottom but it moves back up the pane to the default position no matter how I try to save it. Anyone else having this problem?
    Thanks
    Craig

    The first six slideshows behave themselves and stay where I position them in the area designed for the listing. The remaining six are off to the side right across the moving drop zones, which makes them hard to read.
    I believe all of the menus are defaulted to handle six buttons, while you can add up to twelve on some, maybe this main menu can only "hold" six... I had four on mine.
    How about one button on the main menu that says something like "Slideshows" and when you click on that it takes you to a new menu (the chapter menu) and try to put twelve there.
    G4 DP 1.25 GHz 2GB RAM 4 Drives 770GB   Mac OS X (10.4.6)   2 SuperDrives (SL 8X & DL 16X)

  • Tie Regions by position change.

    As I understand the "Tie Regions by Length Change" is now named "Trim Region End to Next Region".
    OK. What about "Tie Regions by position change"? I've search for it and is not there.

    Andreww Adrian wrote:
    I'll check, but isn't Shuffle a randomization way of ordering items???
    In Logic, no. If you ask a drummer to play shuffle - sometimes yes.

  • When and How to get the Text.ScrollPos value of a String control when scroll bar position changed

    Hi, 
    I'm working on a feature triggered by scroll bar position of a string control changed.
    But I could not find a good way to catch the scroll bar position changed event, 
    the scroll bar is controlled manually by mouse down → mouse move → mouse up, I want the get the Text.ScrollPos value when user mouse up, and compare with the maximum value.
    But the problem is,  mouse up on the scroll bar could not trigger String: Mouse up event!
    So I have to get the Text.ScrollPos continuously in the background in Timeout event, but I think it’s not efficient.
    Do you have any better idea on when to get the correct destination value of Text.ScrollPos?
    I plan to store the value of Text.ScrollPos in the bottom(maximum value) in a shift register, then compare the current Text.ScrollPos value with the max one.
    If it comes close to the bottom(90%~100% of the maximum value), then the close to bottom LED will turn on.
    Attachments:
    scroll bar pos changed.vi ‏15 KB

    Hello Cecilia,
    I don't think there is any build-in event for this.
    One solution would be to create your own user event at the initialisation of you main and launch a thread which is going to be pulling the value of your scrollbar position:
    Then you can build your main as if they were a scrollbar move event.
    And dont forget to close the thread and destroy the event at the end.
    Hope it helps.
    Attachments:
    Scrollbar event.PNG ‏10 KB

  • Sprite color Change on mousEnter?

    I am trying to make a sprite change color when my mouse goes
    over it and chage back with my mouse leaves it. I tryed
    on mouseEnter me
    sprite(1).foreColor = color(0,0,100)
    end mouseEnter
    and the sprit does change color but it does not change back.
    What can i do to fix this?

    Well, you need to tell the sprite to change color when the
    mouse leaves
    on mouseLeave
    sprite(1).foreColor = color(?,?,?)
    end
    Now, are you going to hard code the color, or do you need the
    sprite to
    remember what it's orginal color was?

  • Changing Lead Status

    Hi All,
    I am trying to change lead status when saving. I have configured action profile as follows:
    Created new action in action profile
    Processing type: Method Call
    Method Used: Complete_document ( Am I using right Method?)
    Processing Parameters: PROCESS_TYPE = LEAD (LEAD is my TX type)...Here I have dout ...which parameter I have to pass here.
    Created new condition
    Defined start condition as follows:
    &CRM Lead.System Status& = I0802 ( I0802 = Complete).
    Gun....Thanks for your inputs to my previous question...I have given max points..
    Please help in this issue.
    Thanks,
    Ajay

    Hi again Ajay,
    Using method COMPLETE_DOCUMENT, you don't need to set any parameter.
    I still don't get you for start condition :
    &CRM Lead.System Status& = I0802 ( I0802 = Complete).
    Because using COMPLETE_DOCUMENT, once you run it, it will set the document
    system status to I1005 - COMPLETED.
    Is &CRM Lead.System Status& = I0802 your last system status you want to
    change to I1005 ?
    Hope this could help.
    Gun.

  • Is it possible to customise the tab/address/menu bar positions? I dislike the default position changes.

    Similar to MS Office, one can position all the menu bars in any order, top down or sideways as required. I find that with ver 4, the tabs on the top line , the search, home buttons etc are not intuitive and are quite annoying with their positional changes.

    You can still use/see the Menu Bar (''File, Edit, View, History, Bookmarks, Tools, Help'') if you prefer it:
    *'''Temporarily display the Menu Bar''': press the ALT key or the F10 key and make your selections from the temporarily displayed Menu Bar
    *'''Toggle between the Menu Bar and Firefox button'''. Do one of the following:
    **NOTE:
    ***Menu Bar '''checked''' = Menu Bar on, Firefox button off
    ***Menu Bar '''un-checked''' = Menu Bar off, Firefox button on
    **keyboard shortcut: HOLD the ALT key while pressing the letters VTM on your keyboard
    **Using the Menu Bar: click View > Toolbars, click Menu Bar
    **Using the Firefox Button: click Firefox Button > Options, click Menu Bar
    **right-click on an empty space in one of the toolbars, click Menu Bar

  • HCM Process and Forms Position Change Workflow Rejection

    Hi Experts,
    I am new to HCM Process and Forms workflows and have a simple query here.
    With the conventional workflows (PR/PO) when Approver Rejects a workitem we send a notifcation to the INITIATOR and when he changes the PO/PR the workflow gets triggered via CHANGED EVENT.
    However, here in POSITION CHANGE workflow when an approver REJECTS it at any level HOW WILL I SEND BACK THE FORM TO INITIATOR SO THAT he does the suggested changes and submits for RE-APPROVAL.
    Idea is to avoid the burden of filling all the fields everytime
    Please guide me on this.
    Thanks a lot
    Rgds,
    Lakshmi

    Hi,
    If a change method doesn't exist you can create a new one where you can use a Call Transaction sentence that redirects to a tcode where you can modify the form.
    Regards,

Maybe you are looking for