Clint Thompson Posted December 14, 2017 Share Posted December 14, 2017 1. I don't see any examples of making the sprite blink and I've tried a few things but can't seem to get it working. Is this function actually working and if so, could someone post an example? Is there a way to set the time for blinking, or amount of times it will blink, etc? 2. Without setting up a counter, is there a way to scale a sprite directly adding 1 or subtracting 1 from an object and have it remain? As for example, I want to press 3 and have it scale a sprite by 1 (from 32 to say 33, 34 and so on) and stay that way, and same for subtracting or is a counter actually required? or another example, if sprite A hits sprite B, sprite A will increase +1,+1 every single time? 3. I'm wanting to flip a sprite and have it animate the motion of moving left or right instead of just simply flipping. Would having the same sprite animation contain the frames for moving left or right be the best way to do this? Say IF I press left, it will call frames 12-16 to play and then resume as normal and flip the other way around if so? Playing the primary frames 1-4 for example and then calling beyond that for left or right? Or have others simply created a separate sprite for doing something like this? (which seems like it would be more difficult but may be required) Quote Link to comment Share on other sites More sharing options...
omf Posted December 14, 2017 Share Posted December 14, 2017 1, you would need to handle this yourself, i do not believe there is any functionality to do this automatically 2, you could probably add or subtract 1to the scale sections of the object list. NOTE: scaling objects leaves the collision box as it is. you need to scale that separately. use my list editor for the correct scaling values 3 you would need to control this manually, setting the gfxbase to the required address to the frame you want, there are a few examples of this going around, if you wan find any then i can provide something 1 Quote Link to comment Share on other sites More sharing options...
+CyranoJ Posted December 14, 2017 Share Posted December 14, 2017 1. I don't see any examples of making the sprite blink and I've tried a few things but can't seem to get it working. Is this function actually working and if so, could someone post an example? Is there a way to set the time for blinking, or amount of times it will blink, etc? 2. Without setting up a counter, is there a way to scale a sprite directly adding 1 or subtracting 1 from an object and have it remain? As for example, I want to press 3 and have it scale a sprite by 1 (from 32 to say 33, 34 and so on) and stay that way, and same for subtracting or is a counter actually required? or another example, if sprite A hits sprite B, sprite A will increase +1,+1 every single time? 3. I'm wanting to flip a sprite and have it animate the motion of moving left or right instead of just simply flipping. Would having the same sprite animation contain the frames for moving left or right be the best way to do this? Say IF I press left, it will call frames 12-16 to play and then resume as normal and flip the other way around if so? Playing the primary frames 1-4 for example and then calling beyond that for left or right? Or have others simply created a separate sprite for doing something like this? (which seems like it would be more difficult but may be required) 1. Make a sprite, add an extra blank frame to the end. set max_frame to 1 (0+1) and use anim_spd to set the blink rate. 2. No, there are no auto-scale commands in the API. I'll put it on the list if I can think of a reasonable way to do so. 3. Keep all your animates a set number of frames... so, eg 0-7 moving left, 8-15 moving right, 16-23 turning left, 24-31 turning right. Set your max_frame to 7 (for 8 frames in this example) and then change the gfx_base pointer to an offset into the sprite 5 Quote Link to comment Share on other sites More sharing options...
Sporadic Posted December 14, 2017 Share Posted December 14, 2017 2. Without setting up a counter, is there a way to scale a sprite directly adding 1 or subtracting 1 from an object and have it remain? As for example, I want to press 3 and have it scale a sprite by 1 (from 32 to say 33, 34 and so on) and stay that way, and same for subtracting or is a counter actually required? or another example, if sprite A hits sprite B, sprite A will increase +1,+1 every single time? Instead of using a variable as a counter you could just read the current scale value into a variable, add 1 to it and then set the scale again. Eg. dim currentsize as integer currentsize = rlist[fishobject].scale_x currentsize = currentsize + 1 rlist[fishobject].scale_x = currentsize (you want to add checks to make sure currentsize doesn't go below 0 and above 255 though). It would be more efficient to just maintain the currentsize variable yourself though and just set the size when required though (saves reading its size each time you need it). However if you want to be ultra lazy you could do; rlist[fishobject].scale_x = rlist[fishobject].scale_x + 1 but that wouldn't allow you to test the 0 and 255 limits of the scale property. Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted December 14, 2017 Author Share Posted December 14, 2017 Great, thanks for the info guys! I just saw the command for blink listed so thought it was something I could use but understood. Also, I don't want to lazy it up with the sprite scaling of fish for example but also don't want to over complicate it if it's not exactly necessary since the whole idea is to get bigger as you eat more fish. I'm guessing a rgetobj value and IF x=200 (or more) then do this or do that check could work in place somehow. No real added need for sprite x increase or decrease, just wanted to make sure there wasn't something simple already implemented in place that I am missing before I go the other route though I do like the idea of add and then set based on current value, that seems like it would work for what I want to do as a quick test. 1 Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted December 21, 2017 Author Share Posted December 21, 2017 Looking for some more suggestions on controls please so I'm not making a choppy looking, shit game. I currently have the controls setup to move the fish either 1 or 2 x,y based on D-pad input using xadd or yadd followed by a 0 stop so the fish doesn't endlessly roll one way or the other. What I would like to know is if there's a far better way at doing this so it's more fluid-like? (the puns really are terrible and not intentional) It doesn't seem too bad right now but I can tell when moving at an angle up or down when going left and right that it seems a little jaggy in motion, which is expected I guess since it's probably moving up then left and going back and forth really quickly. I think I tried doing a IF left and up THEN do these two at the same time but I'm not sure if it just didn't work or didn't matter, which brings me here for suggestions on the best way to do it. Right now I know you can add a delay between moves if using a sub routine but feel that may be causing problems and that there may be another command or function to use for this? That way say I press right then release, the fish doesn't come to a complete halt but slows down and then drifts even slower for a few seconds. The problem with delay is that it's only giving me the speed of the update so it's either slow at 1 or faster at 2 with no in-between or below 1. Apologize if this is super amateurish but again, I'm doing my best at the programming stuff since it's not really my area to begin with as much as graphics and music is my thing. Appreciate any help. Quote Link to comment Share on other sites More sharing options...
+CyranoJ Posted December 21, 2017 Share Posted December 21, 2017 You don't need to use xadd/yadd - you can directly add the values to sprite_x, sprite_y. 1 Quote Link to comment Share on other sites More sharing options...
Sporadic Posted December 21, 2017 Share Posted December 21, 2017 (edited) Right now I know you can add a delay between moves if using a sub routine but feel that may be causing problems and that there may be another command or function to use for this? That way say I press right then release, the fish doesn't come to a complete halt but slows down and then drifts even slower for a few seconds. The problem with delay is that it's only giving me the speed of the update so it's either slow at 1 or faster at 2 with no in-between or below 1. I'd say, don't use DELAY(x) in your movement commands. You instead need to use sub pixel values. eg. to move 1 pixel you currently do something like; sprite_x = sprite_x + (1<<16) If you want to move 1 and 1/2 pixels per frame then you should use; sprite_x = sprite_x + (1<<16)+32768 If you want to move 1/2 a pixel per frame then you should use; sprite_x = sprite_x + 32768 The coordinates are fixed point numbers - you shouldn't need to fully understand this though for basic movement with a few pointers... The 1<<16 is your whole number (or whole pixel) - so 5<<16 would be 5 pixels etc etc. 1<<16 = 65536 (1 whole pixel) Therefore, 32768 = half a pixel, 16384 = quarter of a pixel, and so on. If you add a quarter of a pixel to the sprite_x each frame then it'll take 4 frames to move 1 pixel and hence look much smoother than other methods. There is a slight complication when using negative values. You must go to the next whole pixel value lower and then add the fractional pixel on. Eg. To move -1.5 pixels you would do; sprite_x = sprite_x - (-2<<16)+32768. You cannot just subtract the 32768 from the (-1<<16) IIRC. In the rB+ install folder and in "/website/tutorial1-2.html" you will see a larger write up about this. Now for example, you could just do sprite_x = sprite_x + 8192 when DPAD_Right is held down. This will add an 8th of a pixel on to the fishes current position and hence slowly speed up. If you then do sprite_x = sprite_x - 8192 for left, the fish should gradually slow down and then move left. This is just off my head pseudo code FYI. Hope this helps a bit... Edited December 21, 2017 by Sporadic 3 Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted December 21, 2017 Author Share Posted December 21, 2017 (edited) You don't need to use xadd/yadd - you can directly add the values to sprite_x, sprite_y. Yeah, I don't know why I did it that way in the end... I'd say, don't use DELAY(x) in your movement commands. You instead need to use sub pixel values. eg. to move 1 pixel you currently do something like; sprite_x = sprite_x + (1<<16) If you want to move 1 and 1/2 pixels per frame then you should use; sprite_x = sprite_x + (1<<16)+32768 If you want to move 1/2 a pixel per frame then you should use; sprite_x = sprite_x + 32768 The coordinates are fixed point numbers - you shouldn't need to fully understand this though for basic movement with a few pointers... The 1<<16 is your whole number (or whole pixel) - so 5<<16 would be 5 pixels etc etc. 1<<16 = 65536 (1 whole pixel) Therefore, 32768 = half a pixel, 16384 = quarter of a pixel, and so on. If you add a quarter of a pixel to the sprite_x each frame then it'll take 4 frames to move 1 pixel and hence look much smoother than other methods. There is a slight complication when using negative values. You must go to the next whole pixel value lower and then add the fractional pixel on. Eg. To move -1.5 pixels you would do; sprite_x = sprite_x - (-2<<16)+32768. You cannot just subtract the 32768 from the (-1<<16) IIRC. In the rB+ install folder and in "/website/tutorial1-2.html" you will see a larger write up about this. Now for example, you could just do sprite_x = sprite_x + 8192 when DPAD_Right is held down. This will add an 8th of a pixel on to the fishes current position and hence slowly speed up. If you then do sprite_x = sprite_x - 8192 for left, the fish should gradually slow down and then move left. This is just off my head pseudo code FYI. Hope this helps a bit... Excellent, thank you! Will hopefully get some time to test it all out this weekend. Edited December 21, 2017 by Clint Thompson 2 Quote Link to comment Share on other sites More sharing options...
Sporadic Posted December 21, 2017 Share Posted December 21, 2017 (edited) Just had another thought; If you want the fish to keep drifting when the player isn't holding a direction then you do want to use the xadd/yadd values instead of altering the sprite_x/y values directly. Just don't zero the x/yadd values out each frame. then raptor will keep the fish moving in the direction you have set. If you use sprite_x/y (as I detailed in previous post) , you must add a value on every frame otherwise the fish will just stop moving. So it depends how you want it to behave. Edited December 21, 2017 by Sporadic 1 Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted December 22, 2017 Author Share Posted December 22, 2017 Now I know why I did it that way in the end. When I press right, instead of the fish moving right it completely re-positions the fish to the original rapint coordinates and then doesn't actually move right but for whatever wonky reason using x/y_add does it just fine? When you say "something like this" I need verbatim for what exactly it needs to be since I couldn't get the = to work at all, so maybe that's my issue too. I tried multiple things and it just failed to compile. Sorry for what may seem obvious isn't clear to me. Here is what I'm doing but it's just not right: SUB rightRSETOBJ(orangefish, R_sprite_flip, R_is_flipped)RSETOBJ(orangefish, R_sprite_x,R_sprite_x+2<<16) END SUB Should I be using something other than RSETOBJ? Quote Link to comment Share on other sites More sharing options...
Sporadic Posted December 22, 2017 Share Posted December 22, 2017 (edited) Now I know why I did it that way in the end. When I press right, instead of the fish moving right it completely re-positions the fish to the original rapint coordinates and then doesn't actually move right but for whatever wonky reason using x/y_add does it just fine? When you say "something like this" I need verbatim for what exactly it needs to be since I couldn't get the = to work at all, so maybe that's my issue too. I tried multiple things and it just failed to compile. Sorry for what may seem obvious isn't clear to me. Here is what I'm doing but it's just not right: SUB right RSETOBJ(orangefish, R_sprite_flip, R_is_flipped) RSETOBJ(orangefish, R_sprite_x,R_sprite_x+2<<16) END SUB Should I be using something other than RSETOBJ? rlist[orangefish].sprite_x = rlist[orangefish].sprite_x + (2<<16) Or rlist[orangefish].sprite_x += (2<<16) Start using rlist[] instead of rget / rset. It allows you to write the commands much easier. Your line above , using those commands should be; RSETOBJ(orangefish, R_sprite_x,RGETOBJ(orangefish, R_sprite_x)+2<<16) Which as you can see is much harder to write. Sorry I'm brief here, off to sleep now Edited December 22, 2017 by Sporadic 3 Quote Link to comment Share on other sites More sharing options...
ggn Posted December 22, 2017 Share Posted December 22, 2017 (edited) RSETOBJ(orangefish, R_sprite_x,R_sprite_x+2<<16) This is wrong, as Sporadic pointed out. R_sprite_x is just a variable with a fixed value ( 8 ). So what your code does is setting the attribute R_sprite_x of object orangefish to value R_sprite_x+2>>16, which is 8+65536=65544. Instead you need to get current value using rget or rlist and then add 1<<16 or -1<<16. Hope this makes things more clear! Edited December 22, 2017 by ggn 2 Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted December 23, 2017 Author Share Posted December 23, 2017 These are the errors I get when I use either RLIST function exactly as you have written out: As: rlist[orangefish].sprite_x = rlist[orangefish].sprite_x + (2<<16) or as: rlist[orangefish].sprite_x += (2<<16) and if I use this: RSETOBJ(orangefish, R_sprite_x,RGETOBJ(orangefish, R_sprite_x)+2<<16) I press right, it sets the fish over 2 pixels but does not continue to push the fish left or right the longer you hold the button, even though the fish was in an entirely different location. That's why I used xadd and yadd, because it would continue to roll and keep going, not just move this object a few pixels from it's current location. Quote Link to comment Share on other sites More sharing options...
Sporadic Posted December 23, 2017 Share Posted December 23, 2017 (edited) These are the errors I get when I use either RLIST function exactly as you have written out: As: rlist[orangefish].sprite_x = rlist[orangefish].sprite_x + (2<<16) error1.png or as: rlist[orangefish].sprite_x += (2<<16) error2.png and if I use this: RSETOBJ(orangefish, R_sprite_x,RGETOBJ(orangefish, R_sprite_x)+2<<16) I press right, it sets the fish over 2 pixels but does not continue to push the fish left or right the longer you hold the button, even though the fish was in an entirely different location. That's why I used xadd and yadd, because it would continue to roll and keep going, not just move this object a few pixels from it's current location. Sorry my bad, I think you just want rlist[orangefish].x I can't remember where there is a list of the variable names to put on the end. I'll look later or maybe ggn has one. (It might even be in the forum or in the /docs/ install folder either in the quickstart or change log file) The rget/set version above would have to get called every frame (loop) to keep the fish moving, so yes, stick with xadd etc, it's easier. Edited December 23, 2017 by Sporadic Quote Link to comment Share on other sites More sharing options...
ggn Posted December 23, 2017 Share Posted December 23, 2017 (edited) rlist members are: obj active x y xadd yadd flip width height vbox hbox gfxbase framesz framedel curframe maxframe animloop wrap timer track colchk scaled scale_x scale_y CLUT animspd bytewid tracktop was_hit coffx coffy remhit bboxlink hitpoint damage flash gwidth rmotion rmcurfrm rmfrm As shown in the quickref guide Edited December 23, 2017 by ggn 4 Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted December 30, 2017 Author Share Posted December 30, 2017 (edited) Bandwidth: Sick and brain dead, I've fired up the Jag again and want to understand and clear up any confusion regarding the objects being built on-screen and how it affects performance or *could* regarding active vs inactive, as I've seen it written that just because something is inactive doesn't mean it's still not on the screen. With that said and for further clarification: If X object is at 200,200 and I set it to inactive, it's no longer being processed by the OP at this point correct? or no? Edited December 30, 2017 by Clint Thompson Quote Link to comment Share on other sites More sharing options...
Sporadic Posted December 30, 2017 Share Posted December 30, 2017 Inactive objects are not processed by the OP. As far as I know, Raptor culls them. CJ will probably verify this Quote Link to comment Share on other sites More sharing options...
+CyranoJ Posted December 30, 2017 Share Posted December 30, 2017 Correct, at the next VI interrupt (50Hz PAL/60Hz NTSC) the object will disappear from the screen. It *IS* technically still in the list, however the last active object prior to it has its link pointer set to skip over it. This is why it is imperative that the first and last objects in the list are always active. The RAPTOR API will also not do any processing on inactive objects (eg, x_add/y_add/animation/collision detection, etc) Hope that helps 4 Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted January 5, 2018 Author Share Posted January 5, 2018 (edited) I've been messing with this for hours now and it's really pissing me off. Trying to get the collision to work on an object that is acting as a laser and only being displayed for a few moments but it's not working. I set up a xadd, +5 to make sure the detection actually works and force the object as active and it works as seen below: but if I do it the way I *want* it to work, it doesn't do shit: I've removed the DIM titling in case I was messing something up, I've tried different things just to make sure I've got the right object (and it's not hard since I don't have very many), first and last image is active... have even tried adding it to the subroutine for when you press left or right hoping that might work but nothing Any suggestions please.... IF RHIT(4,4,6,6)<>-1 THEN RSETOBJ(4,R_sprite_xadd,+5<<16) DELAY(1) ENDIF That works if I keep the laser object active. Does hit collision not work on objects that are inactive at first and later enabled? Edited January 5, 2018 by Clint Thompson Quote Link to comment Share on other sites More sharing options...
ggn Posted January 5, 2018 Share Posted January 5, 2018 I'm stabbing in the dark here but here's a couple: - delay(1) will halt all your program for one vertical blank. I'm not sure if that's a good idea, ideally I'd expect you have a single delay(1) or vsync call in your main loop. - You don't seem to be resetting was_hit attribute after collision. Try inserting a RSETOBJ(4,R_sprite_was_hit,1)[/i] inside your if block. - Try this: instead of making the object active and inactive, change its y coordinate to something high like 500 to make it "invisible" and then back to the original coordinate to make it "visible". Hope any of this helps! 2 Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted January 5, 2018 Author Share Posted January 5, 2018 Thanks ggn, I'll give it a go this weekend. I did try the moving coordinates completely off screen before posting this and it didn't make a difference but I don't know if I had it set to disable the object or not, though not sure that should matter. As far as displaying an image for x amount of time, in this case the laser, is there a timer example you can give to display object X for X amount of seconds as opposed to using delay, since that's probably what is messing it up if it's halting the program. Same could be for anything else that I'm wanting to slow down. Yeah, vsync is required in main loop otherwise nothing animates I've learned... and for some reason, adding delay is the only way I could get some functions to work like the scaling but that could also explain why I have weird issues in the fish game, just don't know of another way of doing it. Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted January 6, 2018 Author Share Posted January 6, 2018 I was toying around with moving a background via rapini.s and using the R_sprite_xadd and set it as 1... music in the background plays great, animation moves along the top of the screen fluid-like. I decide to change it to zero. Now the music is degraded and slowed down. Reverting back to making the top of the screen animate brings the quality of the music back to normal. This seems completely backwards in regards to performance, so my question is what would cause a static image to degrade the quality of the music AND slow it down but the moment you animate it to shift right, everything clears up perfectly? Quote Link to comment Share on other sites More sharing options...
Clint Thompson Posted January 6, 2018 Author Share Posted January 6, 2018 So a little further diving in: dc.w 10,0 ; ; Put sprite this many pixels down from top of screen. ; R_sprite_y dc.w 0,$00006000 ; ; How many pixels will this sprite move automatically in x? ; R_sprite_xadd dc.w 0,0 ; ; How many pixels will this sprite move automatically in x? ; R_sprite_xadd I found the way to make the animation move far slower and exactly what I wanted.... however, if I go any slower then it's back to degraded audio performance again and slowed down music. If I change 0,$00006000 to 0,$0001000 then total performance hit. Why is that? What's happening in the background as a result of slowing down an animation that would also slow down the music or make it sound worse? Quote Link to comment Share on other sites More sharing options...
ggn Posted January 6, 2018 Share Posted January 6, 2018 This is very weird. What raptor does internally is take whatever value R_sprite_x has and add R_sprite_xadd. That's all to it. It really doesn't care much what increment you give it, 0 to max highest or lower number. So if I were you I'd rule out completely that this is the cause of your problems. How are you testing this by the way? Real hardware or VJ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.