Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved] man, pictures keep dissapearing after a couple of seconds...

Status
Not open for further replies.
Rephrase the question and the situation please.

Uhh, when you want to show a picture in a certain area,
you did this right:

1. Click on an event tile in the editor.
2. Doubleclick on the white space in the event editor to make the event command window appear.
3. Find and click on the SHOW PICTURE event command.
4. Choose the PICTURE NUMBER and the FILE itself, then choose COORDINATES where the picture appears.(preferrably within 640 width and 480 height for the whole picture to be seen.)
5. Click ok.


Have you done that?
 
Linkin_T has help me a lot and he/she game me this code:

---------------------------
sprite = Sprite.new
sprite.bitmap = arshes_bitmap
sprite.x = 320
sprite.y = 240
sprite.z = 9999
sprite.zoom_x = 2
sprite.zoom_y = 2
sprite.blend_type = 1

-------------------------
It works fine, but afer a couple of seconds the picture "magicallly disappears". I want them to stay, like when done with events.

can ayone help?

Thank you
 
I'm not an expert at rgss, but I am assuming the reason why is because you are declaring the object without adding a $ to the front.

You see, when you declare an object without a @ or $ at the front, it becomes a local object, meaning that once the method holding that object gets through running, the data contained in that object is lost. So what could be happening is that the picture successfully gets drawn on the screen, but soon after the method holding the picture gets deleted. Try making the bitmap object a global variable by adding a $ to the front of "sprite" every time it comes up in your code. It is generally bad coding practice to assign something like this to a global variable, but you can use this to see if what I said is actually the case.

Bottom line, try using this code instead:

Code:
$sprite = Sprite.new
$sprite.bitmap = arshes_bitmap
$sprite.x = 320
$sprite.y = 240
$sprite.z = 9999
$sprite.zoom_x = 2
$sprite.zoom_y = 2
$sprite.blend_type = 1

Again, I am not an expert at the structure of RMXP's code, so I could be wrong.
 

Mac

Member

If you made it a global varial it would cause 'alot' of problems as in if any other events call on it, it will collide, anyway it should have an @ before it like so:-

Code:
@sprite = Sprite.new
@sprite.bitmap = arshes_bitmap
@sprite.x = 320
@sprite.y = 240
@sprite.z = 9999
@sprite.zoom_x = 2
@sprite.zoom_y = 2
@sprite.blend_type = 1

You must also add in @sprite.dispose and @sprite.refresh to the script at def refresh and def dispose. Otherwise it will never dissapear.
 
That is just bad coding. You shouldn't use globals for things like that.


If you are trying to add a sprite to the map or any scene, I suggest a method like this:
Code:
class Scene_Map
  def add_sprite(instance_name, object)
    eval "@#{instance_name} = object"
  end
  def sprite(instance_name)
    return eval "@#{instance_name}"
  end
end

Now, if you want to add a sprite on the map, something like
Code:
Script: sprite = Sprite.new
sprite.bitmap = PRG::Cache.picture(filename)
$scene.add_sprite('your_sprite_name', sprite)

From there, you can use something like
Code:
$scene.sprite('your_sprite_name').dispose

It is a bit more complex, but makes your sprites instance of Scene_Map, instead of a global sprite. You could take it a step further and make the method in your scene acess the spriteset, to further control viewports and z values, but I won't go into that unless asked. ^_^
 
shouldn't that be RPG::Cache Seph :p

and yeah using globals for everything is poor form

1) increases chance of name conflicts (whats to keep someone else from using the variable name $sprite for something)

2) I'm not very technical at this but it requires more memory than say an instance or local variable, the only time it is good to use a global is when you have another $data_ or $game_ array or object there are other special cases though

But yeah go with Seph on this

And the reason why the sprite magically disappears is that Garbage Collection removed it as there was no reference to the object since the local variable is wiped after the method command_355 of Class Interpreter is executed (the Call Script Event Command), again I can't explain anything too technical about this but it is about what happens
 
lol i was just giving an example with sprites and bitmaps, and that was just for pinting out some facts. ^^ This would not work well indeed.

And, well, SS and Trickster had explained almost all things. But i want just to add some more ideas, based on SS´s suggestion ^^
Code:
class Scene_Map
  attr_accessor :sprites

  alias old_linkint_big_alias_lol_scene_map_main main
  def main 
    @sprites = {}
    old_linkint_big_alias_lol_scene_map_main
    @sprites.values.each {|sprite| sprite.dispose if !sprite.disposed?}
  end
  
  alias old_linkint_big_alias_lol_scene_map_update update
  def update
    old_linkint_big_alias_lol_scene_map_update
    @sprites.values.each {|sprite| sprite.update if !sprite.disposed?}
  end

end
# A la SS xD

That way, in map you could just call:
Code:
sprite = Sprite.new
$scene["your_sprite_name"] = sprite
$scene["your_sprite_name"].z = 9999
# And so on...
# You can use numbers too, if you think it´s better
$scene[0] = Sprite.new
$scene[0].bitmap = RPG::Cache.battler("001-Fighter01", 0)

Hope you got it.


P.S. 1: Man/Woman? What do i appear to be? lol
P.S. 2: BTW this is the post i wrote explaining the concepts of sprites and bitmaps, and in that case i really forgot about the GC issue, so... sorry ^^
P.S. 3: Sometimes i worry more on explaining how things happens than solving people´s problems. I should´ve posted a good solution for you since the beginning. Sorry for not being so helpful before kaboom xD
 
Thahk YOu all very much.
The original example worked once I followed the direction of Kadoba and Mac. And as always, thank You Linking_T

by the way: why dont the best of the community (lie you guys) unite to make an rpg. Like a community project. I bet that it will be much more easier to make a game like that, instead of everyone making their own game separatly.
 
Status
Not open for further replies.

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top